numerous additions to stdlib, fix test.spl

This commit is contained in:
Daniella / Tove 2023-04-08 17:29:59 +02:00
parent d08daa5a62
commit e7317683fa
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
2 changed files with 30 additions and 1 deletions

15
std.spl
View file

@ -318,6 +318,21 @@ func nconcat { str | with amt ;
_str
}
def cached-results MicroMap:new =cached-results
func cache { ... | with arg-amt id body ;
def args arg-amt anew =args
def i arg-amt -- =i
while { i 0 lt not } {
"from stack"; i args:set;
i -- =i
}
def result [ args id ] cached-results:get =result
result null eq if {
args:to-stack body call dup =result [ args id ] swap cached-results:set;
}
result
}
func handle-panic { | with msg trace ;
program-name dup if {
program-name print " panicked at:" println

View file

@ -2,6 +2,8 @@
"#stream.spl" import
"#http.spl" import
"SPL tester" =program-name
func main { int | with args ;
def thing
@ -124,11 +126,23 @@ func main { int | with args ;
}
"" println
"testing cache" println
2 cached-test _str println
3 cached-test _str println
2 cached-test _str println
3 cached-test _str println
"" println
catch {
"heya" throw
} with { with e ;
e:object println
e:message println
}
100
}
func cached-test { mega | 1 "cached-test" cache <{ { mega | with i ;
i 2 *
"calculated " i _str concat println
} } }