Search Mailing List Archives

Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[terralang] How to defer the typing of a variable?

Zach DeVito zdevito at
Mon Jun 22 12:43:37 PDT 2015

Macros are run during typechecking allowing you to query the types of
arguments. So you can do something like:

local lazyselect = macro(function(c,x,y)
    local T = x:gettype()
    return quote
        var r : T
        if c then
            r = x
            r = y

terra foo(a : bool, b : int, c : int)
    return lazyselect(a,b,c)


On Mon, Jun 22, 2015 at 6:26 AM, Leonard Ritter <paniq at> wrote:

> Hi everyone,
> I'm writing a code generator that works based on expressions only (very
> much in the spirit of Lisp and Scheme), and I hit upon a problem today
> where would not include the statements included in a quoted
> expression in its branch but rather post them top level.
> I filed a bug report for that here
> So instead, I went and looked into how to do conditional expressions with
> if-else blocks instead, and it seems I can not purely do this with
> expressions. What I had in mind was something like this:
> quote
>     var result
>     if [ condition ] then
>         result = [true_expr]
>     else
>         result = [false_expr]
>     end
> in
>     result
> end
> ( )
> however, that approach doesn't work because result needs to be typed if it
> lacks an initializer -- but
> due to separation of interest, I can't know the type until the first
> assignment.
> It seems without this feature, I can't generate static code from an
> S-expression based syntax tree.
> My question is therefore: what are my options in this situation? Can I
> defer the typing of a variable until I have an expression I can assign, if
> yes, how?
> Thank you for your help,
> Leonard
> _______________________________________________
> terralang mailing list
> terralang at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the terralang mailing list