orangeduck/BuildYourOwnLisp

How can we implement macros

Opened this issue · 1 comments

The approach I am taking is to make macro similar to lambda and pass arguments as q expressions and macro would return q expression which I will evaluate. But since we cannot create s expressions macros have to return them as q expressions (eg. (* (+ 1 2) 3) will be returned as {* {+ 1 2} 3}). But I am having issues with differentiating between actual q expressions and s expressions converted to q expressions. I have tried using keyword qexpr like {qexpr {a b c d}} would represent {a b c d} but this approach fails if we ever use join on this.

Is it possible to implement macros without any special syntax like quote? Or is quote actually required for having macro support

The main difference between Macros and Q-Expressions is that with Macros you actually look at the function name itself to decide if it is going to evaluate the arguments or not. Where are with Q-Expressions there is dedicated syntax to halt evaluation. So perhaps I would start by making a way to define functions which do not evaluate their arguments, and have these be detected in the evaluation function. Hope that helps!