Open utterances-bot opened 4 years ago
I need some more examples to understand the usage of '$'.
Some examples can be found here: https://code.haxe.org/category/macros/
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
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.
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.
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?
@Geokureli It's the latter. For example:
var a = macro foo;
var b = macro bar;
macro $b{[a, b]};
Becomes:
{
foo;
bar;
}
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