Hello all,

Is there any reason for which I get a different behaviour on this 2 functions:

1:=> (define (combination n s lst proc-to-apply)
  (cond ((equal? n 0)   (proc-to-apply  lst))  ;;Final
        ((equal? s 1)   (proc-to-apply  (append (make-list n 0) lst))) ;;Final
        ((equal? n s)       (proc-to-apply  (append (make-list n 1) lst))) 
;;Final
        (else           (begin
                          (combination (- n 1) (- s 1)  (cons 1 lst) 
proc-to-apply)
                          (combination (- n 1) s (cons 0 lst) proc-to-apply)))))

1:=> (combination  4 2 '() print)
(0 0 0 1)
(0 0 1 0)
(1 1 0 0)
(1 1 0 0)



1:=> (define (combination_seg-fault n s lst proc-to-apply)
  (cond ((equal? n #f)   (proc-to-apply  lst))  ;;Final
        ((equal? s #t)   (proc-to-apply  (append (make-list n #f) lst))) ;;Final
        ((equal? n s)       (proc-to-apply  (append (make-list n #t) lst))) 
;;Final
        (else           (begin
                          (combination_seg-fault (- n 1) (- s 1)  (cons #t lst) 
proc-to-apply)
                          (combination_seg-fault (- n 1) s (cons #f lst) 
proc-to-apply)))))


= >(combination_seg-fault 4 2 '() print)
*** ERROR:bigloo:
`segmentation violation' exception -- raised


Since it is the same code, just dealing with other values I was expecting to get
(#f #f #f #t)
(#f #f #t #f)
(#t #t #f #f)
(#t #t #f #f)

Note that I get the same behavior in compiled and interpreted mode.

Best regards,
Pierre-Francois



Reply via email to