Ninety-Nine Lisp Problems(ic.unicamp.br)
ic.unicamp.br
Ninety-Nine Lisp Problems
http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html
10 comments
I looked at the first solution and my reaction is something along the lines of "what????".
Why not just something simple like.. (defun foo(thing) (list (nth (1- (length thing)) thing))
Same applies for problem 2.
Why not just something simple like.. (defun foo(thing) (list (nth (1- (length thing)) thing))
Same applies for problem 2.
And for number #5 you don't even need to write a function. Why not just use reverse? And notice his indentation and closing of parens is all wrong (i.e. not Lisp style). He's writing Lisp code thinking in a another language[1].
It's still a good exercise to go through them all as a Lisp newb like myself when I'm bored or need a break.
[1] Programming language, not Portuguese. :)
It's still a good exercise to go through them all as a Lisp newb like myself when I'm bored or need a break.
[1] Programming language, not Portuguese. :)
Well using reverse sort of misses the point. You are supposed to implement reverse.
I think you don't really want to use length. Since it is a program evaluating last it might not be that bad as you have to goto the last element anyway.
Here is mine:
(defun our-last (list) (if (rest list) (our-last (rest list)) list))
Here is mine:
(defun our-last (list) (if (rest list) (our-last (rest list)) list))
Or even
(defun last(thing)
(car (reverse thing)))
Given the context(first two problems), what is a 'box'?