Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100% consistency on argument-requirements. #45

Merged
merged 1 commit into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 42 additions & 41 deletions builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func archFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv
func carFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {

if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

// ensure we received a list
Expand All @@ -176,7 +176,7 @@ func carFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive
func cdrFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {

if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

// ensure we received a list
Expand All @@ -195,7 +195,7 @@ func cdrFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive
func chrFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {

if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

if _, ok := args[0].(primitive.Number); !ok {
Expand All @@ -211,7 +211,7 @@ func chrFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive
// consFn implements (cons).
func consFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) < 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

if len(args) == 1 {
Expand All @@ -231,7 +231,7 @@ func containsFn(env *env.Environment, args []primitive.Primitive) primitive.Prim

// We need a pair of arguments
if len(args) != 2 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// First is a Hash
Expand Down Expand Up @@ -279,7 +279,7 @@ func directoryEntriesFn(env *env.Environment, args []primitive.Primitive) primit

// We only need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a string
Expand Down Expand Up @@ -308,7 +308,7 @@ func directoryFn(env *env.Environment, args []primitive.Primitive) primitive.Pri

// We only need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a string
Expand All @@ -335,7 +335,7 @@ func directoryFn(env *env.Environment, args []primitive.Primitive) primitive.Pri
func divideFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
// ensure we have at least one argument
if len(args) < 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// the first argument must be a number.
Expand Down Expand Up @@ -365,7 +365,7 @@ func divideFn(env *env.Environment, args []primitive.Primitive) primitive.Primit
// eqFn implements "eq"
func eqFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 2 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

a := args[0]
Expand All @@ -383,7 +383,7 @@ func eqFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive
// equalsFn implements "="
func equalsFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 2 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

a := args[0]
Expand All @@ -404,7 +404,7 @@ func equalsFn(env *env.Environment, args []primitive.Primitive) primitive.Primit
// errorFn implements "error"
func errorFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}
return primitive.Error(args[0].ToString())
}
Expand All @@ -414,7 +414,7 @@ func existsFn(env *env.Environment, args []primitive.Primitive) primitive.Primit

// We only need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a string
Expand Down Expand Up @@ -481,8 +481,9 @@ func expandStr(input string) string {
// expnFn implements "#"
func expnFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 2 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

if _, ok := args[0].(primitive.Number); !ok {
return primitive.Error("argument not a number")
}
Expand All @@ -496,7 +497,7 @@ func expnFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv
func fileFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
// We only need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a string
Expand All @@ -523,7 +524,7 @@ func fileFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv
func fileLinesFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
// We only need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a string
Expand Down Expand Up @@ -556,7 +557,7 @@ func fileLinesFn(env *env.Environment, args []primitive.Primitive) primitive.Pri
func fileReadFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
// We only need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a string
Expand All @@ -578,7 +579,7 @@ func fileReadFn(env *env.Environment, args []primitive.Primitive) primitive.Prim
func fileStatFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
// We only need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a string
Expand Down Expand Up @@ -639,7 +640,7 @@ func getFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive

// We need two arguments
if len(args) != 2 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// First is a Hash
Expand All @@ -656,7 +657,7 @@ func getenvFn(env *env.Environment, args []primitive.Primitive) primitive.Primit

// If we have only a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a string
Expand All @@ -674,7 +675,7 @@ func globFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv

// If we have only a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a string
Expand Down Expand Up @@ -703,7 +704,7 @@ func globFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv
func helpFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
// We need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a function
Expand Down Expand Up @@ -734,7 +735,7 @@ func joinFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv

// We require one argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// The argument must be a list
Expand All @@ -756,7 +757,7 @@ func keysFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv

// We need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// First is a Hash
Expand Down Expand Up @@ -797,7 +798,7 @@ func listFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv
// ltFn implements "<"
func ltFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 2 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

if _, ok := args[0].(primitive.Number); !ok {
Expand All @@ -814,7 +815,7 @@ func matchFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti

// We need two arguments
if len(args) != 2 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// First argument is a string (which is a regexp)
Expand Down Expand Up @@ -869,7 +870,7 @@ func minusFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti

// ensure we have at least one argument
if len(args) < 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// the first argument must be a number.
Expand All @@ -895,7 +896,7 @@ func minusFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti
// modFn implements "%"
func modFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 2 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}
if _, ok := args[0].(primitive.Number); !ok {
return primitive.Error("argument not a number")
Expand All @@ -921,7 +922,7 @@ func msFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive
func multiplyFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
// ensure we have at least one argument
if len(args) < 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// the first argument must be a number.
Expand All @@ -947,7 +948,7 @@ func multiplyFn(env *env.Environment, args []primitive.Primitive) primitive.Prim
// nilFn implements nil?
func nilFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

// nil is nil (yeah, really)
Expand All @@ -972,7 +973,7 @@ func nowFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive
func ordFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {

if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

if _, ok := args[0].(primitive.String); !ok {
Expand Down Expand Up @@ -1000,7 +1001,7 @@ func plusFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv

// ensure we have at least one argument
if len(args) < 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// the first argument must be a number.
Expand All @@ -1027,7 +1028,7 @@ func plusFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv
func printFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
// no args
if len(args) < 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

// one arg
Expand Down Expand Up @@ -1059,7 +1060,7 @@ func printFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti
// randomFn implements (random).
func randomFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

// ensure we received a number
Expand All @@ -1078,7 +1079,7 @@ func setFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive

// We need three arguments
if len(args) != 3 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// First is a Hash
Expand All @@ -1096,7 +1097,7 @@ func shellFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti

// We need one argument
if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

// The argument must be a list
Expand Down Expand Up @@ -1138,7 +1139,7 @@ func shellFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti
func sortFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
// If we have only a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Which is a list
Expand Down Expand Up @@ -1182,7 +1183,7 @@ func splitFn(env *env.Environment, args []primitive.Primitive) primitive.Primiti

// We require two arguments
if len(args) != 2 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// Both arguments must be strings
Expand Down Expand Up @@ -1210,7 +1211,7 @@ func sprintfFn(env *env.Environment, args []primitive.Primitive) primitive.Primi

// we need 2+ arguments
if len(args) < 2 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}

// OK format-string
Expand All @@ -1231,7 +1232,7 @@ func sprintfFn(env *env.Environment, args []primitive.Primitive) primitive.Primi
// strFn implements "str"
func strFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}
return primitive.String(args[0].ToString())
}
Expand All @@ -1256,7 +1257,7 @@ func timeFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv
// typeFn implements "type"
func typeFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
if len(args) != 1 {
return primitive.Error("wrong number of arguments")
return primitive.ArityError()
}
return primitive.String(args[0].Type())
}
Expand All @@ -1266,7 +1267,7 @@ func valsFn(env *env.Environment, args []primitive.Primitive) primitive.Primitiv

// We need a single argument
if len(args) != 1 {
return primitive.Error("invalid argument count")
return primitive.ArityError()
}

// First is a Hash
Expand Down
Loading