From b47e1940e93645541df163675c0a4d49df892a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Thu, 16 May 2024 17:35:57 +0200 Subject: [PATCH] [stdlib] remove is callable, add can dispatch Since whether something can be called or not depends on the arguments, according to the dispatch rules. --- anselme/stdlib/function.lua | 18 ++++++++++++++++-- anselme/stdlib/language/frFR.lua | 1 - anselme/stdlib/value check.lua | 1 - 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/anselme/stdlib/function.lua b/anselme/stdlib/function.lua index 47ae905..f509f5c 100644 --- a/anselme/stdlib/function.lua +++ b/anselme/stdlib/function.lua @@ -34,19 +34,33 @@ return { }, { - "call", "(func::is callable, args::is tuple)", + "call", "(func, args::is tuple)", function(state, fn, args) return fn:call(state, args:to_argument_tuple()) end }, { - "call", "(func::is callable, args::is tuple) = v", + "call", "(func, args::is tuple) = v", function(state, fn, args, v) local argumenttuple = args:to_argument_tuple() argumenttuple:add_assignment(v) return fn:call(state, argumenttuple) 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)", diff --git a/anselme/stdlib/language/frFR.lua b/anselme/stdlib/language/frFR.lua index 09c8d47..256ffec 100644 --- a/anselme/stdlib/language/frFR.lua +++ b/anselme/stdlib/language/frFR.lua @@ -60,7 +60,6 @@ return [[ :@est un booléen = stdlib.is boolean :@est vrai = stdlib.is true :@est faux = stdlib.is false -:@est appelable = stdlib.is callable :@est une fonction = stdlib.is function :@est une liste = stdlib.is list :@est un dictionnaire = stdlib.is map diff --git a/anselme/stdlib/value check.lua b/anselme/stdlib/value check.lua index 86f1f59..6be48e4 100644 --- a/anselme/stdlib/value check.lua +++ b/anselme/stdlib/value check.lua @@ -25,5 +25,4 @@ return [[ :@is function = is("function") :@is overload = is("overload") -:@is callable = $(x) x!type == "overload" | x!type == "function" | x!type == "quote" ]] \ No newline at end of file