func listSeq(context *parser.FunctionCallContext) error { values, err := parser.ValidateArguments(context, "list-seq", parser.VALUE_NUMBER, parser.VALUE_NUMBER) if err != nil { return err } newList := parser.NewListValue() min, _ := values[1].N.Float64() max, _ := values[0].N.Float64() if int(min) > int(max) { for i := int(min); i >= int(max); i-- { newList.L = append(newList.L, parser.NewValueFromInt64(int64(i))) } } else { for i := int(min); i <= int(max); i++ { newList.L = append(newList.L, parser.NewValueFromInt64(int64(i))) } } context.Block.Stack.Push(newList) return nil }
func listSize(context *parser.FunctionCallContext) error { values, err := parser.ValidateArguments(context, "list-size", parser.VALUE_LIST) if err != nil { return err } context.Block.Stack.Push(parser.NewValueFromInt64(int64(len(values[0].L)))) return nil }
func stringLength(context *parser.FunctionCallContext) error { values, err := parser.ValidateArguments(context, "string-length", parser.VALUE_STRING) if err != nil { return err } context.Block.Stack.Push(parser.NewValueFromInt64(int64(len(values[0].S)))) return nil }
func stringAt(context *parser.FunctionCallContext) error { values, err := parser.ValidateArguments(context, "string-at", parser.VALUE_STRING, parser.VALUE_STRING) if err != nil { return err } context.Block.Stack.Push(parser.NewValueFromInt64(int64(strings.Index(values[1].S, values[0].S)))) return nil }
func mod(context *parser.FunctionCallContext) error { values, err := parser.ValidateArguments(context, "mod", parser.VALUE_NUMBER, parser.VALUE_NUMBER) if err != nil { return err } n1, _ := values[1].N.Float64() n2, _ := values[0].N.Float64() context.Block.Stack.Push(parser.NewValueFromInt64(int64(n1) % int64(n2))) return nil }
func rand_(context *parser.FunctionCallContext) error { values, err := parser.ValidateArguments(context, "rand", parser.VALUE_NUMBER, parser.VALUE_NUMBER) if err != nil { return err } max, _ := values[0].N.Float64() min, _ := values[1].N.Float64() rand := int(min) + rand.Intn(int(max)) context.Block.Stack.Push(parser.NewValueFromInt64(int64(rand))) return nil }
func stringRuneAt(context *parser.FunctionCallContext) error { values, err := parser.ValidateArguments(context, "string-rune-at", parser.VALUE_STRING, parser.VALUE_STRING) if err != nil { return err } s := values[0].S if len(s) == 0 || len(s) > 1 { return util.NewInvalidArgumentError("string-rune-at", "expected a string of 1 character", context.Token.Line, context.Token.Column, context.Token.File) } context.Block.Stack.Push(parser.NewValueFromInt64(int64(strings.IndexRune(values[1].S, rune(s[0]))))) return nil }
func listEachWithIndex(context *parser.FunctionCallContext) error { values, err := parser.ValidateArguments(context, "list-each-with-index", parser.VALUE_FUNCTION, parser.VALUE_LIST) if err != nil { return err } function := values[0].F for i, item := range values[1].L { _, err := execFunctionWithArguments(context, function, "list-each-with-index", true, parser.NewValueFromInt64(int64(i)), item) if err != nil { return err } } return nil }
func timenano(context *parser.FunctionCallContext) error { context.Block.Stack.Push(parser.NewValueFromInt64(time.Now().UnixNano())) return nil }
func size(context *parser.FunctionCallContext) error { context.Block.Stack.Push(parser.NewValueFromInt64(int64(context.Block.Stack.Len()))) return nil }