Skip to content

fixes for Issue 91 and patterns as values#144

Merged
lutzhamel merged 2 commits intodev-1.0.0from
issue-91
Mar 27, 2022
Merged

fixes for Issue 91 and patterns as values#144
lutzhamel merged 2 commits intodev-1.0.0from
issue-91

Conversation

@lutzhamel
Copy link
Copy Markdown
Collaborator

This PR makes the following changes:

  • remove ‘quote’ syntax
  • rename AST node from ‘quote’ to ‘pattern’
  • introduces patterns that are truly values
  • some clean up in the redundancy checker

This PR introduces patterns that are truly values which has all kinds of ramifications. One of them is the fact that we can pattern match on patterns and we can access sub-structures of patterns computationally,

let z = pattern ((p,q),(r,t)).
let (x,_) = z.  -- extract a sub-pattern from z with pattern matching
let y = z@0.    -- extract a sub-pattern from z via indexing into the pattern structure

assert((1,2) is %[*x]%).
assert((1,2) is %[*y]%).

Another implication is that patterns can always match themselves,

let z = pattern (p,q).
assert(z is %[*z]%).

Finally, we can now formally show that patterns constructed with the pattern keyword and patterns constructed as objects are two different things,

structure A with
  data a.
  data b.
end

let zp = pattern A(p,q). -- pattern constructed purely structural
let zo = A(pattern p, pattern q). -- pattern constructed as an object

-- both patterns can match objects
assert(A(1,2) is %[*zp]%).
assert(A(1,2) is %[*zo]%).

-- two patterns are equivalent if they can match each other, 
-- but these patterns are not equivalent: they cannot match each other
assert(zo is %[*zp]%).
assert(not(zp is %[*zo]%)).

The fact that these two patterns are not equivalent is very satisfying since they were constructed very differently: The pattern constructed with the pattern keyword is a purely structural pattern whereas the pattern constructed as an object was constructed using an object constructor -- in this case just the default constructor but we could have also used a customized constructor.

@lutzhamel lutzhamel requested review from TimColaneri and olwmc March 27, 2022 11:28
Copy link
Copy Markdown
Collaborator

@olwmc olwmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incredible!! Great work.

Copy link
Copy Markdown
Collaborator

@TimColaneri TimColaneri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@lutzhamel lutzhamel merged commit 1a3062e into dev-1.0.0 Mar 27, 2022
@olwmc olwmc deleted the issue-91 branch April 12, 2022 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants