? Object-like system ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
What's going on?? See: Site Update March 2022

Object-like system

Submitted
Updated
Author
DFrost
Public Key
Available Soon!
Min. Compat.
All
Rating
1 vote
Description 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.
Categories
Keywords
4 Comment(s) Chatter Chatter The code you posted for "Let's see the SB implementation" isn't legal SmileBASIC code rando rando Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Third Year My account is over 3 years old Website Avatar Taboo I didn't change my avatar for 180 days Website I’m assuming DFrost is making some sort of library that makes it legal Chatter Chatter No library can fix a nested DEF/ DEF without END rando rando Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Third Year My account is over 3 years old Website Avatar Taboo I didn't change my avatar for 180 days Website Maybe they’re doing it interpreter style idk