Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objects #13

Open
sdm900 opened this issue Oct 29, 2021 · 4 comments
Open

Objects #13

sdm900 opened this issue Oct 29, 2021 · 4 comments
Labels
IDEA IDEA ON IMPROVING THE LANG

Comments

@sdm900
Copy link

sdm900 commented Oct 29, 2021

Thingamejig is an object

Rustle up is the initiator

Buggered is the destructor

@zackradisic zackradisic added the IDEA IDEA ON IMPROVING THE LANG label Oct 29, 2021
@zackradisic
Copy link
Owner

+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;
>;

@zackradisic zackradisic mentioned this issue Oct 30, 2021
8 tasks
@jwfxpr
Copy link
Contributor

jwfxpr commented Oct 30, 2021

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;
>

@bbrk24
Copy link

bbrk24 commented Nov 3, 2021

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();

@bbrk24
Copy link

bbrk24 commented Mar 19, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDEA IDEA ON IMPROVING THE LANG
Projects
None yet
Development

No branches or pull requests

4 participants