chicken-janitors
[Top][All Lists]
Advanced

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

#1703: Arguments being passed to procedure incorrectly


From: Chicken Trac
Subject: #1703: Arguments being passed to procedure incorrectly
Date: Sat, 11 Jul 2020 23:39:42 -0000

#1703: Arguments being passed to procedure incorrectly
--------------------------------+----------------------
            Reporter:  jakob    |       Type:  defect
              Status:  new      |   Priority:  major
           Milestone:  someday  |  Component:  compiler
             Version:  5.2.0    |   Keywords:
Estimated difficulty:  hard     |
--------------------------------+----------------------
 Here is the offending part of a program I have been writing.

 {{{
 (define (reduce proc list init)
   (define (reduce-iter list result)
     (if (null? list)
         result
         (reduce-iter (cdr list) (proc result (car list)))))
   (reduce-iter list init))

 (define-record-type <vec3>
   (make-vec3 x y z)
   vec3?
   (x vec3-x)
   (y vec3-y)
   (z vec3-z))

 ;; Macro for destructuring a vec3.
 (define-syntax vec3-bind
   (syntax-rules ()
     ((vec3-bind ((names vec) ...)
        body)
      (let-values ((names (values (vec3-x vec)
                                  (vec3-y vec)
                                  (vec3-z vec)))
                   ...)
        body))))

 (define (vec3- . vecs)
   "Return the difference of VECS, as in vector space subtraction."
   (define (sub u v)
     (vec3-bind (((x1 y1 z1) u) ((x2 y2 z2) v))
       (make-vec3 (- x1 x2) (- y1 y2) (- z1 z2))))
   (if (zero? (length vecs))
       (make-vec3 0 0 0)
       (reduce sub (cdr vecs) (car vecs))))

 (vec3- (make-vec3 1.00 1.00 1.00)
        (make-vec3 1.00 1.00 1.00)
        (make-vec3 1.00 1.00 1.00))
 }}}

 This runs without error on Version 4.13.0 (rev 68eeaaef), but on Version
 5.2.0 (rev 317468e4), I get the following runtime error.

 {{{

 Error: (vec3-x) bad argument type - not a structure of the required type
 #<procedure (sub u v)>
 <vec3>

         Call history:

         r7rs-raytracer.scm:35: make-vec3
         r7rs-raytracer.scm:36: make-vec3
         r7rs-raytracer.scm:37: make-vec3
         r7rs-raytracer.scm:35: vec3-
         r7rs-raytracer.scm:33: reduce
         r7rs-raytracer.scm:6: reduce-iter
         r7rs-raytracer.scm:5: proc
         r7rs-raytracer.scm:29: ##sys#call-with-values
         r7rs-raytracer.scm:29: vec3-x           <--
 }}}

 I could not build the master branch, so I was unable to see if this has
 been resolved.

 I suspect the arguments are being passed in the wrong order to 'reduce',
 somehow. This error only occurs if the number of arguments to vec3- is
 greater than 2.

-- 
Ticket URL: <https://bugs.call-cc.org/ticket/1703>
CHICKEN Scheme <https://www.call-cc.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.

reply via email to

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