From 389d48b646822288f59c6b80c9fc58e6477d8fec Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Fri, 10 May 2024 04:43:14 +0200 Subject: [PATCH] func-base.go: added functions to check data-type of a value --- func-base.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/func-base.go b/func-base.go index 7211003..755c47c 100644 --- a/func-base.go +++ b/func-base.go @@ -18,6 +18,42 @@ func isNilFunc(ctx ExprContext, name string, args []any) (result any, err error) return } +func isIntFunc(ctx ExprContext, name string, args []any) (result any, err error) { + result = IsInteger(args[0]) + return +} + +func isFloatFunc(ctx ExprContext, name string, args []any) (result any, err error) { + result = IsFloat(args[0]) + return +} + +func isBoolFunc(ctx ExprContext, name string, args []any) (result any, err error) { + result = IsBool(args[0]) + return +} + +func isStringFunc(ctx ExprContext, name string, args []any) (result any, err error) { + result = IsString(args[0]) + return +} + +func isFractionFunc(ctx ExprContext, name string, args []any) (result any, err error) { + result = IsFract(args[0]) + return +} + +func isListFunc(ctx ExprContext, name string, args []any) (result any, err error) { + result = IsList(args[0]) + return +} + +func isDictionaryFunc(ctx ExprContext, name string, args []any) (result any, err error) { + result = IsDict(args[0]) + return +} + + func intFunc(ctx ExprContext, name string, args []any) (result any, err error) { if len(args) == 1 { switch v := args[0].(type) { @@ -50,8 +86,17 @@ func iteratorFunc(ctx ExprContext, name string, args []any) (result any, err err } func ImportBuiltinsFuncs(ctx ExprContext) { - ctx.RegisterFunc("isNil", &simpleFunctor{f: isNilFunc}, 1, -1) - ctx.RegisterFunc("int", &simpleFunctor{f: intFunc}, 1, -1) + ctx.RegisterFunc("isNil", &simpleFunctor{f: isNilFunc}, 1, 1) + ctx.RegisterFunc("isInt", &simpleFunctor{f: isIntFunc}, 1, 1) + ctx.RegisterFunc("isFloat", &simpleFunctor{f: isFloatFunc}, 1, 1) + ctx.RegisterFunc("isBool", &simpleFunctor{f: isBoolFunc}, 1, 1) + ctx.RegisterFunc("isString", &simpleFunctor{f: isStringFunc}, 1, 1) + ctx.RegisterFunc("isFraction", &simpleFunctor{f: isFractionFunc}, 1, 1) + ctx.RegisterFunc("isFract", &simpleFunctor{f: isFractionFunc}, 1, 1) + ctx.RegisterFunc("isList", &simpleFunctor{f: isListFunc}, 1, 1) + ctx.RegisterFunc("isDictionary", &simpleFunctor{f: isDictionaryFunc}, 1, 1) + ctx.RegisterFunc("isDict", &simpleFunctor{f: isDictionaryFunc}, 1, 1) + ctx.RegisterFunc("int", &simpleFunctor{f: intFunc}, 1, 1) } func init() {