Created
December 21, 2019 11:10
-
-
Save porky11/5dd3399a8bcdda17ca4f456bca4f7632 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using import ..pijul.utils.va | |
#inline va-pos (val args...) | |
va-lifold none | |
inline "#hidden" (i key arg result) | |
dump i key arg result | |
static-if (not (none? result)) result | |
elseif (arg == val) i | |
else result | |
args... | |
inline first (a b) | |
static-if (none? a) b | |
else a | |
inline last (a b) | |
static-if (none? b) a | |
else b | |
inline only-one (a b) | |
static-if (none? a) b | |
elseif (none? b) a | |
else | |
static-error "Only one is allowed" | |
inline va-pos-finder (test select) | |
inline va-pos-finder (val args...) | |
va-lifold none | |
inline (i key arg result) | |
define next | |
static-if (test val arg) i | |
select result next | |
args... | |
inline va-find-pos (val test select args...) | |
(va-pos-finder test select) | |
val args... | |
inline va-finder (test select) | |
inline va-pos-finder (val args...) | |
va-lfold none | |
inline (key arg result) | |
define next | |
static-if (test val arg) arg | |
select result next | |
args... | |
inline va-find (val test select args...) | |
(va-finder test select) | |
val args... | |
let args... = 1 2:u32 3.0 | |
inline dispatcher-maker (args...) | |
let types... = | |
va-map typeof args... | |
let finder = | |
va-pos-finder (do >=) only-one | |
_ | |
inline (type) | |
let pos = | |
finder type types... | |
static-if (none? pos) | |
static-error "No argument of specified type found" | |
va@ pos args... | |
inline (type) | |
va-map | |
inline (arg) | |
static-if ((typeof arg) <= type) arg | |
args... | |
inline (type) | |
let pos = | |
finder type types... | |
not (none? pos) | |
let this these has? = | |
dispatcher-maker args... | |
has? u32 | |
has? real | |
has? i8 | |
this u32 | |
sugar type-dispatcher (body...) | |
fn (...) | |
let this these has? = | |
dispatcher-maker ... | |
unquote-splice body... | |
run-stage; | |
define integer-printer | |
type-dispatcher | |
static-if (has? i32) | |
.. | |
tostring (this i32) | |
":i32" | |
else | |
this integer | |
integer-printer 1 | |
integer-printer 2:u32 | |
print 1 | |
print 2:u32 | |
define sum-numbers-and-concatenate-strings | |
type-dispatcher | |
_ | |
+ 0 | |
these integer | |
.. "" | |
these string | |
let num str = | |
sum-numbers-and-concatenate-strings | |
\ 1 2 "Hello" 3 " " 4 5 "world" "!" | |
print num | |
print str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment