Descriptioninfinite-depth dictionary implementation for SmileBASIC
Currently, the methods only allow one parameter, an instance of the owning object to be passed.InstructionsAt 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:
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:
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"))
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.