Skip to content

Commit

Permalink
Add the \!> operator, the \!&> operator and the distinct function
Browse files Browse the repository at this point in the history
  • Loading branch information
i2y committed Dec 14, 2014
1 parent 8a8f368 commit ab6361b
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Revision history
----------------
v0.0.9, 2014-12-14
* Add the !> operator, the !&> operator and the distinct function
v0.0.8, 2014-12-09
* Add some actor functions (link, unlink, cancel, kill, wait)
* Add the quote expression and the quasi_quote expression
Expand Down
19 changes: 17 additions & 2 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def factorial(n, m):
else:
factorial(n - 1, n * m)


factorial(10000, 1)
# => 28462596809170545189064132121198688...

Expand Down Expand Up @@ -65,7 +66,21 @@ actor = spawn(show)
send('foo', actor)
actor ! 'bar' # send('bar', actor)

wait_all()
sleep(1)
# -> foo
# -> bar


'foo' !> spawn(show)

sleep(1)
# -> foo

['foo', 'bar'] !&> spawn(show)

sleep(1)
# -> foo
# -> bar
```

### Flask
Expand Down Expand Up @@ -483,4 +498,4 @@ X.foobar()
MIT License

## Author
[i2y] (https://github.com/i2y)
[i2y] (https://github.com/i2y)
18 changes: 16 additions & 2 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,23 @@ def show():
actor = spawn(show)

send('foo', actor)
actor ! 'bar' # send("bar", actor)
actor ! 'bar' # send('bar', actor)

wait_all()
sleep(1)
# -> foo
# -> bar


'foo' !> spawn(show)

sleep(1)
# -> foo

['foo', 'bar'] !&> spawn(show)

sleep(1)
# -> foo
# -> bar
```

### Flask
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,21 @@ actor = spawn(show)
send('foo', actor)
actor ! 'bar' # send('bar', actor)

wait_all()
sleep(1)
# -> foo
# -> bar


'foo' !> spawn(show)

sleep(1)
# -> foo

['foo', 'bar'] !&> spawn(show)

sleep(1)
# -> foo
# -> bar
```

### Flask
Expand Down
16 changes: 15 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,21 @@ Actor
send('foo', actor)
actor ! 'bar' # send('bar', actor)
wait_all()
sleep(1)
# -> foo
# -> bar
'foo' !> spawn(show)
sleep(1)
# -> foo
['foo', 'bar'] !&> spawn(show)
sleep(1)
# -> foo
# -> bar
Flask
~~~~~
Expand Down
13 changes: 12 additions & 1 deletion examples/actor_example.mochi
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ link(actor2, (&args) -> print("actor2", args))

actor2 ! "bar"

wait_all()
sleep(1)

'foo' !> spawn(show_loop)

sleep(1)
# -> foo

['foo', 'bar'] !&> spawn(show_loop)

sleep(1)
# -> foo
# -> bar
2 changes: 1 addition & 1 deletion mochi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = 'Yasushi Itoh'
__version__ = '0.0.8.4'
__version__ = '0.0.9'
__license__ = 'MIT License'


Expand Down
21 changes: 19 additions & 2 deletions mochi/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def __hash__(self):
lg.add('PIPELINE_FIRST', r'\|>1')
lg.add('PIPELINE_BIND', r'\|>\?')
lg.add('PIPELINE', r'\|>')
lg.add('PIPELINE_SEND', r'!>')
lg.add('PIPELINE_MULTI_SEND', r'!&>')
lg.add('BAR', r'\|')
lg.add('LBRACK', r'\[')
lg.add('RBRACK', r'\]')
Expand Down Expand Up @@ -157,15 +159,16 @@ def __hash__(self):
'LPAREN', 'RPAREN', 'TRUE', 'FALSE', 'DQUOTE_STR', 'SQUOTE_STR', 'AT', 'BANG',
'NAME', 'EQUALS', 'IF', 'ELSEIF', 'ELSE', 'COLON', 'SEMI', 'DATA', 'IMPORT', 'REQUIRE',
'LBRACK', 'RBRACK', 'COMMA', 'DEF', 'DOC', 'CALET', 'PIPELINE', 'PIPELINE_BIND', 'PIPELINE_FIRST',
'PIPELINE_FIRST_BIND', 'RETURN',
'PIPELINE_FIRST_BIND', 'PIPELINE_SEND', 'PIPELINE_MULTI_SEND', 'RETURN',
'LBRACE', 'RBRACE', 'MATCH', 'DEFM', 'RECORD', 'AMP', 'FN', 'THINARROW', 'RECEIVE',
'YIELD', 'FROM', 'FOR', 'IN', 'DOT', 'INDENT', 'DEDENT', 'TRY', 'FINALLY', 'EXCEPT',
'MODULE', 'AS', 'RAISE', 'WITH', 'MACRO', 'QUOTE', 'QUASI_QUOTE', 'UNQUOTE', 'UNQUOTE_SPLICING'],
precedence=[('left', ['EQUALS']),
('left', ['NOT']),
('left', ['OPIS']),
('left', ['OPEQ', 'OPLEQ', 'OPGEQ', 'OPNEQ', 'OPLT', 'OPGT', 'OPAND', 'OPOR',
'PIPELINE', 'PIPELINE_BIND', 'PIPELINE_FIRST', 'PIPELINE_FIRST_BIND']),
'PIPELINE', 'PIPELINE_BIND', 'PIPELINE_FIRST', 'PIPELINE_FIRST_BIND',
'PIPELINE_SEND', 'PIPELINE_MULTI_SEND']),
('left', ['OPPLUS', 'OPMINUS']),
('left', ['LBRACK', 'RBRACK']),
('left', ['OPTIMES', 'OPDIV', 'PERCENT'])],
Expand Down Expand Up @@ -1078,6 +1081,20 @@ def binop_expr(p):
[p[2][0], input_sym] + p[2][(1 if len(p[2]) > 1 else len(p[2])):]]]]


@pg.production('binop_expr : binop_expr PIPELINE_SEND binop_expr')
def binop_expr(p):
return [Symbol('send'), p[0], p[2]]


@pg.production('binop_expr : binop_expr PIPELINE_MULTI_SEND binop_expr')
def binop_expr(p):
return [Symbol('tuple'),
[Symbol('filter'),
[Symbol('fn'), [Symbol('$1')],
[Symbol('send'), Symbol('$1'), p[2]]],
p[0]]]


@pg.production('binop_expr : expr')
def binop_expr(p):
return p[0]
Expand Down

0 comments on commit ab6361b

Please sign in to comment.