简体   繁体   中英

Using Elements in a List As Arguments in Racket/PLT Scheme

In a library I can not modify, there is a function that takes a list of values as one of its arguments.

For the sake of this question, we can just call it fun . I have a function that returns multiple arguments as a list, and was wondering how I can extract those values from the list and pass that into the function. For example, here is fun :

(fun (list someval someval2 arg1 arg2 arg3 ... etc)) .

And my function that process data would return something akin to (list arg1 arg2 arg3 ... etc) . How could I pass the contents of the list that my function returns into fun, alongside someval and someval2 ?

Use list* :

(let ([someval (some-func ...)]
      [someval2 [some-func2 ...)]
      [args (my-func ...)])
  (fun (list* someval someval2 args)))

list* takes it's arguments and builds them into a list like list does, with the exception that if the last argument is a list, it uses that as the tail of the list, eg (list* 1 2 '(3 4 5)) is '(1 2 3 4 5) . So once you calculate someval , someval2 , and your list of arguments you want to pass to fun (I named the list args in the code above), you can build that into one list with (list* someval someval2 args) , then pass that list into fun .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM