Comments (3)
Like much of the sugaring we're doing, this raises the question of whether or not we should be doing this with hygienic macros. For example, a for loop could be a macro like this:
macro
"for" $idseq:idseq $type:(":" type | NONE) "in" $iter:seq "do"
$body:seq
$else:("else" seq | NONE)
"end" =
(seq:scope
(= (var $1 NONE) $iter)
(while
(call (dot (ref (id $1)) (id "has_next")) NONE NONE)
(seq:scope
(= (var $idseq $type) (call (dot (ref (id $1)) (id "next")) NONE NONE)
$body
)
$else
)
)
That would allow rewriting directly to AST. Those nodes would have to be checked for validity, of course, before built-in sugaring but after parsing, since they could be nonsense.
The syntax above is obviously pseudocode, and might not work at all.
Macros would then have package scope, and we could indicate on the macro whether or not it should be picked up by an importer. In any case, an importer could only get macros if they imported a package without a qualifying identifier.
Macros would then be treated as elements of a parsing expression grammar, evaluated in the order defined, and the order of package import.
There is a very good chance that this is a terrible idea and we should never do this.
from ponyc.
With array literals, we can now do things like this:
primitive Black
primitive Blue
primitive Red
primitive Yellow
type Colour is (Black | Blue | Red | Yellow)
primitive ColourList
fun tag apply(): Array[Colour] =>
[Black, Blue, Red, Yellow]
for colour in ColourList().values() do
...
end
On the other hand, in expr_reference()
we detect using a type alias name in an expression and reject it. We could instead transform it to an array literal. How exactly to transform it might be a bit tricky.
from ponyc.
Type alias names in expressions work now, so this all works.
from ponyc.
Related Issues (20)
- Feat: Reconsider support for ponyc bundled builds targeting Intel MacOS HOT 1
- runaway memory growth during GC with reference cycle HOT 12
- RFC #77: Assign Param Syntax
- RFC #78: Remove JSON package from the standard library
- Can't built 0.53.0 on aarch64-darwin HOT 8
- Possible violation of the `pthread_create` interface? HOT 4
- Release 0.54.1 HOT 2
- iftype compile error at runtime HOT 7
- [Epic] EL 9 & Fedora support - prebuilt, install.md, and ponyup HOT 1
- XorOshiro naming in random HOT 2
- Incorrect program result when not using --debug HOT 16
- Release 0.55.0
- Segmentation fault when capturing Env via lambda HOT 17
- Segfault when trying to compile incorrect capabilities HOT 12
- With block doesn't call dispose on an object if its name is _ HOT 7
- Web assembly
- Unreported type inference error with Array's in match case statements HOT 9
- Cannot build with --static nor --nopic. HOT 7
- Release 0.55.1 HOT 1
- How to cross compile for armv7? HOT 7
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 ponyc.