SyntaxBomb - Indie Coders

Languages & Coding => SmallBASIC => Topic started by: steve64 on August 19, 2021, 09:01:18

Title: OOP and map literals
Post by: 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 ...




Title: Re: OOP and map literals
Post by: chrisws on August 20, 2021, 05:10:06
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
Quote
obj = {...}
isn't interpolated; it's just parsing the raw text. It would be better if it worked the way you suggested.




Title: Re: OOP and map literals
Post by: steve64 on August 20, 2021, 13:17:51
ok, thanks
SimplePortal 2.3.6 © 2008-2014, SimplePortal