[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Optional base argument for LOG (and friends)



Hello everyone!
I've recently started a (hopefully useful) debate on
comp.lang.scheme on little changes for R6RS
(<87r7309irh.fsf@xxxxxxxxxxxxxxxxxxxxxxxxxxx>), and tried to get
the ideas rolling with one of my smaller wishes. Michael Sperber
was kind enough to remind me that this SRFI exists for arithmetic
stuff, so I'll repeat my wish here:

It would be nice if the LOG procedure of R5RS would allow an
optional second argument, BASE, for the basis to which the
logarithm is calculated. This is the behavior from Common Lisp,
and the implementation is trivial - but I don't see a reason why
the base procedure shouldn't accept a BASE argument.

The implementation for R5RS is trivial, of course:

(define log
  (let ((ln log))
    (lambda (x . basel)
      (if (null? basel)
          (ln x)
          (/ (ln x)
             (ln (car basel)))))))

Taylor Campbell noted that it would be cleaner to have the base as
the first argument, and provide a more "intuitively" named LN
procedure for the natural logarithm, i.e. (LOG B Z) and (LN Z).

In SRFI 77, there's also INLOG and FLLOG, both accepting only a
single argument. In the spirit of *ATAN1 and *ATAN2, those would
probably be named {IN,FL}LOG{1,2}, though just providing extra
{IN,FL}LOG2 would also be sufficient.

Regards,
        -- Jorgen


PS. There's apparently a typo in SRFI 77:

    procedure: flatan1 fl
    procedure: flatan2 fl1 fl2

        [...] `(flatan1 fl1 fl2)' computes the arc tangent of fl1
        /fl2. The range of flatan1 and flatan2 lies between -pi/2 and
        pi/2, both inclusive if -0.0 is distinguished, both exclusive
        otherwise.

Note that FLATAN1 only accepts one arg, I assume the text refers
to FLATAN2 there.

-- 
((email . "forcer@xxxxxxxxx") (www . "http://www.forcix.cx/";)
 (gpg   . "1024D/028AF63C")   (irc . "nick forcer on IRCnet"))