Giter Club home page Giter Club logo

Comments (3)

sylvanc avatar sylvanc commented on May 14, 2024

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.

sylvanc avatar sylvanc commented on May 14, 2024

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.

sylvanc avatar sylvanc commented on May 14, 2024

Type alias names in expressions work now, so this all works.

from ponyc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.