Page 1 of 2

Favorite "underrated" Lisp feature?

Posted: Thu Aug 07, 2008 6:51 am
by tayssir
What's your favorite "underrated" Lisp feature?

For me, it's special variables. Those things reeeally save me from messy situations. Setting up contexts, so I don't have to change much code.

Though funnily enough, I've seen someone abuse the hell out of them. For instance, there'd be code like this:

Code: Select all

(defun a_STZ ()
  (declare (special a stz verb i ...))
  (setf a 10)
  (b_STZ))

(defun b_STZ ()
  (declare (special a stz verb i ...))
  (list a))

(a_stz)
Now, I stripped the code to essentials here; the real code had all sorts of off-by-one errors. I still wonder how he (apparently) learned about DECLARE SPECIAL before LET -- it's like he'd manually add new variables to all the DECLARE SPECIAL declarations whenever he'd need a new one.

Until that point, /I/ didn't really know what DECLARE SPECIAL really did, and I had more Lisp experience than that programmer.

Re: Favorite "underrated" Lisp feature?

Posted: Thu Aug 07, 2008 7:18 am
by findinglisp
For me, it's probably generic functions. Before I "got it" I used to think of GFs simply as methods ala most other object models (C++, Java, etc.), only using a functional syntax, not a typical "message-based" syntax. That's only scratching the surface of what they can do, however. When you realize that GFs can be declared and used even if you never define a single CLOS object in your program and that you can use arbitrary symbols to do dispatching, you have a very powerful tool at your disposal. In fact, you have a generic dispatch mechanism that can all-but eliminate many boring dispatch tables in your code.

An that's without mixing in all the CLOS stuff, method combinations, wild MOP capabilities, etc. In short, very underrated. 8-)

Re: Favorite "underrated" Lisp feature?

Posted: Thu Aug 07, 2008 8:35 am
by makia
I like how you can easily transform code or add new code because syntax and 'everything returns value' concept does not stand on your way. This is very usefuly to me.

Re: Favorite "underrated" Lisp feature?

Posted: Thu Aug 07, 2008 3:43 pm
by schoppenhauer
Compiler Macros

Re: Favorite "underrated" Lisp feature?

Posted: Thu Aug 07, 2008 3:47 pm
by qbg
(FORMAT NIL "~r" some-integer) because it was the first time I've seen some of those words.

ED would be really cool if more implementations provided a resident editor.

Re: Favorite "underrated" Lisp feature?

Posted: Thu Aug 07, 2008 6:03 pm
by death
I don't know about a "favorite" feature, but one underrated Common Lisp feature I appreciate is its pathnames support. Yes, some of it is too complicated, under-specified, or plain historical baggage, but in languages that don't support pathnames, the typical approach to dealing with them is to just use strings. I find that irksome: pathnames are structured objects, not mere character aggregates. I find that for casual, non-super-portable use the pathnames facility is both sufficient and pleasant.

P.S. regarding ED: I have this in my .swank.lisp:

Code: Select all

#+sbcl
(push #'swank:ed-in-emacs sb-ext:*ed-functions*)

Re: Favorite "underrated" Lisp feature?

Posted: Thu Aug 07, 2008 6:50 pm
by findinglisp
schoppenhauer wrote:Compiler Macros
Interesting. Care to say why? I have never really had an occasion to use a compiler macro. Regular macros, yes, all the time. Compiler macros, never.

Re: Favorite "underrated" Lisp feature?

Posted: Fri Aug 08, 2008 2:41 am
by Wodin
tayssir wrote:I still wonder how he (apparently) learned about DECLARE SPECIAL before LET -- it's like he'd manually add new variables to all the DECLARE SPECIAL declarations whenever he'd need a new one.
Maybe he was reading through the CLHS index and DECLARE comes before LET? ;)

Re: Favorite "underrated" Lisp feature?

Posted: Fri Aug 08, 2008 4:49 am
by Geoff Wozniak
findinglisp wrote:
schoppenhauer wrote:Compiler Macros
Interesting. Care to say why? I have never really had an occasion to use a compiler macro. Regular macros, yes, all the time. Compiler macros, never.
Compiler macros are one of those things that you don't appreciate until you need them. That's why they are my favourite underrated feature as well. :)

The situation where I ended up using them involved trying to do code transformations on existing code that I did not have control over. By adding compiler macros on certain symbols, I could affect the code without changing any definitions in the code (assuming there were no existing compiler macros hanging around). This allowed me to write "code that observed code" very easily.

That sort of thing isn't something you need every day, but when you need it, it makes your job much simpler.

Re: Favorite "underrated" Lisp feature?

Posted: Fri Aug 08, 2008 7:29 am
by tayssir
Yeah, you can often MacGyver a rabbit out of your hat with things like generic functions. For instance, someone mentioned the superiority of Haskell's notation for splitting definitions up:

Code: Select all

    fib 0 = 0
    fib 1 = 1
    fib n = fib (n-1) + fib (n-2)
To be cute, I responded with:

Code: Select all

(defmethod fib ((n (eql 0)))
  0)
(defmethod fib ((n (eql 1)))
  1)
(defmethod fib (n)
  (+ (fib (- n 1))
     (fib (- n 2))))
(Is this a silly trick? Well, maybe the whole example is silly -- people who actually need the Fibonacci numbers probably use a different algorithm, beyond even caching. ;) )

Or for those who really like single-inheritance, you can use the MOP and have single inheritance for yourself and your friends.

(Hmm, with single inheritance, I must sound like some people explaining their views on homosexuality: "I don't mind what people do, just as long as they don't force me to do it too.")