GH-194 let patterns #697

Merged
zxq9 merged 4 commits from GH-194-let-patterns into lima 2019-12-17 01:04:50 +09:00
zxq9 commented 2019-12-11 15:27:59 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

Fixes #194

Work-in-progress. Sits on top of #205.

Also adds pattern matching is list comprehension generators

function somes(xs : list(option('a))) = [ x | Some(x) <- xs ]

Also also

  • fix pattern matching on negative integers
  • compile FATE values to immediates (e.g. [1, 2, 3] is compiled to PUSH [1, 2, 3] instead of a series of CONS instructions)
*Created by: UlfNorell* Fixes #194 ~~Work-in-progress. Sits on top of #205.~~ Also adds pattern matching is list comprehension generators ```sophia function somes(xs : list(option('a))) = [ x | Some(x) <- xs ] ``` Also also - fix pattern matching on negative integers - compile FATE values to immediates (e.g. `[1, 2, 3]` is compiled to `PUSH [1, 2, 3]` instead of a series of `CONS` instructions)
zxq9 commented 2019-12-16 18:17:13 +09:00 (Migrated from gitlab.com)

Created by: tolbrino

There doesn't seem to be a test case for the match support in list comprehensions.

*Created by: tolbrino* There doesn't seem to be a test case for the match support in list comprehensions.
zxq9 commented 2019-12-16 22:06:19 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

Good catch. I added it to my temp test file instead of the actual test case.

*Created by: UlfNorell* Good catch. I added it to my temp test file instead of the actual test case.
zxq9 commented 2019-12-16 22:22:06 +09:00 (Migrated from gitlab.com)

Created by: hanssv

Review: Approved

*Created by: hanssv* **Review:** Approved
zxq9 commented 2019-12-17 01:01:57 +09:00 (Migrated from gitlab.com)

Created by: tolbrino

So this will crash if some = None?

*Created by: tolbrino* So this will crash if `some = None`?
zxq9 commented 2019-12-17 01:02:15 +09:00 (Migrated from gitlab.com)

Created by: tolbrino

Here the pattern match acts as a filter?

*Created by: tolbrino* Here the pattern match acts as a filter?
zxq9 commented 2019-12-17 01:02:36 +09:00 (Migrated from gitlab.com)

Created by: tolbrino

Review: Approved

*Created by: tolbrino* **Review:** Approved
zxq9 commented 2019-12-17 01:03:50 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

Yes, this is equivalent to

switch(some)
  Some(n) => ...
*Created by: UlfNorell* Yes, this is equivalent to ```sophia switch(some) Some(n) => ... ```
zxq9 commented 2019-12-17 01:04:32 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

Indeed

lc([None, Some(1), Some(2)]) == [1, 2]
*Created by: UlfNorell* Indeed ```sophia lc([None, Some(1), Some(2)]) == [1, 2] ```
zxq9 commented 2019-12-17 01:04:50 +09:00 (Migrated from gitlab.com)

Merged by: UlfNorell at 2019-12-16 16:04:50 UTC

*Merged by: UlfNorell at 2019-12-16 16:04:50 UTC*
Sign in to join this conversation.
No description provided.