diff options
author | Marvin Borner | 2022-08-26 19:12:20 +0200 |
---|---|---|
committer | Marvin Borner | 2022-08-26 19:12:20 +0200 |
commit | 2cc4d5bb3c473bd1bb5dc87f58feacb6772a22fe (patch) | |
tree | 7808ea3cf8b0e902becb3cb9380324a036e96697 | |
parent | 0a2d18ec27a6ef1dea90e57632834a7eb84bb9cf (diff) |
General std improvements
-rw-r--r-- | std/Byte.bruijn | 2 | ||||
-rw-r--r-- | std/Combinator.bruijn | 21 | ||||
-rw-r--r-- | std/List.bruijn | 3 | ||||
-rw-r--r-- | std/Math.bruijn | 2 | ||||
-rw-r--r-- | std/Number.bruijn | 2 | ||||
-rw-r--r-- | std/Option.bruijn | 6 | ||||
-rw-r--r-- | std/String.bruijn | 14 |
7 files changed, 31 insertions, 19 deletions
diff --git a/std/Byte.bruijn b/std/Byte.bruijn index 8d75314..2d7e397 100644 --- a/std/Byte.bruijn +++ b/std/Byte.bruijn @@ -1,7 +1,7 @@ # MIT License, Copyright (c) 2022 Marvin Borner :import std/Logic . - +:import std/Combinator . :import std/List . # bit 0 diff --git a/std/Combinator.bruijn b/std/Combinator.bruijn index 6b0eaed..4e11708 100644 --- a/std/Combinator.bruijn +++ b/std/Combinator.bruijn @@ -7,17 +7,17 @@ a [[1 0]] ($) a -# bluebird combinator: 1 <- 1 composition +# bluebird combinator: function composition: (f . g) x = f (g x) b [[[2 (1 0)]]] (.) b -# blackbird combinator +# blackbird combinator: 2x function composition: (f .. g) x y = f (g x y) b' [[[[3 (2 1 0)]]]] (..) b' -# bunting combinator +# bunting combinator: 3x function composition: (f ... g) x y z = f (g x y z) b'' [[[[[4 (3 2 1 0)]]]]] (...) b'' @@ -25,7 +25,7 @@ b'' [[[[[4 (3 2 1 0)]]]]] # becard combinator b''' [[[[3 (2 (1 0))]]]] -# cardinal combinator: reverse arguments +# cardinal combinator: reverse arguments: \f x y = f y z c [[[2 0 1]]] \( c @@ -81,6 +81,8 @@ j [[[[3 2 (3 0 1)]]]] # kestrel combinator: const, true k [[1]] +const k + # kite combinator: const id, false ki [[0]] @@ -107,16 +109,17 @@ o [[0 (1 0)]] # omega combinator Ω ω ω -# phoenix combinator +# phoenix combinator: liftM2 +# alternative name: starling prime: s' φ [[[[3 (2 0) (1 0)]]]] # psi combinator: on ψ [[[[3 (2 1) (2 0)]]]] -# queer combinator +# queer combinator: reverse function composition: (f , g) x = g (f x) q [[[1 (2 0)]]] -(>>>) q +(,) q # quixotic bird combinator q' [[[2 (0 1)]]] @@ -139,9 +142,11 @@ r* [[[[3 1 0 2]]]] # robin twice removed combinator r** [[[[[4 3 1 0 2]]]]] -# starling combinator: <*> +# starling combinator: (f <*> g) x = f x (g x) s [[[2 0 (1 0)]]] +(<*>) s + # thrush combinator: flipped $ t [[0 1]] diff --git a/std/List.bruijn b/std/List.bruijn index 7673456..8e59ffd 100644 --- a/std/List.bruijn +++ b/std/List.bruijn @@ -2,11 +2,8 @@ # Lists in Church/Boehm-Berarducci encoding using pairs :import std/Combinator . - :import std/Pair P - :import std/Logic . - :import std/Number . # empty list element diff --git a/std/Math.bruijn b/std/Math.bruijn index 81a96d0..47b0267 100644 --- a/std/Math.bruijn +++ b/std/Math.bruijn @@ -5,7 +5,7 @@ :input std/Number . # greatest common divisor -gcd Z [[[(1 =? 0) case-eq ((1 >? 0) case-gre case-les)]]] +gcd z [[[(1 =? 0) case-eq ((1 >? 0) case-gre case-les)]]] case-eq 1 case-gre 2 (1 - 0) 0 case-les 2 1 (0 - 1) diff --git a/std/Number.bruijn b/std/Number.bruijn index 523bd21..b6bea75 100644 --- a/std/Number.bruijn +++ b/std/Number.bruijn @@ -4,9 +4,7 @@ # Heavily inspired by the works of T.Æ. Mogensen (see refs in README) :import std/Combinator . - :import std/Pair . - :import std/Logic . # negative trit indicating coeffecient of (-1) diff --git a/std/Option.bruijn b/std/Option.bruijn index 26de3de..b48fdc2 100644 --- a/std/Option.bruijn +++ b/std/Option.bruijn @@ -10,30 +10,36 @@ some [[[0 2]]] # checks whether option is none none? [0 true [false]] + :test (none? none) (true) :test (none? (some [[0]])) (false) # checks whether option is some some? [0 false [true]] + :test (some? none) (false) :test (some? (some [[0]])) (true) # applies a function to the value in option map [[0 none [some (2 0)]]] + :test (map [[1]] (some [[0]])) (some [[[0]]]) :test (map [[1]] none) (none) # applies a function to the value in option or returns first arg if none map-or [[[0 2 1]]] + :test (map-or [[[2]]] [[1]] (some [[0]])) ([[[0]]]) :test (map-or [[[2]]] [[1]] none) ([[[2]]]) # extracts value from option or returns first argument if none unwrap-or [[0 1 I]] + :test (unwrap-or false (some true)) (true) :test (unwrap-or false none) (false) # applies encapsulated value to given function apply [[1 none 0]] + :test (apply none [some ([[1]] 0)]) (none) :test (apply (some [[0]]) [some ([[1]] 0)]) (some [[[0]]]) diff --git a/std/String.bruijn b/std/String.bruijn index 20634c7..c74d950 100644 --- a/std/String.bruijn +++ b/std/String.bruijn @@ -15,13 +15,19 @@ eq? eq? B.eq? # returns true if character is part of a string in? in? B.eq? -∈ \in? +(∈) in? -:test (∈ 'b' "ab") (true) -:test (∈ 'c' "ab") (false) +ni? \in? + +(∋) ni? + +:test ('b' ∈ "ab") (true) +:test ('c' ∈ "ab") (false) +:test ("ab" ∋ 'b') (true) +:test ("ab" ∋ 'c') (false) # splits string by newline character -lines Z [[rec]] +lines z [[rec]] rec <>?(~broken) (^broken : empty) (^broken : (1 ~(~broken))) broken break (B.eq? '\n') 0 |