Comments (3)
You're correct that you can perfectly well use macros instead of Q-Expressions and essentially you can get the same thing - the quote macro is a bit like the Q-Expression indeed. There are subtle differences and pros and cons on both sides. Probably a real macro system is better for a kind of industrial strength Lisp, but I find Q-Expressions kind of nice in terms of simplicity and ease of learning.
To be a bit more precise about the comparison - a Macro is like a function that does not evaluate its arguments first: so if def
is a macro then (def x blah)
is kind of like (def {x blah})
using Q-Expressions. Some macros are also special macros and do special things e.g. assigning variable names, while in our lisp some functions are special functions and do things like assigning variable names.
Some arguments in favor of Q-Expressions over Macros:
- With Macros there is no syntax distinguishing between a function and a macro. The only way to know if
(blah x y)
is going to evaluatex
or not is to know ifblah
is a macro rather than a function. For this reason I think Q-Expressions can be easier spot and to intuitively understand. - Because you can write functions that return Q-Expressions you can build a Lisp using fewer builtin functions (i.e. just assignment and lambda), making things more homoiconic and simple.
Some arguments against Q-Expressions over Macros:
- Q-Expressions make lexical scope difficult to implement compared to Macros, which can cause obscure and difficult variable shadowing bugs due to dynamic scope. (However, a hygienic Macro system is not that easy to implement either).
- In some places you need to work around things being eagerly evaluated by wrapping them in Q-Expressions e.g. the
head
function. - Q-Expressions are fairly unusual/uncommon in other Lisps.
I actually think either is fine - if you want to switch the language to using Macros I think that is a pretty good exercise 👍
from buildyourownlisp.
Thanks, I managed a first cut of a C++ version https://github.com/lewismj/inky , I'll update my docs, to better explain things re: Q-Expressions and Macros. Enjoyable experience. Picked this up as an exercise to learn Spirit - I was going to try to use Boost Spirit. I'm familiar with FastParse (Scala) and Parsec (Haskell) but ... gave up with Spirit.
from buildyourownlisp.
Thanks very much for the explanations. Really appreciated!
from buildyourownlisp.
Related Issues (20)
- Errors with MPC HOT 1
- PCQ Rename
- Wrong name of source.tar.gz
- Segmentation fault chapter 6 mpc
- Average expression for extra points HOT 1
- [noob] can I learn this project and `antlr` at the same time
- Segfault being caused by mpc_parse_run HOT 4
- A link in chapter two doesn't exist anymore. HOT 4
- Suggesting msys2 instead of MinGW In Ch2 installation compiler section
- GNU Readline 8.1 does not use history.h anymore
- Not Isue, help with decimal numbers HOT 2
- Loops HOT 5
- Function defintions HOT 2
- Syntax for Lambda expressions
- How can we implement macros HOT 1
- Print statement not working while evaluating file HOT 3
- it's not work until I remove eval_op() and eval(). It's hard to follow
- What is the best way to include stdlib into binary? HOT 2
- Doesn't properly handle a single negative number as the input in `evaluation.c`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from buildyourownlisp.