Languages & Coding > SmallBASIC

OOP and map literals

(1/1)

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 ...

--- End quote ---

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




steve64:
ok, thanks

Navigation

[0] Message Index

Go to full version