Sign in to follow this  

Generate list in Lisp?

Recommended Posts

Guest Anonymous Poster
Like this:

(defun generate-list (start-num func iters)
(if (= 0 iters) '()
(cons start-num (generate-list (funcall func start-num) func (- iters 1)))))

[26]> (generate-list 10 (lambda (n) (- n 2)) 5)
(10 8 6 4 2)

Sharpquoting lambda expressions is unneccesary; they already return a function.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this