Skip to content

Commit

Permalink
implement #79
Browse files Browse the repository at this point in the history
  • Loading branch information
Mego committed Feb 16, 2017
1 parent 3b0e4c4 commit af3e72d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
6 changes: 3 additions & 3 deletions docs/commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
5D (]): end list literal
5E (^): pop a,b: push a XOR b
5F (_): pop a: push ln(a)
60 (`): function literal delimiter, pushes function whose body contains all of the commands until the next `. An implied ` is present at EOF if needed.
60 (`): prefix for function literal of length 1 (`p is the same as ⌠p⌡)
61 (a): invert the stack ([a,b,c,d] -> [d,c,b,a])
62 (b): pop a: push 0 if a==0 else 1; pop "a" or [a]: push 0 if len(a)==0 else 1; pop f: push 0 if len(f)==0 else 1
63 (c): pop a: push character at ordinal a%256; pop [a],b: push [a].count(b); pop "a","b": push "a".count("b")
Expand Down Expand Up @@ -242,8 +242,8 @@ F0 (≡): pop a: push eval(a) (Python-style evaluation)
F1 (±): pop a: push -a (unary negate)
F2 (≥): pop a,b: push a>=b
F3 (≤): pop a,b: push a<=b
F4 (⌠):
F5 (⌡):
F4 (⌠): begin function literal
F5 (⌡): end function literal
F6 (÷): pop a: push a list of all positive divisors of a that are less than or equal to a
F7 (≈): pop a: push int(a)
F8 (°): pop a: push radians(a)
Expand Down
2 changes: 1 addition & 1 deletion seriously/SeriouslyCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __str__(self):
return '{}'.format(self.code)

def __repr__(self):
return '`{}`'.format(self.code)
return '⌠{}⌡'.format(self.code)

def __len__(self):
return len(self.code)
Expand Down
23 changes: 17 additions & 6 deletions seriously/seriously.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,26 @@ def eval(self, code):
if self.debug_mode:
print("list: [{}]".format(l))
print(self.stack)
elif c == '`':
f = ''
elif c == '':
fn = ''
i += 1
while i < len(code) and code[i] != '`':
f += code[i]
nest = 1
while i < len(code):
if code[i] == '⌠':
nest += 1
elif code[i] == '⌡':
nest -= 1
if nest == 0:
break
fn += code[i]
i += 1
self.push(SeriouslyCommands.SeriousFunction(fn))
if self.debug_mode:
print('fn: {}'.format(f))
self.push(SeriouslyCommands.SeriousFunction(f))
print("fn: {}".format(fn))
print(self.stack)
elif c == '`':
i += 1
self.push(SeriouslyCommands.SeriousFunction(code[i]))
elif ord(c) in range(48, 58):
self.push(int(c))
elif ord_cp437(c) == 0x0B:
Expand Down
38 changes: 20 additions & 18 deletions seriously/test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ def test_numerics(self):
self.assert_serious(':+', [0])

def test_functions(self):
self.assert_serious("`foo`", [SeriousFunction("foo")])
self.assert_serious("`foo`$", ["foo"])
self.assert_serious("`f", [SeriousFunction("f")])
self.assert_serious("⌠foo⌡", [SeriousFunction("foo")])
self.assert_serious("⌠⌠foo⌡⌡", [SeriousFunction("⌠foo⌡")]),
self.assert_serious("⌠foo⌡$", ["foo"])

def test_eval(self):
self.assert_serious('"len(set([1,2,2,3]))"{}'.format(chr_cp437(0xF0)),
Expand Down Expand Up @@ -252,7 +254,7 @@ def test_arithmetic(self):
self.assert_serious(':1+2j'+chr_cp437(0xD7), [2, 1])
self.assert_serious('6:21▲', [42])
# weird prime bug test
self.assert_serious('9uyX9uR`p`░', [[2, 3, 5, 7]])
self.assert_serious('9uyX9uR`p░', [[2, 3, 5, 7]])

def test_lists(self):
self.assert_serious('[1][1,2]-', [[2]])
Expand Down Expand Up @@ -390,7 +392,7 @@ def test_string_methods(self):
self.assert_serious('"abcd"'+chr_cp437(0x8A), ["'abcd'"])
self.assert_serious(':123.45'+chr_cp437(0x8A), ['123.45'])
self.assert_serious(':1+2i'+chr_cp437(0x8A), ['(1+2j)'])
self.assert_serious('`foo`'+chr_cp437(0x8A), ['`foo`'])
self.assert_serious('foo'+chr_cp437(0x8A), ['foo'])
self.assert_serious('"1.23"i', [1.23])
self.assert_serious('"123"R', ["321"])
self.assert_serious('"abc"3*', ['abcabcabc'])
Expand Down Expand Up @@ -467,8 +469,8 @@ def test_list_methods(self):
self.assert_serious('3R#', [[1,2,3]])
self.assert_serious('[1,2,3][0,1]'+chr_cp437(0xB0), [[2]])
self.assert_serious('3R2r'+chr_cp437(0xB0), [[2]])
self.assert_serious('[1,2,3]`2>`'+chr_cp437(0xB0), [[1]])
self.assert_serious('3R`2>`'+chr_cp437(0xB0), [[1]])
self.assert_serious('[1,2,3]⌠2>⌡'+chr_cp437(0xB0), [[1]])
self.assert_serious('3R⌠2>⌡'+chr_cp437(0xB0), [[1]])
self.assert_serious('[1,2,3]N', [3])
self.assert_serious('3RN', [3])
self.assert_serious('[1,2,3]F', [1])
Expand Down Expand Up @@ -499,22 +501,22 @@ def test_bases(self):

class FunctionTests(SeriousTest):
def test_function_methods(self):
self.assert_serious('`foo`'+chr_cp437(0x9C), ['foo'])
self.assert_serious('foo'+chr_cp437(0x9C), ['foo'])
self.assert_serious('"foo"'+chr_cp437(0x9C), [SeriousFunction('foo')])
self.assert_serious('5'+chr_cp437(0x9C), [5])
self.assert_serious('`foo`l', [3])
self.assert_serious('`bar``foo`+', [SeriousFunction('foobar')])
self.assert_serious('`foo`3*', [SeriousFunction('foofoofoo')])
self.assert_serious('["oo"]`f%s`%', [SeriousFunction('foo')])
self.assert_serious('`foo`"foo"=', [1])
self.assert_serious('`foo``bar`=', [0])
self.assert_serious('`foo`3=', [3, SeriousFunction('foo')])
self.assert_serious('[1,2,3]`++`R', [[6]])
self.assert_serious('3`1`n', [1,1,1])
self.assert_serious('5`2@%Y`'+chr_cp437(0xD6), [[0,2,4,6,8]])
self.assert_serious('fool', [3])
self.assert_serious('bar⌡⌠foo+', [SeriousFunction('foobar')])
self.assert_serious('foo3*', [SeriousFunction('foofoofoo')])
self.assert_serious('["oo"]f%s%', [SeriousFunction('foo')])
self.assert_serious('foo"foo"=', [1])
self.assert_serious('foo⌡⌠bar=', [0])
self.assert_serious('foo3=', [3, SeriousFunction('foo')])
self.assert_serious('[1,2,3]⌠++⌡R', [[6]])
self.assert_serious('3`1n', [1,1,1])
self.assert_serious('52@%Y'+chr_cp437(0xD6), [[0,2,4,6,8]])

def test_combinators(self):
self.assert_serious('3`1kMD`Y', [0])
self.assert_serious('31kMDY', [0])

class RandomTests(SeriousTest):
def test_random(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
setup(
name='seriously',

version='2.0.70',
version='2.1.0',

description='A Python-based golfing language',
long_description='Seriously is a Python-based golfing language. See the GitHub page for more details.',
Expand Down

0 comments on commit af3e72d

Please sign in to comment.