来自单个输入的多个输入 window

Several inputs from a single input window

出于好奇,我试图找到一种方法将界面上的多个输入组合成一个输入 window(当前设置为字符串)。在当前示例中,这些输入是调整世界大小所需的 4 个参数。 虽然我的结果有效,但我很想知道是否有人知道更优雅的解决方案。我特别不喜欢在这里使用 item

接口:

input-window 
[0 5 0 5]

代码:

to setup
  let worldsizes runresult input-window
  resize-world item 0 worldsizes item 1 worldsizes item 2 worldsizes item 3 worldsizes
end

使用 this post 作为基础,我创建了一个过程,允许匿名和常规命令将单个参数列表作为输入。

接口:

input-window 
[0 5 0 5]

代码:

to test
  
  let worldsize run-result input-window ;creates a list
  
  apply-command "resize-world" worldsize
  
end



to apply-command [command inputlist]
  ; Takes two inputs
  ; 1: Anonymous command/string containing anonymous command/string containing regular command
  ; 2: A list of inputs, corresponding in length to the number of inputs the command takes
  ; Applies the command with the different items of the list as input
  ; Heavily inspired by Whosebug-user Bryan head
  
  set command anonimify-command command length inputlist ; Using non-anonymous commands gave issues, hence they are anonimified
  (run listify-command command length inputlist inputlist)
  
end

to-report listify-command [ command num-args ]
  ; Takes an anonymous command and the length of a list as input
  ; Outputs an anonymous command that takes the different items of the list as inputs
  ; Heavily inspired by Whosebug-user Bryan head
  
  if (not is-anonymous-command? command) [error "The first input for listify-command has to be an anonymous command"]
  
  let args (reduce word n-values num-args [ x -> (word " item " x " ?") ]) 
  ;show (word runresult (word "[ ? -> (run command " args ") ]"))
  report runresult (word "[ ? -> (run command " args ") ]")
  
end

to-report anonimify-command [ command number-of-inputs]
  ; Takes two inputs
  ; 1: Takes an anonymous command, a string containing an anonymous command or a string containing a regular command
  ; 2: Takes a number that corresponds to the number of inputs the anonimified command should take
  ; Returns anonymous commands unaltered
  ; Returns strings containing an anonymous command as an anonymous command
  ; Returns strings containing a regular command as an anonymous command
  
  if (is-anonymous-command? command) [ ; Anonymous commands get returned
    report command
  ] 
  
  if (is-string? command) [ ; Strings are processed
    carefully [ ; Using run-result on a string that does not contain an anonymous command causes an error, hence carefully
      if (is-anonymous-command? run-result command) [ 
        set command run-result command
      ]
    ]
    [
      let inputs n-values number-of-inputs [ i -> word " x" i]
      let inputs-as-string reduce word inputs
      let command-string (word "[ [" inputs-as-string " ] -> " command inputs-as-string" ]")
      set command run-result command-string
    ] 
    report command
  ]
  
  error "The inputted command must be either an anonymous command, a string containing an anonymous command or a string containing a command"
  ;If the input is neither anonymous command nor string, an error is displayed
  
end