Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function designators unloved?

Browsing through Common Lisp sources I notice that people most often use #'foo where 'foo would suffice – that is, wherever a function designator is accepted, they choose to pass a function.

Of course #'foo is necessary when foo is defined via flet and so forth. I understand the mechanics of it all – my question is one of style. Is it just because people don't want to think about 'foo versus #'foo, so they use the latter because the former will sometimes not work? Even if that were so, it wouldn't explain the use of #'(lambda ...) because #' is always unnecessary there.

CL is sometimes called ugly because of #', and most newcomers don't realize that it's unnecessary in (I daresay) the majority of cases. I'm not a newcomer but I happen to prefer 'foo. Why am I unusual? If I publish some code that gives symbols to funcall and apply, will I be mocked and humiliated? I am considering starting a Function Designators Anonymous chapter in my area. I suspect that people want to use function designators but, due to peer pressure, are afraid to "come out" about it.

like image 676
Brian Watkins Avatar asked Oct 09 '11 19:10

Brian Watkins


1 Answers

Using #' is conceptually simpler: Whether you're dealing with an anonymous function, a function obtained by calling compile, or a function referenced with #', you're always referencing a function object. Given this, passing a symbol to map or funcall is an odd special case that is simply not as intuitive as passing a function object.

However, there are cases where symbols are arguably conceptually more appropriate, such as in the case of the :test argument to make-hash-table. In this case, you're selecting one out of four different kinds of hash tables specified by the name of the key comparison function. I prefer a symbol in this case, since there is no point in using a function object to distinguish one kind of hash table from another. (It is also misleading, since it tends to deceive you into believing that you can pass just any arbitrary equivalence predicate to make-hash-table.)

like image 111
Matthias Benkard Avatar answered Sep 28 '22 08:09

Matthias Benkard