Comments (3)
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.
I need some example understand the concept of reification.I am very confused.
from haxe.org-comments.
https://stackoverflow.com/questions/34974996/creating-a-function-in-a-macro
@ghost
from haxe.org-comments.
Related Issues (20)
- [haxe.org/manual] Implementation details (Standard Library - Json) HOT 1
- [haxe.org/manual] Dynamic (Class Fields - Access Modifier) HOT 10
- [code.haxe.org] Abstract types - Email address as abstract type HOT 1
- [code.haxe.org] Beginner - Pattern matching HOT 2
- [code.haxe.org] Abstract types - Pipe using Abstract Operator Overloading HOT 2
- [haxe.org/manual] Target Details HOT 1
- [haxe.org/manual] Generic HOT 2
- [haxe.org/manual] Null Safety HOT 2
- [haxe.org/manual] Blocks HOT 3
- [haxe.org/manual] Tail Recursion Elimination (TRE) HOT 1
- [haxe.org/manual] Module Sub-Types HOT 3
- [code.haxe.org] Macros - Working with compiler flags HOT 1
- [haxe.org/manual] Extractors HOT 2
- [haxe.org/manual] Array Access (Types - Abstract) HOT 2
- [haxe.org/manual] Overriding Methods HOT 1
- [haxe.org/manual] Variable capture HOT 2
- [haxe.org/manual] Tracing Types HOT 1
- [code.haxe.org] Beginner - Using numbers HOT 2
- [haxe.org/manual] Defines (Target Details - C++) HOT 7
- [haxe.org/manual] Import defaults / import.hx HOT 1
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 haxe.org-comments.