chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] complex library package issue


From: Kon Lovett
Subject: Re: [Chicken-users] complex library package issue
Date: Sat, 1 Sep 2007 16:24:45 -0700


On Sep 1, 2007, at 2:49 PM, Terrence Brannon wrote:

Hello, the complex package is turning the addition of two lists which
start with zero into a complex result when it should just be another
list. Case synopsis:

(Plus '(0 1 2 3) '(0 1 2 3))  ;; yields a complex!
(Plus '(1 2 3) '(1 2 3))      ;; yields a list, as expected
(Plus  3 '(1 2 3))            ;; yields a list, as expected
(Plus  3 4)                   ;; yields a scalar, as expected

The code which follows will exemplify this behavior, as long as you
get all the eggs that it requires:

chicken-setup array-lib complex

(require-extension array-lib)
(require-extension array-lib-hof)
(require-extension complex)


(use srfi-1)

; http://srfi.schemers.org/srfi-63/srfi-63.html
(define (strict-array? obj)
  (and (array? obj) (not (string? obj)) (not (vector? obj))))

'strict-array?' is not part of SRFI-63, but an example. The functionality is provided by 'array-lib' as the 'array-strict?' procedure, which is stronger than the example in the SRFI document.



(define (map-wrap proc . lists)
  (cond
   ((any strict-array? lists)
    (let* ([newlists (apply array-agree lists)])
      (apply array-map '#() proc newlists)))

You didn't include 'array-agree' but not called by the examples anyway.

    ((any (lambda (x) (and list? (not (complex? x)))) lists)

Not sure what you are testing here, 'list?' should always be true, since it is a reference to the top-level binding & will result in a procedure.

         (apply map
             proc
             (map (lambda (x)
                    (if (not (pair? x))
                        (circular-list x)
                        x))
                  lists)))
    (else (apply proc lists))))

(define (Shape dim-list . data)
(let* ([dimension-list (if (list? dim-list) dim-list (list dim- list))]
         [prototype '#()]
         [dimensions (apply make-array-dimensions dimension-list)]
         [cardinality (apply * dimension-list)]
         [data-size (lambda () (length data))]
         [list-logic (lambda (L)
                       (cond
                        ((= (data-size) cardinality) data)
((> (data-size) cardinality) (take data cardinality))
                        ((< (data-size) cardinality)
(take (apply circular-list data) cardinality))))]
         [data* (if (list? data)
                    (list-logic data)
                    (make-list cardinality data))]
         [vektor (list->vector data*)])
    (apply vector->array vektor prototype dimension-list)))


(define (Plus m n) (map-wrap + m n))

(Plus '(0 1 2 3) '(0 1 2 3))  ;; yields a complex!

Sorry, I cannot reproduce the above result:

#;8> (Plus '(0 1 2 3) '(0 1 2 3))
(#,(complex 0 0) 2 4 6)

which is a list. When the result is a real (imag-part = 0) only the real-part is returned, but 0i0 is not considered a real by the complex egg.

You might want to use the numbers egg as the complex egg hasn't been touched in over a year.

Best Wishes,
Kon

(Plus '(1 2 3) '(1 2 3))      ;; yields a list, as expected
(Plus  3 '(1 2 3))            ;; yields a list, as expected
(Plus  3 4)                   ;; yields a scalar, as expected


_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users





reply via email to

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