Jump to content
  • Advertisement
Sign in to follow this  
john13th

Generate list in Lisp?

This topic is 4420 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do you create a list in Lisp that looks like this for an example: (generate-list 10 #'(lambda (n) (- n 2)) 5) => (10 8 6 4 2)

Share this post


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!