On Wed, 21 Jun 100, J C Fitzgerald wrote:

> I am just learning Scheme, so this is probably my error rather than
> Guile's, but the following appears to give inconsistant results:
> 
> 
>     (define (reduce op nv ls)
>       (if (null? ls) nv
>         (op (car ls) (reduce op nv (cdr ls)))))
> 
>     (define ii '(1 2 3 4 5))
>     (define bb '(#t #t #f #f))
> 
>     (display "1. ") (display (reduce + 0 ii)) (newline)
>     (display "2. ") (display (reduce and #t bb)) (newline)
>     (display "3. ") (display (reduce + 0 ii)) (newline)
>     (display "\nShouldn't results 1 and 3 be the same?\n")

The error is still present even in the newest guile.  However, the reason
has most probably to do with macro expansion (which is magic to me btw):


guile>     (define (reduce op nv ls)
...       (if (null? ls) nv
...           (op (car ls) (reduce op nv (cdr ls)))))
guile> (procedure-source reduce)
(lambda (op nv ls) (if (null? ls) nv (op (car ls) (reduce op nv (cdr
ls)))))
guile>     (define bb '(#t #t #f #f))
guile>     (display "2. ") (display (reduce and #t bb)) (newline)
2. #f
guile> (procedure-source reduce)
(lambda (op nv ls) (if (null? ls) nv (and (car ls) (reduce op nv (cdr
ls)))))


After the macro 'and' is passed as a parameter to reduce, the source of
the procedure is changed!  I doubt that it is legal to pass a macro as a
parameter at all.

Best regards
Dirk

Reply via email to