diff options
| author | elioat <elioat@tilde.institute> | 2023-07-19 22:58:17 -0400 |
|---|---|---|
| committer | elioat <elioat@tilde.institute> | 2023-07-19 22:58:17 -0400 |
| commit | aaacfd6f4d6dd57098037de179f98d846b6ad5f3 (patch) | |
| tree | 0284aa0218c853f3da67d0ad41ce8e4c73b016a8 | |
| parent | 313c7d81a673031813bfca84fa64eb3cbe7be24b (diff) | |
| download | tour-aaacfd6f4d6dd57098037de179f98d846b6ad5f3.tar.gz | |
*
| -rw-r--r-- | bqn/while.bqn | 2 | ||||
| -rw-r--r-- | chibi/print.scm | 2 | ||||
| -rw-r--r-- | js/b.js | 50 |
3 files changed, 52 insertions, 2 deletions
diff --git a/bqn/while.bqn b/bqn/while.bqn index 70dba23..a64adf1 100644 --- a/bqn/while.bqn +++ b/bqn/while.bqn @@ -1,3 +1,3 @@ _while_ β {π½βπΎβπ½_π£_πΎβπ½βπΎπ©} -(ββΓ·β2 β’Show) _while_ (>β0) 4096
\ No newline at end of file +(ββΓ·β2 β’Show) _while_ (>β0) 409
\ No newline at end of file diff --git a/chibi/print.scm b/chibi/print.scm index 5f58a23..a23f00e 100644 --- a/chibi/print.scm +++ b/chibi/print.scm @@ -1,7 +1,7 @@ (import (print)) -;; very unofficial test of my tiny print library +;; Very unofficial test of my tiny print library (println "hi there") @@ -0,0 +1,50 @@ +// b is for useful stuff + +'use strict' + +const b = { + pipe: (...args) => args.reduce((acc, el) => el(acc)), + compose: (...fns) => (...args) => fns.reduceRight((res, fn) => [fn.call(null, ...res)], args)[0], + identity: x => x, + curry: (fn) => { + let curried = (...args) => { + if (args.length >= fn.length) + return fn(...args) + else + return (...rest) => curried(...args, ...rest) + } + return curried + }, + match: () => b.curry((what, s) => s.match(what)), + replace: () => b.curry((what, replacement, s) => s.replace(what, replacement)), + filter: () => b.curry((f, xs) => xs.filter(f)), + map: () => b.curry((f, xs) => xs.map(f)) +}; + + +// pipe +const title = '10 Weird Facts About Dogs'; +const toLowerCase = (str) => str.toLowerCase(); +const addHyphens = (str) => str.replace(/\s/g, '-'); +const reverseText = (str) => (str === '') ? '' : reverseText(str.substr(1)) + str.charAt(0); +const slug = b.pipe(title, toLowerCase, addHyphens, reverseText); +console.log('pipe ', slug); + + +// compose +const toUpperCase = x => x.toUpperCase(); +const exclaim = x => `${x}!`; +const shout = b.compose(exclaim, toUpperCase); +const ret = shout('send in the clowns'); // "SEND IN THE CLOWNS!" +console.log('compose ', ret); + + +// curry family +const hasLetterR = b.match(/r/g); +const r1 = hasLetterR('hello world'); +const r2 = hasLetterR('just j and s and t etc'); +const r3 = b.filter(hasLetterR, ['rock and roll', 'smooth jazz']); +const noVowels = b.replace(/[aeiou]/ig); +const censored = noVowels('*'); +const r4 = censored('Chocolate Rain'); +console.log('curry ', r1, r2, r3, r4);
\ No newline at end of file |