; floor $0 1 \ floor|1 ; abs $0 $0 -1 * $0 0 ~ ? abs|1 ; tail recursive Fibonacci $1 $0 $1 + $2 1 ~ tfib_aux $1 $2 ? tfib_aux|3 0 1 $0 tfib_aux tfib|1 ; iterative Fibonacci $1 $0 $1 + $2 1 ~ $1 $2 fib_aux@3 0 1 $0 fib_aux fib|1 ; modulo $0 1 $1 _ mod|2 ; phi approximation using fibonacci numbers ; the argument specifies the number of iterations $1 $0 $1 + $2 1 ~ $1 $0 / $2 phi_aux@3 1 1 $0 phi_aux phi|1 ; factorial $0 $1 * $1 1 ~ $0 $1 fact_aux@2 1 $0 fact_aux fact|1 ; binomial coefficient $0 $1 $2 / * $1 1 - $2 1 ~ $0 $2 bin_aux@3 1 $0 $1 bin_aux bin|2 ; gsum ; sum of the first $0 integers using Gauss' formula $0 $0 1 + * 2 / gsum|1 ; sift ; sum of the integer from $0 to $1, both included ; (generalization of gauss' sum) $1 gsum $0 1 - gsum - sift|2 ; Ackermann function ; this is very slow and memory demanding ; for high enough values it will cause a stack overflow $0 1 ~ $0 $1 1 ~ ack 1 $1 ? $1 1 + $0 ack@2 ; "Hello, World!" 2645608968345021733469237830984 =hello ; '\n' 10 =lf ; '\r' 13 =cr ; characters 'a', 'A' and '0' 97 =chara 65 =charA 48 =char0 ; empty string 0 =null ; cons ; put the character $0 in front of the string $1 $1 256 * $0 + cons|2 ; cat ; concatenates string $0 with string $1 ; can be improved with a more efficient find_end $0 $1 256 * $1 $0 $1 ~ find_end@2 $1 $0 1 find_end * $0 + cat|2 ; WIP for faster find_end ;$0 $1 $1 * $2 2 * $2 $0 $1 ~ overshoot@3 ;find_between@3 ;$1 $0 $0 2 \ find_between find_end_aux|2 ;$0 256 1 overshoot $0 find_end|1 ; reverse ; reverses a string ; this reverses a string byte by byte, it's very slow $0 256 \ $0 256 mod $1 cons $1 $0 reverse_slow@2 ; this reverses $2 bytes $0 256 \ $0 256 mod $1 cons $2 1 - $1 $2 reverse_chunk@3 ; this reverses a string in chunks of 16 bytes, it's faster $0 340282366920938463463374607431768211456 \ $0 340282366920938463463374607431768211456 mod $1 0 16 reverse_chunk $2 340282366920938463463374607431768211456 * + $1 0 reverse_slow $2 cat $0 reverse_aux@3 $0 340282366920938463463374607431768211456 \ $0 340282366920938463463374607431768211456 mod 0 reverse_aux reverse|1 ; str_len ; based on reverse $0 256 \ 1 $1 + $1 $0 str_len_slow@2 $0 340282366920938463463374607431768211456 \ $0 340282366920938463463374607431768211456 mod $2 16 + $1 0 str_len_slow $2 + $0 str_len_aux@3 $0 340282366920938463463374607431768211456 \ $0 340282366920938463463374607431768211456 mod 0 str_len_aux str_len|1 ; to_string ; doesn't work with non positive integers (non naturals) $0 10 \ $0 10 mod char0 + $1 cons $1 $0 to_string_aux@2 $0 0 to_string_aux to_string|1 ; ////////// ; deprecated (replaced by '^') ; power/exponentiation $0 $0 * $1 2 \ $2 $0 * $2 $1 2 mod ? $2 $1 exp_aux@3 $0 $1 floor abs 1 exp_aux exp|2 ; deprecated (replaced by '_') ; exponentiation modulo (fast exponentiation algorithm, temporarily not working) $0 $0 * $1 2 \ $2 $0 * $3 mod $2 $1 2 mod ? $3 $2 $1 mod_exp_aux@4 $0 $1 floor abs 1 $2 mod_exp_aux mod_exp|3 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In a dui id sapien pretium facilisis et id turpis. Suspendisse diam lacus, bibendum a mattis sed, facilisis sed leo. Pellentesque lobortis dui non tellus scelerisque, sed venenatis dolor luctus. Ut at fringilla tortor, in fringilla lacus. In at justo eu nulla tempus facilisis eu sit amet lectus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id consequat lectus. Integer elit felis, rutrum et pellentesque ut, bibendum a ligula. Phasellus sit amet hendrerit quam.\n\nVivamus diam turpis, imperdiet eu varius et, semper sit amet orci. Vestibulum porttitor eleifend turpis, vel aliquam sapien maximus vitae. Cras in risus maximus, pretium ligula vitae, eleifend purus. Sed enim neque, lacinia viverra erat quis, congue tristique nibh. Integer pulvinar, sapien eget bibendum ornare, mauris erat sollicitudin quam, eu aliquet turpis nibh quis augue. Suspendisse non sodales nunc, non consectetur ex. Fusce luctus pellentesque massa at cursus. Fusce et tempor lectus, sit amet blandit ex. Fusce laoreet accumsan dui nec auctor. In id urna eleifend, pellentesque orci pulvinar, ultrices nisl.\n\nVivamus convallis lectus ligula, vel convallis odio faucibus vitae. Cras et ipsum a purus interdum tempus ut eu velit. Aliquam posuere pellentesque elit et varius. Nulla mollis varius augue, eu lacinia quam sagittis eu. Mauris molestie turpis quis felis molestie pharetra. Nunc fringilla accumsan eros vel ornare. Nunc vel nibh eget nisi iaculis dictum. Ut placerat eget libero et mattis. Vivamus rhoncus malesuada felis at vestibulum. Aenean dapibus accumsan tellus, ac facilisis lacus luctus vitae. Donec arcu turpis, lobortis vel suscipit a, tincidunt et sem.\n\nUt gravida elit tristique blandit finibus. Vestibulum interdum enim ut dapibus suscipit. Donec at libero erat. Quisque a venenatis lectus, non volutpat justo. Proin in sem feugiat, faucibus dui id, molestie lorem. Cras et suscipit sem. Donec metus nisi, lobortis quis leo sit eget." =lipsum