aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/base.lux
diff options
context:
space:
mode:
Diffstat (limited to 'new-luxc/source/luxc/base.lux')
-rw-r--r--new-luxc/source/luxc/base.lux34
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)))