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:
parent
5733b9f74b
commit
c54fa4344f
3 changed files with 24 additions and 4 deletions
|
|
@ -7,7 +7,7 @@ return [[
|
||||||
:resume target = ()
|
:resume target = ()
|
||||||
|
|
||||||
fn.:check = $(anchor::is anchor)
|
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=()))
|
fn.:checkpoint = $(anchor::is anchor, on resume=attached block(default=()))
|
||||||
:resuming = resuming(1) /* calling function is resuming */
|
:resuming = resuming(1) /* calling function is resuming */
|
||||||
if(on resume)
|
if(on resume)
|
||||||
|
|
@ -15,12 +15,12 @@ return [[
|
||||||
if(resume target == anchor | resuming)
|
if(resume target == anchor | resuming)
|
||||||
on resume!
|
on resume!
|
||||||
else!
|
else!
|
||||||
fn.reached(anchor) = (fn.reached(anchor) | 0) + 1
|
fn.reached(anchor) = fn.reached(anchor, 0) + 1
|
||||||
merge branch!
|
merge branch!
|
||||||
else!
|
else!
|
||||||
fn.current checkpoint = anchor
|
fn.current checkpoint = anchor
|
||||||
if(resume target != anchor)
|
if(resume target != anchor)
|
||||||
fn.reached(anchor) = (fn.reached(anchor) | 0) + 1
|
fn.reached(anchor) = fn.reached(anchor, 0) + 1
|
||||||
merge branch!
|
merge branch!
|
||||||
|
|
||||||
:f = $
|
:f = $
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,16 @@ return {
|
||||||
return s:get(k)
|
return s:get(k)
|
||||||
end
|
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)",
|
"has", "(s::is struct, key)",
|
||||||
function(state, s, k)
|
function(state, s, k)
|
||||||
|
|
@ -137,6 +147,16 @@ return {
|
||||||
return t:get(state, key)
|
return t:get(state, key)
|
||||||
end
|
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",
|
"_!", "(t::is table, key) = value",
|
||||||
function(state, t, key, value)
|
function(state, t, key, value)
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,6 @@
|
||||||
|
|
||||||
x={4}
|
x={4}
|
||||||
|
|
||||||
|no={a(x)}
|
|no={a(x,())}
|
||||||
|
|
||||||
f!
|
f!
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue