OOP and map literals

Started by steve64, August 19, 2021, 09:01:18

Previous topic - Next topic

steve64

I'm looking at the nice "prototype-based OOP" in SBASIC.
I just noticed that the following code works as expected:

sub hello
print "hello " + self.world
end

obj = { world: "world" }
obj.foo=@hello
obj.foo()

while the following one (apparently equivalent to the former) generates an error.

sub hello
print "hello " + self.world
end

obj = { world: "world", foo: @hello }
obj.foo()

What's the reason? Is it just a limitation of map literals?
The value @hello in the latter case seems to be stored as string instead of pointer ...





chrisws

Quote from: steve64 on August 19, 2021, 09:01:18
I'm looking at the nice "prototype-based OOP" in SBASIC.
I just noticed that the following code works as expected:

sub hello
print "hello " + self.world
end

obj = { world: "world" }
obj.foo=@hello
obj.foo()

while the following one (apparently equivalent to the former) generates an error.

sub hello
print "hello " + self.world
end

obj = { world: "world", foo: @hello }
obj.foo()

What's the reason? Is it just a limitation of map literals?
The value @hello in the latter case seems to be stored as string instead of pointer ...

It's a limitation with the current implementation. The map assignment
Quoteobj = {...}
isn't interpolated; it's just parsing the raw text. It would be better if it worked the way you suggested.





steve64