October 28, 2021, 19:18:40

Author Topic: OOP and map literals  (Read 528 times)

Offline steve64

  • Jr. Member
  • **
  • Posts: 17
OOP and map literals
« 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 ...





Offline chrisws

  • Full Member
  • ***
  • Posts: 117
    • SmallBASIC
Re: OOP and map literals
« Reply #1 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.





Offline steve64

  • Jr. Member
  • **
  • Posts: 17
Re: OOP and map literals
« Reply #2 on: August 20, 2021, 13:17:51 »
ok, thanks

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal