stuh505
09-29-2005, 05:05 PM
Edit: It works if I add () to the end
struct foo
(
a, b, c,
fn baz n = sqrt (n + 1),
fn bar x y = print (x ^ 2 + y ^ 2)
)
If I do this:
f1 = foo
f1.a = 1
I get a runtime error. I guess, if values for the properties are not defined during initialization, they are no longer members of that initialization..
There's no problem doing it like this...
f1 = foo 1 2 3
f1.a = 2
..except that if I have 20 members, my initialization is going to be really long, and I wouldn't
be able to leave any of them null to be determined later on. Since they must be initialized at creation, I'd like to set default values for them in the struct definition, so that I don't have to specifically declare them all:
struct foo
(
a=0, b=0, c=0,
fn baz n = sqrt (n + 1),
fn bar x y = print (x ^ 2 + y ^ 2)
)
However, this doesn't seem to work at all...because when I do this:
f1 = foo
f1.a
...the result is not 0 as expected, but rather a runtime error.
struct foo
(
a, b, c,
fn baz n = sqrt (n + 1),
fn bar x y = print (x ^ 2 + y ^ 2)
)
If I do this:
f1 = foo
f1.a = 1
I get a runtime error. I guess, if values for the properties are not defined during initialization, they are no longer members of that initialization..
There's no problem doing it like this...
f1 = foo 1 2 3
f1.a = 2
..except that if I have 20 members, my initialization is going to be really long, and I wouldn't
be able to leave any of them null to be determined later on. Since they must be initialized at creation, I'd like to set default values for them in the struct definition, so that I don't have to specifically declare them all:
struct foo
(
a=0, b=0, c=0,
fn baz n = sqrt (n + 1),
fn bar x y = print (x ^ 2 + y ^ 2)
)
However, this doesn't seem to work at all...because when I do this:
f1 = foo
f1.a
...the result is not 0 as expected, but rather a runtime error.
