3 ms·
That code scares me. Someone please tell me there is a way to write lisp that doesn't make me want to shoot myself in the head. Is this representative of "pro
by S_A_P 16y ago
That code scares me. Someone please tell me there is a way to write lisp that doesn't make me want to shoot myself in the head. Is this representative of "proper" lisp syntax?
- lispm 16y agoIf you still use punch cards (this Lisp code was written in punch cards) to feed programs into your computer, then it is a good way. If not, you can use a text editor and format your code differently.
- weavejester 16y agoNot really. I find I very rarely write functions with explicit loops, because there is usually a higher-level function that encompasses what I want to do. For example, in Clojure I'd write the flatten function as: (defn flatten [x] (remove sequential? (tree-seq sequential? seq x))) Other lisps probably have similar functions.
- jimbokun 16y agoDidn't know about tree-seq. Cool. I suspect I will find a lot of uses for it, now that I know about it.
- rayiner 16y agoIt's scary because it's old and ALL IN CAPS. Modern Lisp code is much easier to read, especially in a proper editor with syntax highlighting and braces matching. Eg, fib in C: int fib(int n) { if(n < 2) return n; return fib(n - 1) + fib(n - 2); } (defun fib (n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2))))) The parens aren't really that annoying once you get used to them, and I personally find them a lot less distracting than the profusion of commas and curly braces that C-syntax languages use in their place. Eg: {{"apples", RED}, {"bananas", YELLOW}, {"oranges", ORANGE}} '(("apples" RED) ("bananas" YELLOW) ("oranges" ORANGE)) Also, don't forget that abstraction makes everything more readable: (dolist (var '(1 2 3 4)) (princ a)) for(list::iterator itr = list.begin(); itr != list.end(); ++itr) { cout << *itr; }
- derleth 16y agoTo be excruciatingly explicit: That code is 51 years old. Nobody writing Lisp now writes code that looks like that. Lisp environments are no longer based around punch cards and computers the size of a row of filing cabinets with the computational power of a fifteen-year-old cell phone. Trying to judge what Lisp is from that code is akin to trying to judge what airplanes are from something the Wright brothers built in their bicycle shop.