Alex Rivera | Logout

Getting the first n elements of a list in Common Lisp?

Asked 2009-11-12T02:39:33.957
25

How would I get the first n elements of a list?

CL-USER> (equal (some-function 2 '(1 20 300))
                '(1 20))
T

I am absolutely certain this is elementary, but help a brother newb out.

Edit
Report

1 Answer

-4

(butlast '(1 20 300) (- (list-length '(1 20 300)) 2))

Should be made into a function/macro.

P.S. This page might be useful. See function 'extrude'.

answered 2009-12-16T18:41:50.707

Your Answer