Skip to content

Commit

Permalink
remove accidental introduced integer-division function
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Dec 5, 2023
1 parent 8e932ed commit 7272c97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
11 changes: 5 additions & 6 deletions pkg/builtin/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ var (
"gte?": functions.NewBuilder(gteCoalescer).WithDescription("returns a >= b").Build(),
}

// aliases to make bang functions nicer (add! vs +!)
addRudiFunction = functions.NewBuilder(numberAddFunction, integerAddFunction).WithDescription("returns the sum of all of its arguments").Build()
subRudiFunction = functions.NewBuilder(numberSubFunction, integerSubFunction).WithDescription("returns arg1 - arg2 - .. - argN").Build()
multiplyRudiFunction = functions.NewBuilder(numberMultFunction, integerMultFunction).WithDescription("returns the product of all of its arguments").Build()
divideRudiFunction = functions.NewBuilder(numberDivFunction, integerDivFunction).WithDescription("returns arg1 / arg2 / .. / argN").Build()
addRudiFunction = functions.NewBuilder(integerAddFunction, numberAddFunction).WithDescription("returns the sum of all of its arguments").Build()
subRudiFunction = functions.NewBuilder(integerSubFunction, numberSubFunction).WithDescription("returns arg1 - arg2 - .. - argN").Build()
multiplyRudiFunction = functions.NewBuilder(integerMultFunction, numberMultFunction).WithDescription("returns the product of all of its arguments").Build()
divideRudiFunction = functions.NewBuilder(numberDivFunction).WithDescription("returns arg1 / arg2 / .. / argN (always a floating point division, regardless of arguments)").Build()

MathFunctions = types.Functions{
"+": addRudiFunction,
Expand All @@ -65,7 +64,7 @@ var (
lenRudiFunction = functions.NewBuilder(stringLenFunction, vectorLenFunction, objectLenFunction).WithDescription("returns the length of a string, vector or object").Build()
appendRudiFunction = functions.NewBuilder(appendToVectorFunction, appendToStringFunction).WithDescription("appends more strings to a string or arbitrary items into a vector").Build()
prependRudiFunction = functions.NewBuilder(prependToVectorFunction, prependToStringFunction).WithDescription("prepends more strings to a string or arbitrary items into a vector").Build()
reverseRudiFunction = functions.NewBuilder(reverseVectorFunction, reverseStringFunction).WithDescription("reverses a string or the elements of a vector").Build()
reverseRudiFunction = functions.NewBuilder(reverseStringFunction, reverseVectorFunction).WithDescription("reverses a string or the elements of a vector").Build()
containsRudiFunction = functions.NewBuilder(stringContainsFunction, vectorContainsFunction).WithDescription("returns true if a string contains a substring or a vector contains the given element").Build()

StringsFunctions = types.Functions{
Expand Down
6 changes: 3 additions & 3 deletions pkg/builtin/lists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func TestRangeFunction(t *testing.T) {
},
{
// multiple expressions that use a common context
Expression: `(range [1 2 3] [a] (set! $foo $a) (+ $foo 3))`,
Expression: `(range [1 2 3] [a] (do (set! $foo $a) (+ $foo 3)))`,
Expected: int64(6),
},
{
Expand Down Expand Up @@ -442,12 +442,12 @@ func TestMapFunction(t *testing.T) {
},
{
// last expression controls the result
Expression: `(map [1 2 3] [val] (+ $val 3) "foo")`,
Expression: `(map [1 2 3] [val] (do (+ $val 3) "foo"))`,
Expected: []any{"foo", "foo", "foo"},
},
{
// multiple expressions that use a common context
Expression: `(map [1 2 3] [val] (set! $foo $val) (+ $foo 3))`,
Expression: `(map [1 2 3] [val] (do (set! $foo $val) (+ $foo 3)))`,
Expected: []any{int64(4), int64(5), int64(6)},
},
{
Expand Down
12 changes: 0 additions & 12 deletions pkg/builtin/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ func numberMultFunction(base ast.Number, extra ...ast.Number) (any, error) {
return product, nil
}

func integerDivFunction(base int64, extra ...int64) (any, error) {
for _, num := range extra {
if num == 0 {
return nil, errors.New("division by zero")
}

base /= num
}

return base, nil
}

func numberDivFunction(base ast.Number, extra ...ast.Number) (any, error) {
result := base.MustToFloat()

Expand Down

0 comments on commit 7272c97

Please sign in to comment.