[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Macro Question

William James

10/26/2015 8:20:00 PM

Pascal Bourguignon wrote:

> Let's say we want a function that takes a list ( ... i ...) of numbers
> as argument and return a form like:
>
> (list (+ 3 4) ... (+ i i) ... (- 4 3))
>
> How can we write such a function?
>
> (defun fun-test-2 (list)
> (append
> (list (quote list) (quote (+ 3 4)))
> (mapcar (lambda (i) (list (quote +) i i)) list)
> (list (quote (- 4 3)))))
>
> Let's try it:
>
> (fun-test-2 '(10 20 30 40 50))
> --> (LIST (+ 3 4) (+ 10 10) (+ 20 20) (+ 30 30) (+ 40 40) (+ 50 50) (- 4 3))

Gauche Scheme:

(define (fun-test-2 items)
`(list (+ 3 4) ,@(map (^x (list '+ x x)) items) (- 4 3)))

(fun-test-2 '(10 20 30 40 50))
===>
(list (+ 3 4) (+ 10 10) (+ 20 20) (+ 30 30) (+ 40 40) (+ 50 50) (- 4 3))

--
The negroes have first rate tents with stoves in them, get soft bread to eat
most of the time, and don't have to do night work. The white men have no
stoves, have to eat hard tack, and do night work.
--- The Old Guard, February 1863, p. 36
1 Answer

Kaz Kylheku

10/26/2015 8:48:00 PM

0

On 2015-10-26, WJ <w_a_x_man@yahoo.com> wrote:
> Pascal Bourguignon wrote:
>
>> Let's say we want a function that takes a list ( ... i ...) of numbers
>> as argument and return a form like:
>>
>> (list (+ 3 4) ... (+ i i) ... (- 4 3))
>>
>> How can we write such a function?
>>
>> (defun fun-test-2 (list)
>> (append
>> (list (quote list) (quote (+ 3 4)))
>> (mapcar (lambda (i) (list (quote +) i i)) list)
>> (list (quote (- 4 3)))))
>>
>> Let's try it:
>>
>> (fun-test-2 '(10 20 30 40 50))
>> --> (LIST (+ 3 4) (+ 10 10) (+ 20 20) (+ 30 30) (+ 40 40) (+ 50 50) (- 4 3))
>
> Gauche Scheme:
>
> (define (fun-test-2 items)
> `(list (+ 3 4) ,@(map (^x (list '+ x x)) items) (- 4 3)))

Reminds me of the time, not so long ago, you posted:

Gauche Scheme:

(dotimes ...)

Nope, no quasiquotes or dotimes in Common Lisp.

ISTR that your (dotimes ...) form executed vebatim in a CL listener.

By the way, what is wrong with `(list + ,x ,x)? It's shorter by character
count 'n' everything.