diff options
Diffstat (limited to 'std/List.bruijn')
-rw-r--r-- | std/List.bruijn | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/std/List.bruijn b/std/List.bruijn index b84f5d0..891dc7c 100644 --- a/std/List.bruijn +++ b/std/List.bruijn @@ -42,7 +42,7 @@ tail P.snd :test (~((+1) : ((+2) : empty))) ((+2) : empty) # returns the length of a list in balanced ternary -length Z [[[rec]]] (+0) +length z [[[rec]]] (+0) rec <>?0 case-end case-inc case-inc 2 ++1 ~0 case-end 1 @@ -53,7 +53,7 @@ length Z [[[rec]]] (+0) :test (#empty) ((+0)) # returns the element at index in list -index Z [[[rec]]] +index z [[[rec]]] rec <>?0 case-end case-index case-index =?1 ^0 (2 --1 ~0) case-end empty @@ -66,7 +66,7 @@ index Z [[[rec]]] :test (((+1) : ((+2) : ((+3) : empty))) !! (+3)) (empty) # applies a left fold on a list -foldl Z [[[[rec]]]] +foldl z [[[[rec]]]] rec <>?0 case-end case-fold case-fold 3 2 (2 1 ^0) ~0 case-end 1 @@ -78,7 +78,7 @@ foldl Z [[[[rec]]]] foldl1 [[foldl 1 ^0 ~0]] # applies a right fold on a list -foldr [[[Z [[rec]] 0]]] +foldr [[[z [[rec]] 0]]] rec <>?0 case-end case-fold case-fold 4 ^0 (1 ~0) case-end 3 @@ -143,7 +143,7 @@ reverse foldl \cons empty list [0 [[[2 (0 : 1)]]] reverse empty] # appends two lists -append Z [[[rec]]] +append z [[[rec]]] rec <>?1 case-end case-merge case-merge ^1 : (2 ~1 0) case-end 0 @@ -161,7 +161,7 @@ snoc [[1 ++ (0 : empty)]] :test (((+1) : empty) ; (+2)) ((+1) : ((+2) : empty)) # maps each element to a function -map Z [[[rec]]] +map z [[[rec]]] rec <>?0 case-end case-map case-map (1 ^0) : (2 1 ~0) case-end empty @@ -171,9 +171,9 @@ map Z [[[rec]]] :test (inc <$> ((+1) : ((+2) : ((+3) : empty)))) ((+2) : ((+3) : ((+4) : empty))) # filters a list based on a predicate -filter Z [[[rec]]] +filter z [[[rec]]] rec <>?0 case-end case-filter - case-filter 1 ^0 (cons ^0) I (2 1 ~0) + case-filter 1 ^0 (cons ^0) i (2 1 ~0) case-end empty (<#>) \filter @@ -181,7 +181,7 @@ filter Z [[[rec]]] :test (((+1) : ((+0) : ((+3) : empty))) <#> zero?) ((+0) : empty) # returns the last element of a list -last Z [[rec]] +last z [[rec]] rec <>?0 case-end case-last case-last <>?(~0) ^0 (1 ~0) case-end empty @@ -191,7 +191,7 @@ _( last :test (last ((+1) : ((+2) : ((+3) : empty)))) ((+3)) # returns everything but the last element of a list -init Z [[rec]] +init z [[rec]] rec <>?0 case-end case-init case-init <>?(~0) empty (^0 : (1 ~0)) case-end empty @@ -211,7 +211,7 @@ concat-map [foldr (append . 0) empty] :test (concat-map [-0 : (0 : empty)] ((+1) : ((+2) : empty))) ((-1) : ((+1) : ((-2) : ((+2) : empty)))) # zips two lists discarding excess elements -zip Z [[[rec]]] +zip z [[[rec]]] rec <>?1 case-end case-zip case-zip <>?0 empty ((^1 : ^0) : (2 ~1 ~0)) case-end empty @@ -219,7 +219,7 @@ zip Z [[[rec]]] :test (zip ((+1) : ((+2) : empty)) ((+2) : ((+1) : empty))) (((+1) : (+2)) : (((+2) : (+1)) : empty)) # applies pairs of the zipped list as arguments to a function -zip-with Z [[[[rec]]]] +zip-with z [[[[rec]]]] rec <>?1 case-end case-zip case-zip <>?0 empty ((2 ^1 ^0) : (3 2 ~1 ~0)) case-end empty @@ -227,7 +227,7 @@ zip-with Z [[[[rec]]]] :test (zip-with (+) ((+1) : ((+2) : empty)) ((+2) : ((+1) : empty))) ((+3) : ((+3) : empty)) # returns first n elements of a list -take Z [[[rec]]] +take z [[[rec]]] rec <>?0 case-end case-take case-take =?1 empty (^0 : (2 --1 ~0)) case-end empty @@ -235,7 +235,7 @@ take Z [[[rec]]] :test (take (+2) ((+1) : ((+2) : ((+3) : empty)))) ((+1) : ((+2) : empty)) # takes elements while a predicate is satisfied -take-while Z [[[rec]]] +take-while z [[[rec]]] rec <>?0 case-end case-take case-take 1 ^0 (^0 : (2 1 ~0)) empty case-end empty @@ -243,7 +243,7 @@ take-while Z [[[rec]]] :test (take-while zero? ((+0) : ((+0) : ((+1) : empty)))) ((+0) : ((+0) : empty)) # removes first n elements of a list -drop Z [[[rec]]] +drop z [[[rec]]] rec <>?0 case-end case-drop case-drop =?1 0 (2 --1 ~0) case-end empty @@ -251,7 +251,7 @@ drop Z [[[rec]]] :test (drop (+2) ((+1) : ((+2) : ((+3) : empty)))) ((+3) : empty) # removes elements from list while a predicate is satisfied -drop-while Z [[[rec]]] +drop-while z [[[rec]]] rec <>?0 case-end case-drop case-drop 1 ^0 (2 1 ~0) 0 case-end empty @@ -259,7 +259,7 @@ drop-while Z [[[rec]]] :test (drop-while zero? ((+0) : ((+0) : ((+1) : empty)))) ((+1) : empty) # returns pair of take-while and drop-while -span Z [[[rec]]] +span z [[[rec]]] rec <>?0 case-end case-drop case-drop 1 ^0 ((^0 : ^recced) : ~recced) (empty : 0) recced 2 1 ~0 @@ -298,7 +298,7 @@ eq? &&( ... zip-with :test (eq? (=?) empty empty) (true) # removes first element that match an eq predicate -remove Z [[[[rec]]]] +remove z [[[[rec]]]] rec <>?0 case-end case-remove case-remove (2 ^0 1) ~0 (^0 : (3 2 1 ~0)) case-end empty @@ -306,7 +306,7 @@ remove Z [[[[rec]]]] :test (remove (=?) (+2) ((+1) : ((+2) : ((+3) : ((+2) : empty))))) ((+1) : ((+3) : ((+2) : empty))) # removes duplicates from list based on eq predicate (keeps first occurrence) -nub Z [[[rec]]] +nub z [[[rec]]] rec <>?0 case-end case-nub case-nub ^0 : (2 1 (~0 <#> [!(2 0 ^1)])) case-end empty @@ -315,7 +315,7 @@ nub Z [[[rec]]] :test (nub (=?) ((+1) : ((+2) : ((+1) : empty)))) (((+1) : ((+2) : empty))) # returns a list with infinite-times a element -repeat Z [[rec]] +repeat z [[rec]] rec 0 : (1 0) :test (take (+3) (repeat (+4))) ((+4) : ((+4) : ((+4) : empty))) @@ -326,16 +326,16 @@ replicate [[take 1 (repeat 0)]] :test (replicate (+3) (+4)) ((+4) : ((+4) : ((+4) : empty))) # returns an infinite list repeating a finite list -cycle Z [[rec]] +cycle z [[rec]] rec 0 ++ (1 0) :test (take (+6) (cycle "ab")) ("ababab") # returns a list with infinite-times previous (or start) value applied to a function -iterate Z [[[rec]]] +iterate z [[[rec]]] rec 0 : (2 1 (1 0)) :test (take (+5) (iterate inc (+0))) (((+0) : ((+1) : ((+2) : ((+3) : ((+4) : empty)))))) :test (take (+2) (iterate dec (+5))) (((+5) : ((+4) : empty))) -:test (take (+5) (iterate I (+4))) (repeat (+5) (+4)) +:test (take (+5) (iterate i (+4))) (repeat (+5) (+4)) :test (take (+0) (iterate inc (+0))) (empty) |