Skip to content

Operators

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

check notes below for table interpretation

Nulary Functions (Nilads)

Action Observations
🡔 pass stack pop
🡖 push size of stack size of stack
🡗 stack = [] clear stack
½ 1/2 push one half
while stack not empty:
  result += pop
push result
collapse stack content into a list
pass outputs a newline
"abc...z" push lowercase alphabet
Ȧ "ABC...Z" push uppercase alphabet
"0123456789" push digits
Ø [""] list with empty string
``

Unary Functions (Monads)

Assuming a as the top of the stack

Fraction String List Observations
, a a a output top
. a a a output top and newlines
a+1 Map a Map a successor
a-1 Map a Map a predecessor
🡕 push a twice ibid. ibid. duplicate top
E 10**a Map 10** ca Map 10** a scientific notation
¬ not a Map ¬ ca Map ¬ a boolean not
! 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 from 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
for i in range(a)
  result += pop
push result
-- -- pops a elems from stack
and list them
ȧ b.insert(0,a)
push b
ibid. ibid. add element at list's head
b.append(a)
push b
ibid. ibid. add element at list's end
o M c digits M c letters sum M o a convert to codebase values
Σ sum digits a sum M c a sum M Σ a sum elements
Π prod digits a prod M c a prod M Σ a prod elements
Π prod digits a prod M c a prod M Σ a prod elements
forall digits a≠0 forall letters≠'0' forall M ∧ a forall
exists digits a≠0 exists letters≠'0' exists M ∨ a exists
``

Binary Functions (Dyads)

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

a×b Frac×Frac Frac×Str Str×Frac Str×Str Frac×List List×Frac Str×List List×Str List×List
push a
push b
ibid. ibid. ibid. ibid. ibid. ibid. ibid. ibid.
+ a+b M a+ b M +b a ab M a+ b M +b a M a+ b M +b a M + zip(a,b)
- a-b M -a b M -b a M ca-cb
zip(a,b)
M a- b M -b a M a- b M -b a M - zip(a,b)
* a*b [b,...,b] [a,...,a] a×b M a* b M *b a M a* b M *b a M * zip(a,b)
÷ a//b M a//
  (M c b)
M //b
  (M c a)
M // zip(ca,cb) M a// b M //b a M a// b M //b a M // zip(a,b)
% a%b M a%
  (M c b)
M %b
  (M c a)
M % zip(ca,cb) M a% b M %b a M a% b M %b a M & zip(a,b)
/ a/b M a/ cb M /b ca M / zip(a,b) M a/ b M /b a M a/ b M /b a M / zip(a,b)
^ a**b M a** cb M **b ca M ** zip(a,b) M a** b M **b a M a** b M **b a M ** zip(a,b)
B
change base
int(a,b) [int(a,bi)] int(a,b) [int(a,bi)] [int(a,bi)] [int(ai,b)] M aB b [int(ai,b)] M B zip(a,b)
i a a a a a a
a[b]
a a
a[cb%la]
a
a[b[:]%la]
î same as i
but pops the list
| a or b M a|
  (M c b)
M |b
  (M c a)
M | zip(ca,cb) M a| b M |b a M a| b M |b a M | zip(a,b)
& a and b M a&
  (M c b)
M &b
  (M c a)
M & zip(ca,cb) M a& b M &b a M a& b M &b a M & zip(a,b)
a xor b M a⊻
  (M c b)
M ⊻b
  (M c a)
M zip(ca,cb) M a⊻ b M ⊻b a M a⊻ b M ⊻b a M zip(a,b)
c ab
concatenate
ab ab ab M ac b M cb a M ac b M cb a ab
ŀ digits of a
not in b
ibid ibid ibid M b M ŀb a M b M ŀb a list
difference
``

Ternary Functions (Triads)

Operator V performs vectorized assignment. Use: values indices newValue V goes thru all valid indices of values and assign newValue (if newValue is a list, the operator cycles thru its elements if needed). Values and indices must be lists.

Notes:

  • c maps char to its codebase; ca means c(a)
  • u maps number as codebase to char; ua means u(a)
  • l maps list to its size; la means l(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)
  • Operator × is the cartesian product
  • 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