LoginLogin
Might make SBS readonly: thread

Object-like system

Root / Submissions / [.]

DFrostCreated:
Download:Available Soon!
Version:Size:
infinite-depth dictionary implementation for SmileBASIC Currently, the methods only allow one parameter, an instance of the owning object to be passed.

Instructions:

At a basic level, the mini-dictionaries contain three core pieces of information: key, type, and value. Let's say we have some code in Python: class vector: def __init__(self, x,y,z): self.x = x self.y = y self.z = z def add(self, V): return vector(self.x + V.x, self.y + V.y, self.z + V.z) I know there are tuples in Python, but just ignore that for a bit. The point here is that this object has internal variables and has a method, __sum__(). Methods are essentially functions imbedded inside of an object. Methods in an instance of an object take in a reference of that instance for manipulation. Though methods aren't exactly available in SB, functions are. These functions can be remotely CALLed as well, by storing the function's name as a string. In order to make it less tedious for the end-user, there are two non-native additional types in these dictionaries: pointers(essentially strings, but get() returns the variable that this value is pointing to) and methods(automatically called by get() and uses the object as an input to the function referenced) Pointers reference other variables, which in themselves, can be dictionaries as well. Let's see the SB implementation with the current version:
DEF VECTOR(X,Y,Z):
 DIM OBJ[0]
 PUSH OBJ, NUM("'X", X)
 PUSH OBJ, NUM("'Y", Y)
 PUSH OBJ, NUM("'Z", Z)
 PUSH OBJ, F("'ADD", "ADDVEC") 'VECTOR'S "ADD" METHOD IS SET TO THE FUNCTION'S NAME, 'ADDVEC'
 PUSH OBJ, F("STR", "STRVEC")
DEF ADDVEC(SELF, V)
 RETURN VECTOR(SELF.GET("X") + V.GET("X"),  SELF.GET("Y") + V.GET("Y"), SELF.GET("Z") + V.GET("Z"))
END
DEF STRVEC(SELF)
 x = GET(SELF, "X")
 y = GET(SELF, "Y")
 z = GET(SELF, "Z")
 RETURN FORMAT$("%S, %S, %S", x,y,z)

V1 = VECTOR(-10,-10,-10)
V2 = VECTOR(10,10,10)
V3 = GET(V1, "ADD", V2)' NOT CURRENTLY POSSIBLE DUE TO A LACK OF OPTIONAL ARGS IN SB3.

The code you posted for "Let's see the SB implementation" isn't legal SmileBASIC code

Replying to:Chatter
The code you posted for "Let's see the SB implementation" isn't legal SmileBASIC code
Iโ€™m assuming DFrost is making some sort of library that makes it legal

Replying to:Chatter
The code you posted for "Let's see the SB implementation" isn't legal SmileBASIC code
No library can fix a nested DEF/ DEF without END

Replying to:Chatter
The code you posted for "Let's see the SB implementation" isn't legal SmileBASIC code
Maybe theyโ€™re doing it interpreter style idk