Function identifiers unloved?

Looking at common Lisp sources I noticed that people most often use #'foo , where 'foo will be enough - that is, wherever a function tag is accepted, they choose to pass a function.

Of course, #'foo necessary when foo is defined via flet and so on. 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 sometimes don't work? Even if that were the case, this would not explain the use of #'(lambda ...) , because #' is not always needed here.

CL is sometimes called ugly because of #' , and most beginners do not realize that this is unnecessary (I dare to suggest) most cases. I'm not a newbie, but I prefer 'foo . Why am I unusual? If I publish some code that gives the characters funcall and apply , will I be mocked and humiliated? I am considering creating the chapter "Anonymous Functions" in my area. I suspect that people want to use function pointers, but, because of peer pressure, they are afraid to "get out" about it.

+4
source share
3 answers

Using #' conceptually simpler: regardless of whether you are dealing with an anonymous function, the function obtained by calling compile , or the function referenced by #' , you always refer to the function object. Given this, passing a character to map or funcall is an odd special case, which is just not as intuitive as passing a function object.

However, there are cases where characters are perhaps more conceptually suitable, for example, in the case of the argument :test for make-hash-table . In this case, you select one of four different hash tables specified by the name of the key comparison function. I prefer the symbol in this case, since it makes no sense to use a function object to distinguish one kind of hash table from another. (This is also misleading, as it seeks to trick you into believing that you can pass any arbitrary equivalence predicate to a make-hash-table .)

+4
source

They do not match. 'foo is a reference to what happens with the global definition of the function foo , and is a remnant of the old days when areas where it is very confused.

 CL-USER(1): (defun foo (x) 1) FOO CL-USER(2): (flet ((foo (x) 2)) (mapcar #'foo '(1 2 3))) (2 2 2) CL-USER(3): (flet ((foo (x) 2)) (mapcar 'foo '(1 2 3))) (1 1 1) 
+3
source

These are two separate decision styles that everyone must make for themselves. I have never seen criticism of any of the four combinations.

Personally, I prefer to use #' instead of ' because it makes the functions more visible. I think this is not ugly at all - on the contrary, I like this more explicit syntax. Although, when programming in Clojure, I rarely miss it.

However, I use lambda without a harsh quote. A good discussion of this can be found in Let over Lambda . And the original argument for #'(lambda... refers to Kent Pitman, I suppose.

0
source

All Articles