Re:Problems with Lisp
by pmjordan on Sunday January 25, 2009 @04:39PM
(#449573)
Yep, the funcall semantics of symbols and keywords are to forward the symbol and key itself along with the arguments to the get function.
I do sometimes use this notation, mostly when:
- the map could be nil. (get nil :foo) and (:foo nil) will return nil, but (nil :foo) will throw an exception.
- dealing with struct-maps, where the key can effectively be seen as an accessor function. (cf structs in CL)
- (rarely) when the expression evaluating to the map is long and complex. A keyword in the function position (a) makes it clear that what follows must be a map or set and (b) you don't have to start counting parens.
I do sometimes use this notation, mostly when:
- the map could be nil. (get nil :foo) and (:foo nil) will return nil, but (nil :foo) will throw an exception.
- dealing with struct-maps, where the key can effectively be seen as an accessor function. (cf structs in CL)
- (rarely) when the expression evaluating to the map is long and complex. A keyword in the function position (a) makes it clear that what follows must be a map or set and (b) you don't have to start counting parens.