3 ms·
Except you can, just use reader macros.
by jpr 16y ago
Except you can, just use reader macros.
- prodigal_erik 16y agoLisp is a remarkable toolkit for creating domain-specific languages with any syntax you happen to need. It amazes me how many people try to use it as an ordinary programming language without modifying it at all, and then give up because they found nothing special about it. I think they're missing the point.
- vorg 16y agoWith 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?