Skip to content

Commit

Permalink
all non-functional, non-complex commands implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Mego committed Nov 9, 2015
1 parent 95c3f76 commit 6d8efc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 9 additions & 1 deletion commands.py
Expand Up @@ -165,6 +165,13 @@ def dupe_each_fn(srs):
tmp.append(a)
tmp.append(a)
srs.stack=tmp[:]

def r_fn(srs):
a=srs.pop()
if type(a) is StringType:
map(srs.push,a.split('')[::-1])
elif type(a) in [IntType, LongType]:
srs.push(range(a))

fn_table={32:lambda x:x.push(len(x.stack)),
33:lambda x:x.push(math.factorial(x.pop())),
Expand All @@ -191,6 +198,7 @@ def dupe_each_fn(srs):
75:lambda x:x.push(ceil(x.pop())),
76:lambda x:x.push(floor(x.pop())),
80:lambda x:x.push(nth_prime(x.pop())),
82:lambda x:x.push(range(1,x.pop()+1)),
83:lambda x:x.push(math.sin(x.pop())),
84:lambda x:x.push(math.tan(x.pop())),
85:lambda x:x.push(list(set(x.pop()).union(x.pop()))),
Expand All @@ -214,7 +222,7 @@ def dupe_each_fn(srs):
111:psh_fn,
112:p_fn,
113:enq_fn,
114:lambda x:map(x.push,x.pop().split('')[::-1]),
114:r_fn,
115:lambda x:x.push(math.sgn(x.pop())),
116:flat_explode_fn,
122:lambda x:map(x.eval,(lambda y:['.' for _ in range(y)])(x.pop())),
Expand Down
12 changes: 7 additions & 5 deletions commands.txt
Expand Up @@ -98,7 +98,8 @@ If the -e flag is passed, consecutive runs of characters in [a-zA-Z0-9.,'"() ] a
80 (P): pop a: push the a-th prime (zero-indexed)
81 (Q): if stack is empty: print the program's source code to stdout
82 (R): pop �,[a]: call �, using [a] as a temporary stack, push [a] (similar to reduce(�,[a]))
pop "a", push reverse("a")
pop "a": push reverse("a")
pop a: push [1,2,...,a] (range(1,a+1))
83 (S): pop a: push sin(a)
84 (T): pop a: push tan(a)
85 (U): pop [a],[b]: push union of [a] and [b]
Expand Down Expand Up @@ -134,7 +135,8 @@ If the -e flag is passed, consecutive runs of characters in [a-zA-Z0-9.,'"() ] a
112 (p): pop a: push 1 if a is prime else 0
pop [a]: pop b from [a], push [a],b
113 (q): pop [a],b: enqueue b in [a], push [a]
114 (r): pop "a"; push each character in "a", starting from the end (explode string)
114 (r): pop "a": push each character in "a", starting from the end (explode string)
pop a: push [0,1,...,a-1] (range(0,a))
115 (s): pop a: push sgn(a)
116 (t): pop all elements from stack, flatten any lists and explode any strings, and push them in the same order they were popped (full stack flatten/explode)
117 (u):
Expand All @@ -146,7 +148,7 @@ If the -e flag is passed, consecutive runs of characters in [a-zA-Z0-9.,'"() ] a
123 ({): pop a: rotate stack right a times
124 (|): pop a,b: push (a | b)
125 (}): pop a: rotate stack left a times
126 (~): pop a: push ~a (unary negate)
126 (~): pop a: push ~a (unary bitwise negate)
127 (): terminate the program
128 (�): pop a,b: push a+ib
129 (�): pop entire stack and print to stdout
Expand Down Expand Up @@ -176,7 +178,7 @@ If the -e flag is passed, consecutive runs of characters in [a-zA-Z0-9.,'"() ] a
153 (�):
154 (�):
155 (�): pop a,b: push abs(a)*sgn(b)
156 (�): pop �,a: fix first argument of � to a, decrease �'s arity by one, push � (partial(�,a))
156 (�):
157 (�):
158 (�): pop z: push phase(z)
159 (�): pop �: call �
Expand Down Expand Up @@ -261,7 +263,7 @@ If the -e flag is passed, consecutive runs of characters in [a-zA-Z0-9.,'"() ] a
238 (�):
239 (�): pop [a],[b]: push intersection of [a] and [b]
240 (�):
241 (�): pop a: push 0-a
241 (�): pop a: push -a (unary negate)
242 (�): pop a,b: push a>=b
243 (�): pop a,b: push a<=b
244 (�):
Expand Down

0 comments on commit 6d8efc6

Please sign in to comment.