1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

[stdlib] add optional default value for table and struct call

This commit is contained in:
Étienne Fildadut 2024-01-16 14:34:18 +01:00
parent 5733b9f74b
commit c54fa4344f
3 changed files with 24 additions and 4 deletions

View file

@ -7,7 +7,7 @@ return [[
:resume target = ()
fn.:check = $(anchor::is anchor)
fn.reached(anchor) = (fn.reached(anchor) | 0) + 1
fn.reached(anchor) = fn.reached(anchor, 0) + 1
fn.:checkpoint = $(anchor::is anchor, on resume=attached block(default=()))
:resuming = resuming(1) /* calling function is resuming */
if(on resume)
@ -15,12 +15,12 @@ return [[
if(resume target == anchor | resuming)
on resume!
else!
fn.reached(anchor) = (fn.reached(anchor) | 0) + 1
fn.reached(anchor) = fn.reached(anchor, 0) + 1
merge branch!
else!
fn.current checkpoint = anchor
if(resume target != anchor)
fn.reached(anchor) = (fn.reached(anchor) | 0) + 1
fn.reached(anchor) = fn.reached(anchor, 0) + 1
merge branch!
:f = $

View file

@ -112,6 +112,16 @@ return {
return s:get(k)
end
},
{
"_!", "(s::is struct, key, default)",
function(state, s, k, default)
if s:has(k) then
return s:get(k)
else
return default
end
end
},
{
"has", "(s::is struct, key)",
function(state, s, k)
@ -137,6 +147,16 @@ return {
return t:get(state, key)
end
},
{
"_!", "(t::is table, key, default)",
function(state, t, key, default)
if t:has(state, key) then
return t:get(state, key)
else
return default
end
end
},
{
"_!", "(t::is table, key) = value",
function(state, t, key, value)

View file

@ -27,6 +27,6 @@
x={4}
|no={a(x)}
|no={a(x,())}
f!