hi lispers, :)
hmmm, I'm learning Lisp and wondering how to deal with the following
case:
f.e. I have a function with a lot of keywords as arguments:
(defun foo (&key one two three four five six)
(do-something.. ))
now, somewhere else in my code I have constructed a list with all
needed arguments:
(setf myparameter
'(:one 1 :two 2 :three "three" :four 4 :five "five" :six 6))
what would be the best way to call that function with that prepared
list?
Something like (incorrect):
(foo ,@myparameter)
thanks for any help!
okflo
On Mar 28, 12:17 pm, learninglisp <············@mytrashmail.com>
wrote:
> hi lispers, :)
>
> hmmm, I'm learning Lisp and wondering how to deal with the following
> case:
>
> f.e. I have a function with a lot of keywords as arguments:
>
> (defun foo (&key one two three four five six)
> (do-something.. ))
>
> now, somewhere else in my code I have constructed a list with all
> needed arguments:
>
> (setf myparameter
> '(:one 1 :two 2 :three "three" :four 4 :five "five" :six 6))
>
> what would be the best way to call that function with that prepared
> list?
>
> Something like (incorrect):
>
> (foo ,@myparameter)
>
> thanks for any help!
>
> okflo
Try (apply 'foo myparameter)
From: learninglisp
Subject: Re: Use keyword-list as argument for a function (?)
Date:
Message-ID: <871w5v876y.fsf@mytrashmail.com>
blandest <··············@gmail.com> writes:
> On Mar 28, 12:17 pm, learninglisp <············@mytrashmail.com>
> wrote:
>> f.e. I have a function with a lot of keywords as arguments:
>>
>> (defun foo (&key one two three four five six)
>> (do-something.. ))
>>
>> now, somewhere else in my code I have constructed a list with all
>> needed arguments:
>>
>> (setf myparameter
>> '(:one 1 :two 2 :three "three" :four 4 :five "five" :six 6))
>>
>> what would be the best way to call that function with that prepared
>> list?
>>
>> Something like (incorrect):
>>
>> (foo ,@myparameter)
>
> Try (apply 'foo myparameter)
>
ooohhh - of course, why shouldn't work apply also with keyword-lists!
- thanks for you help! :)
okflo
CL-USER> (defun foo (&key one two three four five six)
(list one two three four five six))
FOO
CL-USER> (setf my '(:one 1 :two 2 :three "three" :four 4 :five "five" :six 6))
(:ONE 1 :TWO 2 :THREE "three" :FOUR 4 :FIVE "five" :SIX 6)
CL-USER> (apply #'foo my)
(1 2 "three" 4 "five" 6)
learninglisp wrote:
> hi lispers, :)
>
> hmmm, I'm learning Lisp and wondering how to deal with the following
> case:
>
> f.e. I have a function with a lot of keywords as arguments:
>
> (defun foo (&key one two three four five six)
> (do-something.. ))
>
> now, somewhere else in my code I have constructed a list with all
> needed arguments:
>
> (setf myparameter
> '(:one 1 :two 2 :three "three" :four 4 :five "five" :six 6))
>
> what would be the best way to call that function with that prepared
> list?
>
> Something like (incorrect):
>
> (foo ,@myparameter)
(apply 'foo myparameter)
kenny
--
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/
"In the morning, hear the Way;
in the evening, die content!"
-- Confucius
On Mar 28, 3:17 am, learninglisp <············@mytrashmail.com> wrote:
> hi lispers, :)
>
> hmmm, I'm learning Lisp and wondering how to deal with the following
> case:
>
> f.e. I have a function with a lot of keywords as arguments:
>
> (defun foo (&key one two three four five six)
> (do-something.. ))
>
> now, somewhere else in my code I have constructed a list with all
> needed arguments:
>
> (setf myparameter
> '(:one 1 :two 2 :three "three" :four 4 :five "five" :six 6))
>
> what would be the best way to call that function with that prepared
> list?
>
> Something like (incorrect):
>
> (foo ,@myparameter)
>
> thanks for any help!
>
> okflo
Try (untested)
(apply #'foo myparameters)
HTH
From: Joost Diepenmaat
Subject: Re: Use keyword-list as argument for a function (?)
Date:
Message-ID: <87od8x4rkd.fsf@zeekat.nl>
learninglisp <············@mytrashmail.com> writes:
> hi lispers, :)
>
> hmmm, I'm learning Lisp and wondering how to deal with the following
> case:
>
> f.e. I have a function with a lot of keywords as arguments:
>
> (defun foo (&key one two three four five six)
> (do-something.. ))
>
> now, somewhere else in my code I have constructed a list with all
> needed arguments:
>
> (setf myparameter
> '(:one 1 :two 2 :three "three" :four 4 :five "five" :six 6))
>
> what would be the best way to call that function with that prepared
> list?
(apply #'foo myparameter)
works for any parameter list, keywords or not.
http://www.lispworks.com/documentation/HyperSpec/Body/f_apply.htm#apply
Cheers,
Joost.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/