diff options
author | Eduardo Julian | 2017-05-29 22:05:57 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-05-29 22:05:57 -0400 |
commit | 953f49d5a46209f2d75e67b50edea378261108cd (patch) | |
tree | b2f1c4e08fbbbfa84c5b918ce68e4acbae08efa1 /new-luxc/source/luxc/base.lux | |
parent | 9ca82858b0e15800972ca7b2a776190a8d4b371c (diff) |
- Fixes for pattern-matching (case) analysis.
- Small refactorings.
- Improved common procedures analysis.
- Can now handle tagged structures (variants & records).
- Tests for pattern-matching, functions (definition & application), and common procedures.
Diffstat (limited to 'new-luxc/source/luxc/base.lux')
-rw-r--r-- | new-luxc/source/luxc/base.lux | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/new-luxc/source/luxc/base.lux b/new-luxc/source/luxc/base.lux index 612ce70d2..abd154190 100644 --- a/new-luxc/source/luxc/base.lux +++ b/new-luxc/source/luxc/base.lux @@ -55,15 +55,25 @@ (#R;Success [(set@ #;type-context context' compiler) output])))) -(def: #export (pl-contains? key mappings) - (All [a] (-> Text (List [Text a]) Bool)) - (case mappings +(def: #export (pl-get key table) + (All [a] (-> Text (List [Text a]) (Maybe a))) + (case table #;Nil - false + #;None - (#;Cons [k v] mappings') - (or (T/= key k) - (pl-contains? key mappings')))) + (#;Cons [k' v'] table') + (if (T/= key k') + (#;Some v') + (pl-get key table')))) + +(def: #export (pl-contains? key table) + (All [a] (-> Text (List [Text a]) Bool)) + (case (pl-get key table) + (#;Some _) + true + + #;None + false)) (def: #export (pl-put key val table) (All [a] (-> Text a (List [Text a]) (List [Text a]))) @@ -78,16 +88,16 @@ (#;Cons [k' v'] (pl-put key val table'))))) -(def: #export (pl-get key table) - (All [a] (-> Text (List [Text a]) (Maybe a))) +(def: #export (pl-update key f table) + (All [a] (-> Text (-> a a) (List [Text a]) (List [Text a]))) (case table #;Nil - #;None + #;Nil (#;Cons [k' v'] table') (if (T/= key k') - (#;Some v') - (pl-get key table')))) + (#;Cons [k' (f v')] table') + (#;Cons [k' v'] (pl-update key f table'))))) (def: #export (with-source-code source action) (All [a] (-> [Cursor Text] (Lux a) (Lux a))) |