Created
November 19, 2024 16:31
-
-
Save christianvdstap/ad2b4f1e7c122253c566fe410b4ff6d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def = function(self) function(fName) | |
let(_definition = [ | |
// Static | |
op("new", function() | |
def([]) | |
), | |
// Access | |
op("get", function(name) function(default = undef) | |
safeGet(self, name, default) | |
), | |
op("toString", function() | |
doPrint() (self) | |
), | |
// Mutation | |
op("set", function(name) | |
def(set(self, name)) | |
), | |
op("add", function(a) | |
let(b = safeGet(self, "sum", 0), | |
) def(set(self, field("sum", a+b))) | |
), | |
op("test", function(a, b) | |
let(s = safeGet(self, "sum", 0), | |
) def(set(self, field("sum", s+a+b))) | |
), | |
], | |
) get(_definition, fName) | |
; | |
function call(fName) = | |
let(unset=function() undef | |
) function(a=unset, b=unset, c=unset, d=unset, e=unset, f=unset) | |
let(params = filter([a, b, c, d, e, f], function(p) p != unset), | |
map = [ | |
function(f) f(fName) (), | |
function(f) f(fName) (params[0]), | |
function(f) f(fName) (params[0], params[1]), | |
function(f) f(fName) (params[0], params[1], params[2]), | |
function(f) f(fName) (params[0], params[1], params[2], params[3]), | |
function(f) f(fName) (params[0], params[1], params[2], params[3], params[4]), | |
function(f) f(fName) (params[0], params[1], params[2], params[3], params[4], params[5]), | |
], | |
) map[len(params)] | |
; | |
echo( | |
compose([ | |
call ("toString") (), | |
function(f) foldl([1,2,3], function(a, g) g ("test") (1, a), f), | |
call("test") (1, 1), | |
call("add") (1), | |
call("add") (1), | |
call("new") () | |
]) (def()) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replacement of the inline foldl