3 ms·
With these reader macros, can the code in the blog example be rewritten as below, so it still directly maps to the Lisp tree-like semantics, but be more readabl
by vorg 16y ago
With these reader macros, can the code in the blog example be rewritten as below, so it still directly maps to the Lisp tree-like semantics, but be more readable?
defun diff(expr, x){
if(expr == x) 1
else if(car(expr) == 'plus') ['plus', diff(cadr(expr), x), caddr(expr), x]
else if(car(expr) == 'times')[
'plus',
['times', cadr(expr), diff(caddr(expr), x)],
['times', diff(cadr(expr), x), caddr(expr)]
]else 0
}
- jpr 16y agoI have to admit that I'm not an expert on reader macros, so I can't say for sure. Your example seems to map some already used characters, so it wouldn't be a pure extension of the reader. I guess you could make a readtable that recognizes that syntax and transforms it to the tree-like semantics. FWIW, I don't find it more readable than the standard notation. Maybe I have become too accustomed to the standard CL-notation.
- crux_ 16y agoI'm sure it's possible; lisp is very flexible. But would your example code still be considered lisp?