Y combinator in arc 3 points by mpr 620 days ago | 7 comments Y combinator in mit-scheme`````` (define Y (lambda (f) (let ((g (lambda (h) (f (lambda (x) ((f (h h)) x)))))) (g g)))) `````` Y combinator in Arc`````` (def Y (fn (f) (let g (fn (h) (f [(f (h h)) _])) (g g)))) `````` The shortest working definition of Y I can think of. It makes use of Arc's bracketed anonymous functions of a single argument. These types of bracketed anonymous functions of one argument cannot be nested as they all bind their argument to the underscore.What if they could be nested? Maybe the outermost function would bind its argument to @0, and subsequently nested functions would bind their arguments to unique variables by incrementing the integer (@0, @1, @2, ...). Then we could write Y quite compactly like this.`` (def Y [let g [@0 [(@0 (@1 @1)) @2]] (g g)])``
 2 points by zck 611 days ago | link I agree; the nested case is a bit difficult for humans to parse.I wonder if there's a way to make (fn (x) ...) even more lightweight.What if, to do the same thing, we had a new anonymous function syntax?`````` {x ...} `````` It would work somewhat like this:`````` arc> (let my-fn {arg (string "I got " arg)} (my-fn "this thing")) "I got this thing" `````` This is somewhat analogous to "let"`````` (let x ...) `````` It could also allow for multiple arguments, like this:`````` {(x y} ...) `````` Allowing for multiple arguments prevents destructuring-bind style function calls, though, which is a downside. I guess you could use other kinds of brackets for that?`````` {{x y} ...};; this would be non-destructuring-bind {(x y) ...};; this is destructuring-bind {{(x y} ...);;; this is the same as #2; it would destructuring-bind the first argument, a list. `````` Heck, we could even build it into the existing anonymous function syntax:`````` [{x y} ...] `````` Would be the same as`````` (fn (x y) ...) `````` But I'm not sure that's a big enough win.-----
 3 points by mpr 610 days ago | link As per akkartik's comment, we already have multi-argument anonymous functions in anarki:`````` ([prn _1 _2] "hello " "there") `````` But yeah maybe having full lambda list capabilities in the anonymous function would be cool.`````` ([((a b) c) (prn c b a)] (list "is" "name ") "my ") `````` So if the first argument to the bracket function is a list, it acts as a lambda list.But this interferes with the arc special syntax of having lists act as functions on their indices. Because the following is already valid arc code:`````` (let x (list 1 2 3) (x 2)) ;; > 3 `````` In that case having different delimiters might be the way to go. So your brace notation would be used for anonymous functions with full lambda list capability.`````` (let x (list 1 2) ({((a b) c) (prn c b a)} x 3)) `````` Edit: trying some other formatting...`````` (with (f {((a b) c) (prn c b a)} x (list 1 2)) (f x 3))``````-----