The Grinnell Scheme Web: The * procedure

How do I multiply numbers in Scheme?

Call the * procedure, and give it all of the numbers you want to multiply as operands. Here are some examples:

> (* 11 13)
143
> (* -9 -111111111111)
999999999999
> (* 1 2 3 4 5)
120
The * procedure accepts numbers of any supported type as operands:
> (* 3/4 -1/3 1/12)
-1/48
> (* 7.2+6.1i -4.3i)
26.23-30.96i
Does * accept any number of operands, like +? What does it return if you give it one operand or none?

Yes, you can give * any number of operands. The ``product'' of one number is that number itself, and the ``product'' of no numbers is the multiplicative identity, 1:

> (* 53)
53
> (*)
1
Again, this makes sense analogically: (* 5 5 5) is 125, (* 5 5) is 25, (* 5) is 5, so naturally (*) is 1.


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/times.html


created June 23, 1995
last revised December 30, 1995

Copyright 1995 by John David Stone (stone@math.grin.edu)