using [java]java.lang
class Main
{
static Int foo()
{
return DateTime.boot.sec
}
static Str gogo(Int x := foo)
{
return x.toStr
}
static Void main(Str[] args)
{
echo(DateTime.boot.sec.toStr)
Thread.sleep(2000)
echo(gogo)
Thread.sleep(2000)
echo(gogo)
}
}
the output I get is something like:
12
12
12
So clearly the foo method is not dynamically evaluated for every evaluation of gogo. When is it evaluated? At classloading? Seems like that could be weird if my value depends something initialized after class loading.
Thanks, -Andrew
KevinKelleyMon 26 Mar 2012
I think you're misinterpreting DateTime.boot.sec...
andrewc Mon 26 Mar 2012
Hi Fantom team,
How should I reason about this code
the output I get is something like:
So clearly the foo method is not dynamically evaluated for every evaluation of gogo. When is it evaluated? At classloading? Seems like that could be weird if my value depends something initialized after class loading.
Thanks, -Andrew
KevinKelley Mon 26 Mar 2012
I think you're misinterpreting
DateTime.boot.sec
...It seems to be the time-of-boot, not time-since-boot. That is it doesn't vary.
About the default param: I hope it works like the intuition, I actually wrote code just today to use it like that...
My case is like the java overloading pattern,
translating to Fantom:
...
StephenViles Mon 26 Mar 2012
Andrew, you probably want
sys::Duration.uptime
:A
sys::Duration
is a period of time, where asys::DateTime
is a fixed instant.andrewc Mon 26 Mar 2012
Of course! Thanks guys.
qualidafial Mon 26 Mar 2012
I would not have looked in
Duration
for uptime. Might this be a better fit inEnv
?