How about subtraction? How does that work in Scheme?
Call the - procedure, giving it the minuend as the first
operand and the subtrahend as the second:
Must all the numbers be integers?> (- 128 71) 57 > (- 129837981749809183094102634 23098172098709187098273) 129814883577710473907004361 > (- 31 47) -16 > (- -12 -23) 11
No. Like the + procedure, - takes accepts as
operands any numbers that are supported by the implementation.
What will the - procedure do if you give it a different number
of operands?
If you give it just one operand, it returns the negative (the additive inverse) of the number:
Giving it no operands at all is an error that will probably bring your program to an abrupt halt:> (- 12) -12 > (- -43) 43 > (- 0) 0
(In this advisory message, produced by the SCM implementation of Scheme, the word ``args'' is short for ``arguments.'' An argument is an expression that is evaluated to obtain an operand for a procedure.)> (-) ERROR: -: Wrong number of args
The Scheme standard does not require an implementation of the
- procedure to make any provision for more than two operands.
Some Scheme implementations (SCM and Elk, for instance) treat any extra
operands as additional subtrahends:
Others (Scheme 48, for instance) consider such calls erroneous:> (- 12 1 2 3 4) 2
> (- 12 1 2 3 4)
Error: wrong number of arguments
(- 12 1 2 3 4)
The careful programmer will avoid giving - more than two
operands.
Next topic
Previous topic
Table of contents
This document is available on the World Wide Web as
http://www.math.grin.edu/~stone/scheme-web/minus.html