Question

I am still new to Scheme and trying to solve the magic squares via call/cc and the amb operator. Currently, it is printing out:

1 1 1 31 Row 1
16 16 1 1 Row 2
16 1 16 1 Row 3
1 16 16 1 Row 4 

I can't figure out why it is only using those numbers. Is it my distinct? procedure? Here is my code:

;; check whether an element of one given list is a member of any 
;; of the other given lists
(define distinct?
  (lambda (o l)
    (if (null? l)
    #t
    (if (= (car l) o)
            '()
            (distinct? o (cdr l))))))
Was it helpful?

Solution

I noticed that your 'distinct?' procedure never returns a false value. The problem that you are running in to is that your asserts always pass. This can be seen when you remove the calls of assert altogether, and the result is unchanged. Within your nested if check, you should replace your '() with the boolean false: #f

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top