numerous additions to stdlib, fix test.spl
This commit is contained in:
parent
d08daa5a62
commit
e7317683fa
2 changed files with 30 additions and 1 deletions
15
std.spl
15
std.spl
|
@ -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
|
||||
|
|
16
test.spl
16
test.spl
|
@ -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
|
||||
} } }
|
||||
|
|
Loading…
Add table
Reference in a new issue