BuildYourOwnLisp icon indicating copy to clipboard operation
BuildYourOwnLisp copied to clipboard

How can we implement macros

Open ssrangisetti opened this issue 4 years ago • 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

ssrangisetti avatar Dec 30 '21 12:12 ssrangisetti

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!

orangeduck avatar Dec 31 '21 09:12 orangeduck