Skip to content
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

[2.0] Add support for macros #153

Closed
foxbunny opened this issue Nov 26, 2018 — with GitSpeak · 2 comments
Closed

[2.0] Add support for macros #153

foxbunny opened this issue Nov 26, 2018 — with GitSpeak · 2 comments

Comments

Copy link

Currently, there's quite a bit of duplication in operators. One rationale for that is that it allows users coming from different languages to feel comfortable. After all, that's how Imba started.

With 2.0, I think all such duplication should be removed and we should settle on the best option in each case as seen by the community (and primarily the Imba developers).

To counter the effect of missing syntax, I propose adding macros to the language. A 'macro' would be a piece of comment that would be added to the top of the source code which would apply from that point on to any Imba code in the same module. The comment would specify a pattern and a replacement for the pattern.

For example:

#macro $x ? $y :  $z ==> if $x then $y else $y

The placeholders that begin with $ are treated as "any valid expression", or at least "any value or variable reference". In the macro body, the expressions referenced by placeholders will be inserted as is.

The compiler would also have the ability to use a macro file during compilation which contains multiple macros that are applied to any Imba modules compiled.

With macros, users would have the ability to add back any syntax that would be removed in 2.0, and the project could also publish a macro file containing such syntax for those that may like to stick to the old syntax or have an easier transition.

Macros could also open the door for custom operators like:

#macro $x eq $y ==> deepEquals $x, $y

Multi-line macros would have a newline right after ==> and span multiple lines until #endmacro

#macro [$x..$y] ==> 
#(do 
#    var i = $x
#    while i < $i
#        ++i
#)()
#endmacro

Now if we use the above in the code:

var x = [40..100]

it would be treated by the compiler as if the following was written

var x = (do 
    var i = 40
    while i < 100
        ++i
)()

Of course, there are potential pitfalls with this, as the example macro would also mean that arr[1..20] would yield wonky results. But that's on the user pretty much. With great power, comes great responsibility. :)

@somebee somebee added the proposal label Aug 4, 2020 — with GitSpeak
@stale
Copy link

stale bot commented May 4, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@peter-wasilko
Copy link

Perhaps we can revisit this topic.

Dough Hoyte's "Let Over Lambda" (ISBN 978-1-4357-1275-1) https://letoverlambda.com/index.cl makes the strongest case from Macro support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants