HaxeFoundation / haxe.org-comments

Repository to collect comments of our haxe.org websites
2 stars 2 forks source link

[haxe.org/manual] Expression Reification #40

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Expression Reification - Haxe - The Cross-platform Toolkit

Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.

https://haxe.org/manual/macro-reification-expression.html

ghost commented 4 years ago

I need some more examples to understand the usage of '$'.

Gama11 commented 4 years ago

Some examples can be found here: https://code.haxe.org/category/macros/

ghost commented 4 years ago

Thank you for your last reply,I have a little problem and don't understand. typedef Measurable = {public var length(default, null):Int;} I don't quite understand the role of (default,null). Why length becomes read-only.

KiKli

ghost commented 4 years ago

I I just tried to change public var length(default, null):Int; to public var length:Int;,

the compilation failed, and Inconsistent setter for field length : null should be default was displayed. length(default, null) means a setter and null means it cannot be assigned. Is this correct? Looking forward to your reply.

markknol commented 3 years ago

To understand (default,null) you need to look into field properties. But it means something like normal access on get, only access in current class on set.

Geokureli commented 3 years ago

I'm having trouble understanding what a block expression is, regarding $b{}. does it just concatenate the expressions or is it creating a semi-colon delimited block of expressions?

Aurel300 commented 3 years ago

@Geokureli It's the latter. For example:

var a = macro foo;
var b = macro bar;
macro $b{[a, b]};

Becomes:

{
  foo;
  bar;
}