4 ms·
Indeed, I like that better than either typical prefix or infix nested expressions. What do you advise in the case the expression tree is a little bit more comp
by lliamander 9y ago
Indeed, I like that better than either typical prefix or infix nested expressions.
What do you advise in the case the expression tree is a little bit more complex?
For example:
(setv result (- (/ (+ 1 3 88) 2) (* 8 (+ 3 2)))
- mthomas 9y agoI don't see any clever way to make that more readable. I would have to break it into two subexpressions and then take the difference. i.e. (setv e0 (-> (+ 1 3 88) (/ 2))) (setv e1 (-> (+ 3 2) (* 8))) (setv result (- e0 e1))
- kazinator 9y agoBTW doesn't setv support multiple pairs? (setv e0 (-> (+ 1 3 88) (/ 2))) e1 (-> (+ 3 2) (* 8)) result (- e0 e1)) like setq and setf in CL.
- jlarocco 9y agoBecause the operators all take a list of values it's sometimes convenient to format them like any other long list, with each nested sub-expression on its own line to form a tree: (setv result (- (/ (+ 1 3 88) 2) (* 8 (+ 3 2))) Another possibility is to use a (let ...) to give nested values temporary names, like: (setv result (let ((first (/ (+ 1 3 88) 2)) (second (* 8 (+ 3 2)))) (- first second))) It helps if "first" and "second" have meaningful names like "velocity" or "force" that can describe what they are.