[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: When to use apply

William James

10/3/2015 12:07:00 AM

Michael Price wrote:

> CL-USER> (defun nth-elements (n &rest lists)
> (loop for item in lists collect (nth n item)))
>
> NTH-ELEMENTS
> CL-USER> (nth-elements 3 '(10 20 hello x world) '(-1 -2 -3 y) '(z0 z1 z2 z))
>
> (X Y Z)

Gauche Scheme:

(define (nths n . seqs)
(map (cut ref <> n) seqs))

(nths 3 '(10 20 hello x world) #(-1 -2 -3 y) '(z0 z1 z2 z))
===>
(x y z)

--
Whatever disagreed with the opinions of the Puritans, was held as a crime to be
punished with imprisonment and death. That is the moral temper of Puritanism
still. It never relents, never forgives, never loses its dictatorial and
intolerant spirit. --- The Old Guard, March 1863, p. 59
1 Answer

William James

10/13/2015 4:42:00 AM

0

WJ wrote:

> Michael Price wrote:
>
> > CL-USER> (defun nth-elements (n &rest lists)
> > (loop for item in lists collect (nth n item)))
> >
> > NTH-ELEMENTS
> > CL-USER> (nth-elements 3 '(10 20 hello x world) '(-1 -2 -3 y) '(z0 z1 z2 z))
> >
> > (X Y Z)

Portable Standard Lisp:

(load useful)

(dn nths (args)
(let ((n (pop args)))
(for (in item args)
(collect (nth item n)))))

(nths 4 '(10 20 hello x world) '(-1 -2 -3 y) '(z0 z1 z2 z))
===>
(x y z)