@define in docs

4 views
Skip to first unread message

Bill Hart

unread,
Sep 17, 2013, 1:19:53 PM9/17/13
to crack-l...@googlegroups.com
Hi,

I just noticed that the following example does not compile for me from the docs:

@ import crack.ann define;

@define max(Type) {
   Type max(Type a, Type b) {
       return a > b ? a : b;
   }
}

int a = 3, b = 5;

x := @max(a, b); 
It seems like one has to do:
@max(int)
int a = 3, b = 5;
x := max(a, b);
though that seems to not be the intention of that example.
Bill. 

Conrad Steenberg

unread,
Sep 17, 2013, 1:28:42 PM9/17/13
to crack-l...@googlegroups.com
Hi Bill,

@max is the name of the define, and it takes only one argument.

The code for the max() function is injected when the macro is 'called'
with @max(int).

This is similar to the C #define:
#define func(Type) function func(Type a) { return a*2; }

(In C it would be a bad idea to name the define and the function the
same name, but Crack allows you to do that because @func is different
from func)

Hope this helps,
Conrad
> --
> You received this message because you are subscribed to the Google
> Groups "crack-lang-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to crack-lang-de...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.


Reply all
Reply to author
Forward
0 new messages