3 ms·
Heh. If you see [1], they define a function called "user-email" (spelled correctly). The lisp convention here would be to define the accessor as something like
by vzcx 9y ago
Heh. If you see [1], they define a function called "user-email" (spelled correctly). The lisp convention here would be to define the accessor as something like "%user-email." While the code isn't too bad, these little things betray a lack of knowledge of lisp lore. Perhaps another reason for the rewrite was that the team actually didn't have much experience writing lisp code.
[1] https://github.com/reddit-archive/reddit1.0/blob/bb4fbdb5871a32709df30540685cf44c637bf203/data.lisp#L336 https://github.com/reddit-archive/reddit1.0/blob/bb4fbdb5871...
- kazinator 9y agohttps://github.com/Clozure/ccl/blob/master/lib/case-error.lisp#L51 https://github.com/Clozure/ccl/blob/master/lib/case-error.li... %assertion-failure doesn't look like an accessor. http://clhs.lisp.se/Body/f_car_c.htm http://clhs.lisp.se/Body/f_car_c.htm car described as "accessor", not named %car. No public function in CL is named this way. In fact, the character % doesn't make an appearance at all: http://www.lispworks.com/documentation/lw50/CLHS/Front/X_Perm_9.htm http://www.lispworks.com/documentation/lw50/CLHS/Front/X_Per... I've never named a function or macro %something in 18 years of Lisp.
- vzcx 9y agoSure, sure. But while it's definitely not in the standard, I do see it all over, and it's something I picked up from reading a lot of other people's lisp. SBCL internals, for example. You might not like the convention and chose not to follow along with it, but I would be surprised if, after 18 years of lisp, you had never seen it before, and would choose to misspell an accessor to prevent a clash instead of naming it differently. Edit: ah, I think I understand. I don't mean to imply that all accessors should be named in this way. That would be gross.
- kazinator 9y agoI've never seen this outside of internals. In application code, this is just a smell. To prevent clashes, there are packages. What will you do if three or more modules want the same function name? Tack on %%, %%%, ...
- vzcx 9y agoOnly in implementation internals? I'm fairly certain I've encountered it in other unexported package symbols in library code, things like struct constructors where you want a "smarter" "make-my-struct" function. But perhaps I misremember. > What will you do if three or more modules want the same function name? Tack on %%, %%%, ... Certainly not! I think your points are all very fair: it would be a smell, and is evidence of a need for improvements at a more structural level. It just smells a little less than a seemingly purposeful misspelling to my nose.
- jjwiseman 9y agoTo be explicit, the old Lisp convention I know of, which is not a super common one but one I've definitely used quite a bit, is that you might name a slightly lower-level/more primitive version of a function with a %-prefix. So if we have a user-email function that is just an object slot accessor, We could have %user-email that actually does a database query. I can't remember for sure, but I wouldn't be surprised if I'd seen a double %%-prefix used, too. You don't always want to put those functions in separate packages (traditionally in Lisp, packages are relatively heavyweight--e.g. an entire web server framework might have only one or two packages). Another similar example might be the convention of defining a macro with the name my-macro, and a function that actually implements much of the macro, or is an equivalent of the macro that takes a thnk, that is named my-macro*. (24 years of lisp here--I wouldn't be surprised if the conventions of mainstream lisp during the earliest six years were somewhat different than the following decades.) Edited to add: Now that I think about it, this convention may have been heavily used in the Macintosh Common Lisp community.
- vzcx 9y agoThank you, and thank you to the grandparent. It's quite fantastic to be schooled by old-time lispers (only 6 years of lisp here).
- kazinator 9y ago> Macintosh Common Lisp community. That's why I linked to some CCL code (descendant of MCL). I use foo-impl and such for the implementation of foo. If I have a my-macro, which is implemented by an expander function, then I call that function expand-my-macro.