Replies: 6 comments 23 replies
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
I like the idea of having |
Beta Was this translation helpful? Give feedback.
-
|
My concern with this proposal is that using a single token to represent the opening and closing of a syntax quote will make writing a macro that expands to something containing a syntax quote difficult to write/read. |
Beta Was this translation helpful? Give feedback.
-
|
It's probably 50 year too late to change this, but I hate that most (all?) programming languages use the same character to start and end an string (Preemptive reply: Yes, but nobody uses |
Beta Was this translation helpful? Give feedback.
-
|
I've pushed the change to use As one example, the macro becomes Initially, I expected to push this change in a branch, so we could try out it. But it ended up being an involved change, and part of the reason things get better is that the change enabled and forced a generalization of syntax objects to gracefully handle single-term, single-group, and multi-group syntax objects. So, whatever syntax we settle on, I'm pretty sure the path runs through this version of the implementation. The generalization to different kinds of syntax objects is why |
Beta Was this translation helpful? Give feedback.
-
|
I like the general idea of rhombus of using indentation to define blocks, but I think that blocks of code in macros are weird enough to go back to matched parenthesis. It's slightly similar to strings, that really need a starting and an ending border. I insist in using a different delimiter for each border, so nesting is easier. And my idea is to use I'm not sure if this makes sense, but my proposal is |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In response to the recent discussion on macros on Rhombus, I would like to share my own ideas on how we can make macro definitions more ergonomic and user friendly. The main idea is to remove incidental details so that the programmer can focus on essential parts of the macro definition.
Today, defining a macro looks something like this (from the docs):
Defining a macro requires using
expr.macrowith a template denoted by'( ... ), and a block that returnsvalueswhere the first argument is a template with the resulting expanded code and the second argument is matched syntax to be handled by something else. (You can also define a macro usingdefwithout the need forvalues).In this post, I would like to propose a few changes to the syntax for the sake of discussion. To do that, I will use a toy-example macro that imitates python's list comprehensions.
(In today's macro system)
Support for single return
When writing a macro that consumes all of its matched input and would return
values( ..., '()), it would be nice to be able to simply return the template without the need to call values.This would implicitly produce
values('(base.map(fun($a): $exp , $lst)), '()). This would make it similar to howdefcreates macros when given a template and a body with a resulting template. It also just makes it a little bit cleaner.Templates created with back-ticks or single-quotes
Instead of using single-quote as a prefix operator paired with parentheses
'(...)to create a template, we could use back-ticks or single-quotes as a new type of parentheses. This would require an extension to shrubbery but could make templates cleaner by removing extra parentheses.My first idea involved using back-ticks, but after some discussion with @mflatt, it seemed like it would be better to use single quotes, specifically to avoid clashing with markdown. Below, I've included examples using both for the sake of discussion.
Using back-ticks:
Pros:
Cons:
Using single-quote
Pros:
'()formsCons:
Other examples with proposed ideas
Beta Was this translation helpful? Give feedback.
All reactions