orc-lang / orc

Orc programming language implementation
https://orc.csres.utexas.edu/
BSD 3-Clause "New" or "Revised" License
41 stars 3 forks source link

As-Pattern and Call-Pattern can't be used together #100

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The 'as' pattern has unexpected behavior in conjunction with call patterns.

As currently implemented, the 'as' pattern captures and binds the input value 
fragment sent to a pattern, not the expected output fragment, which is never 
constructed. This is done for efficiency and simplicity: generating the full 
output fragment would incur substantial overhead and increase code complexity.

If call patterns are not used, this behavior is correct, since patterns then 
act only as filters and not as maps, and thus the input and output fragments 
are equal. However, in the presence of call patterns, the output fragment may 
be different.

There are four possible solutions:

1) Remove 'as' patterns entirely. This frees up a keyword and simplifies the 
pattern language slightly. The programmer can always replace uses of 'as' by 
multiple stages of pattern matching.

2) Add a note to the documentation stating that 'as' patterns and call patterns 
should not be used simultaneously, to avoid counterintuitive behavior.

3) In addition to (2), add documentation on the 'as' pattern which describes 
this problem explicitly and in detail, noting the input/output distinction

4) Rewrite the implementation of 'as' patterns to explicitly reconstruct the 
output fragment.

( I have written these in order of preference; (1) seems most preferable, (4) 
seems least preferable. - dkitchin )

Original issue reported on code.google.com by dkitc...@gmail.com on 19 Mar 2012 at 11:18

GoogleCodeExporter commented 9 years ago
Note on #1: The translation to remove 'as' looks like:

....p as x....
scope

to:

....p....
val x = p
scope

Original comment by dkitc...@gmail.com on 2 Apr 2012 at 7:20

GoogleCodeExporter commented 9 years ago

Original comment by arthur.peters on 29 Nov 2012 at 8:53

GoogleCodeExporter commented 9 years ago
Add a warning when using as-patterns with call-patterns.

Original comment by arthur.peters on 29 Nov 2012 at 9:28

GoogleCodeExporter commented 9 years ago
As of r3125, the compiler emits a warning when a call pattern is used within an 
as pattern.

Original comment by dkitc...@gmail.com on 6 Dec 2012 at 6:00

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r3146.

Original comment by dkitc...@gmail.com on 4 Jan 2013 at 9:04