random-state.net

Nikodemus Siivola

<< next | top | previous >>

This Calls for Dispute #
hacking, December 17th 2007

Eric Normand writes about expressing higher-order functions. His case study is basically:

(mapcar (lambda (x) (* x 2)) list)

One of the expressions this can be given is:

(mapcar (curry #'* 2) list)

and another is

(mapcar #L(* 2 _) list)

I realize that some people are really fond of #L. Fine, it's fine — use it. Let's just be fair about the comparison...

Problems of #L according to Eric:

  • It's not widely used, so it might be hard for someone to understand at first glance.
  • Can only be used for functions of one argument.

The same for CURRY:

  • Not very common, so it's not readable by all.
  • #' syntax gets in the way.
  • I would not use it since the form is a bit clunky.

Huh? #' gets in the way and #L does not? How is the CURRY klunky? I just so do not get this. That said, I generally prefer the explicit lambda — though there are exceptions.

Finally, I really don't understand why to use a reader-macro for this when regular macros work for similar purposes more then fine. Use macros when fuctions won't do, and use reader-macros when macro's won't do is a good rule of the thumb in my books.

(defmacro <- (&body body) `(lambda (_) ,@body))

...with the added benefit that the user can macroexpand the form for instant comprehansion.