Hi Andrew,
Thanks for your interest. (1) The website is out of date, and the
readme/getting started guide is correct. I will try to get the website
consistent when I have time to read through it.
(2) If named vars are treated as escapes by default, then why require
[escapes] at all?
While variables are escaped by default, other expressions are not. Escapes
are necessary, for instance, to capture local terra variables and pass them
to lua functions for further meta-programming:
local function createadd(a,b)
return `a + b
end
terra myfunction(c : int, b : int)
return [ createadd(c,b) ]
end
(2) If named vars are treated as escapes by default, then why require
[named variables] at all?
This cuts down on syntactic noise in Terra code. Without variables as
escapes, every use of one terra function from another would require an
escape, for instance. Generally, I use escape syntax when I want to make it
clear that I am piecing together more complicated code, but not for simply
calling one function from another.
-- Zach
On Tue, Mar 15, 2016 at 6:25 AM, Andrew Zamulinskyj <
[email protected]> wrote:
> Hi!
>
> I'm happy to have discovered this beautiful language on HN, and have
> recently had a small amount of time to look at it. I haven't finished
> reading through the README and front page of terralang.org completely yet
> but I have a couple of fundamental questions which will help with my
> current understanding of the language:
>
> 1)
>
> terralang.org says: "An escape is evaluated when a Terra function is
> /compiled/"
> README.md says: "When the function is defined, the Lua expression inside
> the brackets (`[]`) is evaluated"
>
> The description provided by terralang.org implies that the following
> script will actually print sin of 0:
>
> 1 local a = 5
> 1 local a = 5
> 2 terra sin5()
> 3 return [math.sin(a)]
> 4 end
> 5
> 6 a = 0
> 7
> 8 print(sin5()) -- from my understanding, sin5 is compiled here,
> which is also
> 9 -- when the escape is evaluated, at which
> point a = 0
>
> The behavior exhibited at the tip of master matches what is described in
> the README, and therefore the script prints sin of 5. I assume this is the
> intended behavior. If my assumption is correct, I recommend updating the
> website to reflect this because it can and will cause people's fundamental
> assumptions about the language to be wrong.
>
>
> 2)
>
> This question is far more general: If named vars are treated as escapes by
> default, then why require them at all? Is there any scenario where they
> actually need to be explicitly specified? Is it recommended to use them in
> all cases? If there is no difference, why does the syntax exist in the
> first place? I'm concerned that I might get confused about the intentions
> of an author whose code I read and the potential to mistake terra for lua
> if they don't explicitly express that what I'm reading is actually a quote.
> More information would be helpful in understanding Terra.
>
>
> Thanks for your time!
>
>
>
> _______________________________________________
> terralang mailing list
> [email protected]
> https://mailman.stanford.edu/mailman/listinfo/terralang
>
_______________________________________________
terralang mailing list
[email protected]
https://mailman.stanford.edu/mailman/listinfo/terralang