list to values

Q&A's, tips, howto's
Locked
jopython
Posts: 123
Joined: Tue Sep 14, 2010 3:08 pm

list to values

Post 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?

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Re: list to values

Post by HPW »

Like this:

Code: Select all

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

jopython
Posts: 123
Joined: Tue Sep 14, 2010 3:08 pm

Re: list to values

Post by jopython »

HPW,

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


William James
Posts: 58
Joined: Sat Jun 10, 2006 5:34 am

Re: list to values

Post 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"

Locked