aussieplusplus
aussieplusplus copied to clipboard
Objects
Thingamejig is an object
Rustle up is the initiator
Buggered is the destructor
+1 for thingamajig 😂, we kind of have to decide how we want to implement objects. Do we want them like JavaScript objects / Python dictionaries? Or do we want them to be like C, Rust, Go structs? Or do we want them to be classes? Here are some examples:
JS objs / Python dicts
I RECKON nigel = THINGAMAJIG <
name: "Nigel",
age: 57
>
C/Rust/Go structs, this would probably require a type system
THINGMAJIG Person IS LIKE <
name IS A THINGY THAT YOU SAY
age IS A THINGY THAT YOU COUNT
>
I RECKON nigel = Person<
name: "Nigel";
age: 57;
>;
Love THING YA SAY
and THING YA COUNT
as type declarations. Might suggest FURPHY
for boolean types?
Would be great to see these types for pattern matching:
YA RECKON wotsit IS A <
THING YA SAY ~ "Say it, drongo",
THING YA COUNT ~ "Count it, drongo",
FURPHY ~ "Believe it, drongo",
BUGGER ALL ~ "Bugger it, drongo",
doodad ~ "What the bleedin' 'eck is a " + doodad;
>
like JavaScript objects [...]? Or do we want them to be classes?
It's worth noting that JavaScript itself has both. Although, classes in JS are a special type of function:
// This modern syntax:
class C {
constructor() {
this.propertyName = 1;
}
methodName() {
alert('Hello!');
}
}
// Is roughly equivalent to this:
function C() {
this.propertyName = 1;
}
C.prototype.methodName = function methodName() {
alert("Hello!");
};
// In either case, you create one like this:
var obj = new C();
I just had an idea to emulate arrays as functions:
G'DAY MATE!
// Takes in an "array" function, an index, and the new value for that index.
// Returns an "array" function that has the that value at the given index.
THE HARD YAKKA FOR replacingValueAtIndex IS (array, index, newValue) <
THE HARD YAKKA FOR retFunc IS (i) <
YA RECKON i == index ? <
BAIL newValue;
>
BAIL array(i);
>
BAIL retFunc;
>
// Declare an array [1, 2, 3, 4].
THE HARD YAKKA FOR myArr IS (i) <
YA RECKON i IS A <
0 ~ BAIL 1;
1 ~ BAIL 2;
2 ~ BAIL 3;
3 ~ BAIL 4;
_ ~ BAIL BUGGER ALL;
>
>
// Change the array to [1, 2, 5, 4].
// Since functions are immutable, we have to use `I RECKON` rather than re-assigning to `myArr`.
I RECKON newArr = replacingValueAtIndex(myArr, 2, 5);
// Change the array to [1, 2, 5, 4, 3].
newArr = replacingValueAtIndex(newArr, 4, 3);
// Iterate over the array. Use inf as the upper bound of iteration.
I RECKON i IS A WALKABOUT FROM [0 to 1 / 0) <
I RECKON next = newArr(i);
YA RECKON next == BUGGER ALL ? <
MATE FUCK THIS;
>
GIMME next;
>
GIMME "Program end.";
CHEERS C***!
Sure enough, this prints out
1
2
5
4
3
Program end.
You could probably do objects/dictionaries in much the same way. However, because of the way these are defined, I imagine they will take up a lot of memory after relatively few writes.