Giter VIP home page Giter VIP logo

Comments (3)

markknol avatar markknol commented on May 31, 2024 4

Reification, as far as I understand it, is some sort of sugar to create expressions more easily. The internal structure of the compiler is using enums, so as a simple example you want a macro function to return 123 as expression, you could do this:

public static macro function getNumber() {
  var calculatedValue = 123;
  return {expr: EConst(CInt(calculatedValue)), pos: Context.currentPos()};
}

This can become super unmanagable if you want to return more than just a number, imaging constructing a full class like that🀯 That's what reification is for. Of course, it still requires a bit of knowledge of what you are going to return, in our case we will return a basic type, so we need the macro $v{ } reification-function. This allows to rewrite the macro above to the following:

public static macro function getNumber():ExprOf<Int> {
  var calculatedValue = 123;
  return macro $v{calculatedValue}; 
]

Now there are many reinfication functions to construct anything virtually anything you can do in "normal" Haxe code, on this page the syntax for types is explained. Hope this helps to give you bit of understanding, but also take a look here and check out some real examples at the Haxe cookbook https://code.haxe.org/category/macros/

from haxe.org-comments.

 avatar commented on May 31, 2024 3

I need some example understand the concept of reification.I am very confused.

from haxe.org-comments.

sonygod avatar sonygod commented on May 31, 2024

https://stackoverflow.com/questions/34974996/creating-a-function-in-a-macro
@ghost

from haxe.org-comments.

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.