Hello, Pierre-Francois, In your second example, you are testing equality between numeric values and the booleans #t and #f. Neither of these equality checks will every return true (the only value equal to #t is #t, likewise for #f; see r5rs ), and hence your function loops until it runs out of stack space and throws a seg-fault. Try the following: (define (combination_seg-fault 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 #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))))) Best Regards,Joe
| | | | The R5RS standard - The CHICKEN Scheme wiki | | | On Fri, Mar 23, 2018 at 9:07 AM, Ollagnon, Pierre-Francois<[email protected]> wrote: 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
