Too many arguments for function

I am starting to learn Lisp from the Java background. The SICP exercise has many tasks when students should create abstract functions with many parameters, for example

(define (filtered-accumulate combiner null-value term a next b filter)...) 

to exercise 3.11 . In Java (a language with a safe, static typed discipline), a method with more than 4 arguments usually smells, but in Lisp / Scheme this is not so, is it? I am wondering how many arguments do you use in your functions? If you use it in production, do you make so many layers?

+6
function functional-programming lisp arguments scheme
source share
1 answer

SICP is a book used in an introductory computer science course. Although he explains some advanced concepts, he uses a very tiny language, a subset of the Schema language, and a subset of any real world schema or Lisp provides a typical implementation.

In SICP, for example, there are no macros. Add that the standard circuit has only positional parameters for functions.

In 'real' Lisp or in a schema, you can use one or more of the following:

  • objects or records / structures (bad human circuits) that group things together. A transferred object may contain several data elements that would otherwise have to be spread.

  • default values ​​for optional variables. Thus, we only need to convey those that we want to have a non-standard value

  • optional and named arguments. This allows flexible lists of arguments that are more descriptive.

  • computed arguments. The default value or value of the arguments can be calculated based on other arguments.

The above leads to more complicated writing of functional interfaces, which are often easier to use.

In Lisp, good style has descriptive names for arguments, and also provides online documentation for the interface. Information on the interface of the function will be displayed in the development environment, so this information is usually just a keystroke or even automatically displayed.

It is also a good style for any non-trivial interface that should be used interactively by the user / developer to check his arguments at runtime.

+12
source share

All Articles