It's one of the most trivial library functions ever:
(define (square x) (* x x))
But I've written it many times, and I'm not alone. So it was a pleasant surprise to see that WG1 recently voted to add it to R7RS.
The request gave the (weak) reason that it could have an optimized method for bignums, but voter comments suggest they were more interested in symmetry with sqrt
. They also added make-list
for symmetry with make-vector
. I don't think symmetry is a good reason in either case, let alone sufficient reason to add features to Small Scheme, but square
is attractive as a convenience.
It's not the most important feature (and it probably belongs in Big Scheme, not Small Scheme), but it's a small step forward. Every language that aims to be convenient should have square
in its standard library.
I actually find myself writing make-list occasionally when writing tests. CompleteSequenceCowan shows the procedures WG1 added for symmetry between lists, strings, and vectors. Bytevectors, however, only have a subset of these.
ReplyDelete