Favorite "underrated" Lisp feature?

Discussion of Common Lisp
tayssir
Posts: 35
Joined: Tue Jul 15, 2008 2:33 pm

Favorite "underrated" Lisp feature?

Post by tayssir » Thu Aug 07, 2008 6:51 am

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.

findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: Favorite "underrated" Lisp feature?

Post by findinglisp » Thu Aug 07, 2008 7:18 am

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-)
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

makia
Posts: 25
Joined: Tue Jul 22, 2008 2:37 am

Re: Favorite "underrated" Lisp feature?

Post by makia » Thu Aug 07, 2008 8:35 am

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.

schoppenhauer
Posts: 99
Joined: Sat Jul 26, 2008 2:30 pm
Location: Germany
Contact:

Re: Favorite "underrated" Lisp feature?

Post by schoppenhauer » Thu Aug 07, 2008 3:43 pm

Compiler Macros
Sorry for my bad english.
Visit my blog http://blog.uxul.de/

qbg
Posts: 64
Joined: Mon Jun 30, 2008 1:05 pm
Location: Minnesota

Re: Favorite "underrated" Lisp feature?

Post by qbg » Thu Aug 07, 2008 3:47 pm

(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.

death
Posts: 17
Joined: Sat Jun 28, 2008 1:44 am

Re: Favorite "underrated" Lisp feature?

Post by death » Thu Aug 07, 2008 6:03 pm

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*)

findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: Favorite "underrated" Lisp feature?

Post by findinglisp » Thu Aug 07, 2008 6:50 pm

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.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Wodin
Posts: 56
Joined: Sun Jun 29, 2008 8:16 am

Re: Favorite "underrated" Lisp feature?

Post by Wodin » Fri Aug 08, 2008 2:41 am

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? ;)

Geoff Wozniak
Posts: 9
Joined: Wed Jul 16, 2008 5:38 pm
Location: Canada

Re: Favorite "underrated" Lisp feature?

Post by Geoff Wozniak » Fri Aug 08, 2008 4:49 am

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.

tayssir
Posts: 35
Joined: Tue Jul 15, 2008 2:33 pm

Re: Favorite "underrated" Lisp feature?

Post by tayssir » Fri Aug 08, 2008 7:29 am

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.")

Post Reply