Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit 7272c97

Browse files
committed
remove accidental introduced integer-division function
1 parent 8e932ed commit 7272c97

3 files changed

Lines changed: 8 additions & 21 deletions

File tree

pkg/builtin/functions.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ var (
4343
"gte?": functions.NewBuilder(gteCoalescer).WithDescription("returns a >= b").Build(),
4444
}
4545

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

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

7170
StringsFunctions = types.Functions{

pkg/builtin/lists_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func TestRangeFunction(t *testing.T) {
315315
},
316316
{
317317
// multiple expressions that use a common context
318-
Expression: `(range [1 2 3] [a] (set! $foo $a) (+ $foo 3))`,
318+
Expression: `(range [1 2 3] [a] (do (set! $foo $a) (+ $foo 3)))`,
319319
Expected: int64(6),
320320
},
321321
{
@@ -442,12 +442,12 @@ func TestMapFunction(t *testing.T) {
442442
},
443443
{
444444
// last expression controls the result
445-
Expression: `(map [1 2 3] [val] (+ $val 3) "foo")`,
445+
Expression: `(map [1 2 3] [val] (do (+ $val 3) "foo"))`,
446446
Expected: []any{"foo", "foo", "foo"},
447447
},
448448
{
449449
// multiple expressions that use a common context
450-
Expression: `(map [1 2 3] [val] (set! $foo $val) (+ $foo 3))`,
450+
Expression: `(map [1 2 3] [val] (do (set! $foo $val) (+ $foo 3)))`,
451451
Expected: []any{int64(4), int64(5), int64(6)},
452452
},
453453
{

pkg/builtin/math.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,6 @@ func numberMultFunction(base ast.Number, extra ...ast.Number) (any, error) {
6060
return product, nil
6161
}
6262

63-
func integerDivFunction(base int64, extra ...int64) (any, error) {
64-
for _, num := range extra {
65-
if num == 0 {
66-
return nil, errors.New("division by zero")
67-
}
68-
69-
base /= num
70-
}
71-
72-
return base, nil
73-
}
74-
7563
func numberDivFunction(base ast.Number, extra ...ast.Number) (any, error) {
7664
result := base.MustToFloat()
7765

0 commit comments

Comments
 (0)