binkle on Nostr: I bent Jai into being able to do """member functions""" :devilish: (I bake the index ...
I bent Jai into being able to do """member functions"""
(I bake the index to a global array of structs into a runtime function stored on that struct during creation, so when I call that function from the instantiated struct's member it's got a reference to where the data local to it is stored, and I can "using" that so that I can reference the members as though they were local to the function itself). Here's sort of what it looks like:
Gorf :: struct {
TestProc :: ($id: s64) {
using arr[id];
print("(%, %, %)\n", x, y, z);
x += 1.0;
}
f: ();
x, y, z: float;
}
arr: [..] Gorf;
get_id :: () -> s64 {
arr.count += 1; // fake the alloc
return arr.count-1;
}
make_gorf :: (g: Gorf, $id: s64) {
array_add(*arr, g);
arr[id].f = #procedure_of_call arr[id].TestProc(id);
}
Test :: () {
p :: #run get_id();
make_gorf(.{ x = 100.0 }, p);
// print a few times to show x changing
arr[p].f();
arr[p].f();
arr[p].f();
}
#import "Basic";
I'm probably never going to actually use this but it's neat that I could do it if I wanted to
Published at
2026-07-09 17:08:48 UTCEvent JSON
{
"id": "d6f17260da2e149b491cbbc500d1cbda8b3760ff99f3e5b221ca70a4ad5b0d14",
"pubkey": "b3482fd6b7d6ee4fd5b25a54f73d7eeb2047979b85c0ab2b029274a0c3dea86e",
"created_at": 1783616928,
"kind": 1,
"tags": [
[
"t",
"import"
],
[
"t",
"procedure_of_call"
],
[
"t",
"run"
],
[
"emoji",
"devilish",
"https://clubcyberia.co/emoji/misc/devilish.png"
],
[
"proxy",
"https://clubcyberia.co/objects/62cba0e4-e9fa-4032-b8d2-74359d73960e",
"activitypub"
],
[
"client",
"Mostr",
"31990:6be38f8c63df7dbf84db7ec4a6e6fbbd8d19dca3b980efad18585c46f04b26f9:mostr",
"wss://relay.ditto.pub"
]
],
"content": "I bent Jai into being able to do \"\"\"member functions\"\"\" :devilish: \n\n(I bake the index to a global array of structs into a runtime function stored on that struct during creation, so when I call that function from the instantiated struct's member it's got a reference to where the data local to it is stored, and I can \"using\" that so that I can reference the members as though they were local to the function itself). Here's sort of what it looks like:\n\nGorf :: struct {\n TestProc :: ($id: s64) {\n using arr[id];\n print(\"(%, %, %)\\n\", x, y, z);\n x += 1.0;\n }\n\n f: ();\n x, y, z: float;\n}\n\narr: [..] Gorf;\n\nget_id :: () -\u003e s64 {\n arr.count += 1; // fake the alloc\n return arr.count-1;\n}\n\nmake_gorf :: (g: Gorf, $id: s64) {\n array_add(*arr, g);\n arr[id].f = #procedure_of_call arr[id].TestProc(id);\n}\n\nTest :: () {\n p :: #run get_id();\n make_gorf(.{ x = 100.0 }, p);\n\n // print a few times to show x changing\n arr[p].f();\n arr[p].f();\n arr[p].f();\n}\n\n#import \"Basic\";\n\n\nI'm probably never going to actually use this but it's neat that I could do it if I wanted to",
"sig": "212e8c8d1e89ff27acc6017f516c50e7eda7bb1fa114d49bc437d2cbdb767fe0a7d658a70fbb4f757045b50f6d5b315b07c4c23cee6e6ba82fc1a4acfa26946e"
}