r/ProgrammingLanguages • u/TizioCaio84 • Apr 12 '21
What are some cool/wierd features of a programming language you know?
I'm asking this question out of curiosity and will to widen my horizons.
146
Upvotes
r/ProgrammingLanguages • u/TizioCaio84 • Apr 12 '21
I'm asking this question out of curiosity and will to widen my horizons.
3
u/raiph Apr 18 '21
(In repl in case you want to play around.)
Afaik Raku isn't converting the NFAs to DFAs to handle the integration with the host GPL (Raku's MAIN slang) to print that
42. What is it about your approach that means NFAs interfere with your host GPL integration? Or, perhaps more to the point, what is it about Raku's approach which means they don't?One way in Raku that nicely separates the matching code and the host GPL code:
In repl.
Right. That's fundamentally different.
That's a curious comment! Raku is supposed to interoperate with any PL.
Standard Raku doesn't go that far. It provides:
Read-only access to the state of the node of the parse tree as it currently stands while it's being constructed; and
Read-write access to the AST hanging from that node.
Host functions can be:
Passed arbitrary arguments from the ambient GPL processing that's interwoven with, or run parallel with, the parsing process;
Just called, with their return values ignored; or
Called, and their return values used as part of the parsing process.
In this latter case the return value can:
Signal failure, which may, for example, result in backtracking in the input, or simply pruning of some failed part of the parse tree; or
Signal success but without otherwise affecting the parse tree; or
Signal success and return a new node to be added to the parse tree.
These standard facilities do not allow host code to alter the input or take over the parse tree beyond as I've just listed.
To gain more power, metaprogramming is at least required, and compiler plug ins at the extreme.
Ah. There was nothing like regexbuddy back in the day. :)
Gotchya.
That's... I'll go with your "nifty". :)
Raku builds a parse-tree automatically based on the nested region names, but not in the manner you show above. Raku provides simple tools for making a sparse tree that hangs off the parse tree. (As described in my one and only Computer Science StackExchange Answer.) That would allow for your nifty nesting.
The only thing I recall being irksome about them being compiled at compile time is that "adverbs" like "ignore case" have to be set in each individual rule of a set of rules. Hopefully the upcoming macros will provide relief for that, at least within a single compilation unit.