News for hackers. Stuff that matters.
Re:Lisp in Small Pieces of Clojure, part 3 by kazinator on Monday April 30, 2018 @03:13AM (#16956445)
What is your rewrite rule for reducing (set! var value) to application?

For iteration and selection, did you just turn everything into lambdas? E.g.

  (if x y z) -> (__if_fun (lambda () x) (lambda () y) (lambda () z))
If you minimize the special forms, you have fewer cases in the expanding code walker; but then the compiler has little information for producing good code.

Note that a compiler doesn't necessarily just let every instance of function application be function application. If the above expansion for if is forced upon you as a compiler writer, you can recognize the __if_fun function as a built-in and open-code it, effectively undoing the reduction to function application.

Check that all arguments are lambdas (and diagnose if they aren't zero-argument lambdas) destructure them and turn into an open-coded branching construct.

The cost for fewer code walking cases in the macro expander ends up being more cruft in the compiler.

About let to lambda: in non-toy implementations, you almost always want to go the other way: recognize lambdas which can be turned into lets.

There are no comments on this comment yet.