Page 1 of 1

list to values

Posted: Sat Dec 08, 2012 2:20 am
by jopython
Lets say I have a function which accepts 2 strings and three integers

Code: Select all

e.g
(myfunc "str1" "str2" 3 4 5)
However I have a list which contains these integer values.
(setq myvalues '(3 4 5))

Code: Select all

How can I convert the content of myvalues list to a set of values so that i can pass them to "myfunc" as arguments?

Re: list to values

Posted: Sat Dec 08, 2012 7:09 am
by HPW
Like this:

Code: Select all

(setq myvalues '(3 4 5))
(myfunc "str1" "str2" (myvalues 0)(myvalues 1)(myvalues 2))
?

Re: list to values

Posted: Sat Dec 08, 2012 12:33 pm
by jopython
HPW,

This is not possible if myvalues has a 'unknown' number of elements.

Re: list to values

Posted: Sat Dec 08, 2012 3:03 pm
by Lutz

Re: list to values

Posted: Fri Dec 21, 2012 3:11 pm
by William James

Code: Select all

(define (my-func s1 s2 a b c)
  (dup (string s1 s2 a b) c))

> (my-func "o" "-" 1984 9 3)
"o-19849o-19849o-19849"

> (apply my-func (cons "o" (cons "-" '(1984 9 3))))
"o-19849o-19849o-19849"

> (apply my-func (append '("o" "-") '(1984 9 3)))
"o-19849o-19849o-19849"