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

[stdlib] remove is callable, add can dispatch

Since whether something can be called or not depends on the arguments, according to the dispatch rules.
This commit is contained in:
Étienne Fildadut 2024-05-16 17:35:57 +02:00
parent d04344e9ff
commit b47e1940e9
3 changed files with 16 additions and 4 deletions

View file

@ -34,19 +34,33 @@ return {
}, },
{ {
"call", "(func::is callable, args::is tuple)", "call", "(func, args::is tuple)",
function(state, fn, args) function(state, fn, args)
return fn:call(state, args:to_argument_tuple()) return fn:call(state, args:to_argument_tuple())
end end
}, },
{ {
"call", "(func::is callable, args::is tuple) = v", "call", "(func, args::is tuple) = v",
function(state, fn, args, v) function(state, fn, args, v)
local argumenttuple = args:to_argument_tuple() local argumenttuple = args:to_argument_tuple()
argumenttuple:add_assignment(v) argumenttuple:add_assignment(v)
return fn:call(state, argumenttuple) return fn:call(state, argumenttuple)
end end
}, },
{
"can dispatch", "(func, args::is tuple)",
function(state, fn, args)
return Boolean:new(not not fn:dispatch(state, args:to_argument_tuple()))
end,
},
{
"can dispatch", "(func, args::is tuple) = v",
function(state, fn, args, v)
local argumenttuple = args:to_argument_tuple()
argumenttuple:add_assignment(v)
return Boolean:new(not not fn:dispatch(state, argumenttuple))
end,
},
{ {
"_._", "(c::is function, s::is string)", "_._", "(c::is function, s::is string)",

View file

@ -60,7 +60,6 @@ return [[
:@est un booléen = stdlib.is boolean :@est un booléen = stdlib.is boolean
:@est vrai = stdlib.is true :@est vrai = stdlib.is true
:@est faux = stdlib.is false :@est faux = stdlib.is false
:@est appelable = stdlib.is callable
:@est une fonction = stdlib.is function :@est une fonction = stdlib.is function
:@est une liste = stdlib.is list :@est une liste = stdlib.is list
:@est un dictionnaire = stdlib.is map :@est un dictionnaire = stdlib.is map

View file

@ -25,5 +25,4 @@ return [[
:@is function = is("function") :@is function = is("function")
:@is overload = is("overload") :@is overload = is("overload")
:@is callable = $(x) x!type == "overload" | x!type == "function" | x!type == "quote"
]] ]]