! Copyright (c) 2012 Anonymous
! See http://factorcode.org/license.txt for BSD license.
-USING: fry kernel math ;
+USING: combinators kernel math ;
IN: rosetta-code.y-combinator
! http://rosettacode.org/wiki/Y_combinator
: Y ( quot -- quot )
'[ [ dup call call ] curry @ ] dup call ; inline
+! factorial sequence
: almost-fac ( quot -- quot )
- '[ dup zero? [ drop 1 ] [ dup 1 - _ call * ] if ] ;
+ '[ dup zero? [ drop 1 ] [ dup 1 - @ * ] if ] ;
+! fibonacci sequence
: almost-fib ( quot -- quot )
- '[ dup 2 >= [ 1 2 [ - _ call ] bi-curry@ bi + ] when ] ;
+ '[ dup 2 >= [ 1 2 [ - @ ] bi-curry@ bi + ] when ] ;
+
+! Ackermann–Péter function
+:: almost-ack ( quot -- quot )
+ [
+ {
+ { [ over zero? ] [ nip 1 + ] }
+ { [ dup zero? ] [ [ 1 - ] [ drop 1 ] bi* quot call ] }
+ [ [ drop 1 - ] [ 1 - quot call ] 2bi quot call ]
+ } cond
+ ] ;