Missing/nice to have info about Macros
I would like to slowly compose a list of stuff that I bump into while playing around with macros, so we can later on improve the docs.
Working with $typeof
- I found it a bit difficult to find what is available on the result of
$typeof, currently it's listed on top of the reflection page. The documentation for$typeofshould ideally mention that the attributes are at the top. -
nameofmissing from the attributes
Working with $membersof
-
.getshould be mentioned in the docs
Add an example for working with macros and generics
macro @test_list(a)
{
var $Type = $typeof(a);
$if $defined(a[0]) &&& $Type.typeid == List(<$typeof(a[0])>).typeid:
$echo("LIIIIST");
$else
$echo("NOT LIST");
$endif
}
macro @example(t_slice)
{
var $type = $typeof(t_slice);
}
Error: A type must be followed by either (...) or '.'.
This is not an error
macro @example(t_slice)
{
var $Type = $typeof(t_slice);
}
from: https://github.com/c3lang/c3c/issues/1553
#76
Another thing I ran into:
macro @escape_sequence(String seq)
{
return "\u001b" +++ seq;
}
const TEST = @escape_sequence("[H");
Fails to compile and places the error at the "\u001b" literal, complaining it's not compile time constant.
The fix is to simply prefix seq with $:
macro @escape_sequence(String $seq)
{
return "\u001b" +++ $seq;
}
const TEST = @escape_sequence("[H");
The difference between the different types of macro parameters should probably be mentioned:
- no prefix
param - dollar sign prefix
$param - hash prefix
#param
Edit:
Nevermind, it's in there, but half a page down. Looking at it, maybe we should split macros into the "differences between C" and the actual macro system info.