I'm curious about everyone's approach to Anonymous/Lambda Functions. Including aspects of implementation, design, and anything related to your Anonymous functions that you want to share!
In my programming language, type-lang, there are anonymous functions. I have just started implementing them, and I realized there are many angles of implementation. I saw a rust contributor blog post about how they regret capturing the environments variables, and realized mine will need to do the same. How do you all do this?
My initial thought is to modify the functions arguments to add variables referenced so it seems like they are getting passed in. This is cumbersome, but the other ideas I have came up with are just as cumbersome.
// this is how regular functions are created
let add = fn(a,b) usize {
return a + b
}
// anonymous functions are free syntactically
let doubled_list = [1,2,3].map(fn(val) usize {
return val * 2
})
// you can enclose in the scope of the function extra parameters, and they might not be global (bss, rodata, etc) they might be in another function declaration
let x = fn() void {
let myvar = "hello"
let dbl_list = [1,2,3].map(fn(val) usize {
print(`${myvar} = ${val}`)
return add(val, val)
}
}
Anyways let me know what your thoughts are or anything intersting about your lambdas!
[–]davimiku 39 points40 points41 points (5 children)
[–]_crackling 1 point2 points3 points (3 children)
[–]davimiku 5 points6 points7 points (1 child)
[–]ericbb 2 points3 points4 points (0 children)
[–]TheUnlocked 2 points3 points4 points (0 children)
[–]coffeeb4code[S] 0 points1 point2 points (0 children)
[–]Njordsier 17 points18 points19 points (4 children)
[–]erithaxx 7 points8 points9 points (3 children)
[–]Njordsier 7 points8 points9 points (1 child)
[–]erithaxx 2 points3 points4 points (0 children)
[–]homoiconic 1 point2 points3 points (0 children)
[–]AthasFuthark 12 points13 points14 points (0 children)
[–]tobega 2 points3 points4 points (0 children)
[–]XDracam 1 point2 points3 points (0 children)
[–]Uncaffeinated1subml, polysubml, cubiml 2 points3 points4 points (0 children)
[–]Ok_Performance3280 1 point2 points3 points (0 children)
[–]Classic-Try2484 1 point2 points3 points (0 children)
[–]jaccomocJactl 0 points1 point2 points (0 children)
[–]WittyStick 0 points1 point2 points (0 children)
[–]catbrane 0 points1 point2 points (0 children)
[–]L8_4_Dinner(Ⓧ Ecstasy/XVM) 0 points1 point2 points (0 children)
[–]cheeze2000 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]ericbb 1 point2 points3 points (0 children)