[Top][All Lists]

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

Re: (< complex) and friends

From: Neil Jerram
Subject: Re: (< complex) and friends
Date: Wed, 17 Sep 2008 23:37:24 +0200

This is mostly for the record, as I'm afraid I don't have any fix yet...

2008/8/12 Neil Jerram <address@hidden>:
> 2008/8/11 Bill Schottstaedt <address@hidden>:
>> guile> (< 1.0+1.0i)
>> #t

> My guess (without actually looking at the code) is that

> - the single arg case is being optimized before reaching the check for
> a complex number.

My guess was correct.  This comes from < being implemented as a
scm_tc7_rpsubr, which means that there is an underlying C primitive
(scm_less_p) that takes 2 args, and the evaluator deals with calling
this however many times are needed.  When there's just 1 arg, the
evaluator shortcuts the process and returns #t.

Instead of just returning #t, I guess there should be a type predicate
call.  It's not obvious where one would store the type predicate
though, in the subr structure...

As a workaround, you could use:

(let ((libguile-< <))
  (set! < (lambda args
            (or (null? args)
                (not (null? (cdr args)))
                (real? (car args))
                (error "wrong type arg" (car args)))
            (apply libguile-< args))))

Would that help?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]