Re:CL21: An experimental project redesigning Common Lisp
by beeworker on Thursday February 19, 2015 @08:25PM
(#9078362)
Ah, but how would you easily access the number 6 out of the nested list '((((5 4 3 2 1) 6) 7) 8 9) without one of the cute compositions of "car" and "cdr"? In this case, "cadaar". (Rhetorical question. "car" and "cdr" are neat for their cute composition, but I would never inflict that on someone first learning the language.)
[ Parent
| on HN ]
Re:CL21: An experimental project redesigning Common Lisp
by ajuc on Friday February 20, 2015 @04:20AM
(#9079650)
(def x ((((5 4 3 2 1) 6) 7) 8 9))
(get-in x (0 0 0 1))
Probably botched quoting, don't know common lisp, only clojure.
Re:CL21: An experimental project redesigning Common Lisp
by GregBuchholz on Friday February 20, 2015 @11:34AM
(#9081165)
For the heck of it, I though I'd try it in scheme with pattern matching...
(let ((x '((((5 4 3 2 1) 6) 7) 8 9)))
(syntax->datum
(syntax-case x ()
((((_ p) _) _ ...) #'p))))
Re:CL21: An experimental project redesigning Common Lisp
by chongli on Friday February 20, 2015 @04:23AM
(#9079656)
One word: lenses.
Re:CL21: An experimental project redesigning Common Lisp
by Flow on Friday February 20, 2015 @05:36AM
(#9079854)
And how would that look for this particular example?
Re:CL21: An experimental project redesigning Common Lisp
by chongli on Friday February 20, 2015 @02:53PM
(#9082544)
Definitely not as terse but far more general, flexible and powerful. With car and cdr you're restricted to working on cons cells while lenses are generic.
Some examples (from Haskell):
>>> ((((5,4,3,2,1),6),7),8,9) & view (_1 . _1 . _2)
6
>>> ((((5,4,3,2,1),6),7),8,9) & (_1 . _1 . _2) .~ 4
((((5,4,3,2,1),4),7),8,9)
>>> let foo = ((((5,4,3,2,1),6),7),8,9)
>>> foo & view (_1 . _1 . _2)
6
>>> let six = _1 . _1 . _2
>>> foo & view six
6
>>> foo & six .~ 4
((((5,4,3,2,1),4),7),8,9)
>>> foo & six .~ "abc"
((((5,4,3,2,1),"abc"),7),8,9)