Skip to content

Operators

João Pedro Neto edited this page Nov 9, 2020 · 38 revisions

check notes below for table interpretation

Nulary Functions (Nilads)

Action Observations
while stack not empty:
  result += pop
push result
collapse stack content into a list

Unary Functions (Monads)

Assuming a as the top of the stack

Fraction Character List Observations
a+1 next char in codebase Map a successor
a-1 prev char in codebase Map a predecessor
! Factorial of a Factorial of ca Map ! a factorial function
a-th prime ca-th prime Map a get n-th prime
p is a prime? is ca prime? Map p a isPrime predicade
l 1 1 length of a length of data
L [a] a Map L a make list of top
[0,1,...,↓a] ['a',..., ↓a] if a lowercase
['A',...,↓a] if a uppercase
['0',...,↓a] if a is digit
Map a range from 0 to a exclusive
[1,...,a] ['a',...,a] if a lowercase
['A',...,a] if a uppercase
['1',...,a] if a is digit
Map a range from 1 to a inclusive
ė a a for x in a
  push a
split list into single elements
pass pass a[0] head of list
pass pass a[1:] tail of list
pass pass a[-1] last of list
pass pass a[:-1] init of list
1/a if a≠0 else 1 a a[::-1] invert list
``

Binary Functions (Dyads)

Assuming b as the top of the stack, a below b

Frac×Frac Frac×Chr Chr×Frac Chr×Chr Frac×List List×Frac Chr×List List×Chr List×List
+ a+b u(a+cb) u(ca+b) u(ca+cb) M +a b M +b a M +ca b M +cb a M + zip(a,b)
- a-b u(a-cb) u(ca-b) u(ca-cb) M -a b M -b a M -ca b M -cb a M - zip(a,b)

Notes:

  • c(char) is the value of char in the codebase; ca means c(a)
  • u(n) is the char with codebase n; ua means u(a)
  • Fraction x rounds to ⌊x⌋ when needed as int
  • Predicades push 1 for True, 0 for False
  • Map op/M op means map operation op over elements of String/List (recursively with lists of lists)
  • Unless stated otherwise,
    • operators initially pop values a,b
    • character operators consider a circular codebase; eg. i=(i+1)%256
    • zip functions cycle the smaller list
Clone this wiki locally