mathstodon.xyz is one of the many independent Mastodon servers you can use to participate in the fediverse.
A Mastodon instance for maths people. We have LaTeX rendering in the web interface!

Server stats:

2.8K
active users

Julia

I came up with a weird data structure. It’s a hash, but you can also add functions that receive the hash as input so you can do math with it (if you squint, it’s vaguely like a spreadsheet). Something like:

m = MagicDict()
m["a"] = 1
m["b"] = 2
m["sum"] = lambda self: self["a"] + self["b"]

print(m["sum"])

Ideally, I’d want to do this in . (I know it’s possible because I did something much weirder once (I gave Str a CALL-ME method).)

@julia pretty sure we already have those; in Perl they are called “packages”

@julia
#RakuLang

my %m;
%m<a> = 2;
%m<b> = 3;
%m<sum> := Proxy.new(
STORE => method ($) {},
FETCH => method () {%m<a> + %m<b>}
);
dd %m<sum>;
dd %m;
%m<a> = 1;
dd %m<sum>;
dd %m;

@wamba @julia

or maybe like this...?

use Hash::Agnostic;

class MagicDict does Hash::Agnostic {
has %!hash handles<AT-KEY keys>;

method sum { self<a> + self<b> }
}

my \m = MagicDict.new;

m<a> = 1;
m<b> = 2;
say m.sum; #3