-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multi-stage programming (macro) system #492
Labels
Comments
mtshiba
added
enhancement
New feature or request
RFC
New specifications of Erg
syntax
labels
Feb 19, 2024
It may be difficult to tell which is which with the syntax |
mtshiba
changed the title
Add multi-stage compilation system
Add multi-stage programming (macro) system
Mar 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here I propose to add a multi-stage programming (macro) system to Erg.
Motivation
Erg is compatible with Python's API. In other words, Erg is an alt Python.
However, Erg's syntax is far different from Python's. Whereas Python has statements, almost everything in Erg is expressions.
if
andfor
are also implemented as functions rather than statements.This makes Erg code look very different from Python code.
If you try to write an else clause in
if
, you will need two indentations.for!
has the opposite order ofi
anditerable
compared to Python'sfor i in iterable: ...
, which is confusing. I admit that Python's syntax is simpler.However, I feel reluctant to bring the concept of statements into Erg. I want to minimize basic grammar.
Draft plan
Therefore, I will introduce a hygienic macro system to Erg. It is heavily inspired by Scala and defines macros as functions that receive syntax elements and return syntax elements.
To introduce macros, two syntaxes will be added:
${}
and'{}
.${ x }
takes an expressionx
of typeT
and returnsExpr T
.'{ x }
takes an expression of typeExpr T
and returnsT
.Use these to implement
if, for!, import
.Note that if this proposal is implemented, the current
if
function etc. will be moved to thecontrol
module instead of built-in.Then we can use them:
The text was updated successfully, but these errors were encountered: