;;; ================================ ;;; CMPU-145, Spring 2013 ;;; Code from class ;;; Feb. 11, 2013 ;;; ================================ (load "asmt-helper.txt") (header "Code from class" "Feb. 11, 2013") ;;; REFLEXIVE? ;;;-------------------------- ;;; INPUTS: RELN, a list of lists representing a relation ;;; LISTA, a list ;;; OUTPUT: #t (or something that counts as true) if RELN is reflexive over LISTA ;;; #f otherwise. (define reflexive? (lambda (reln lista) (cond ;; Base Case: ((null? lista) #t) ;; Recursive Case: ((member (list (first lista) (first lista)) reln) (reflexive? reln (rest lista))) ;; Base Case 2: We found a counter-example (else (printf "Counter-example: ~A~%" (list (first lista) (first lista))) #f)))) (tester '(reflexive? '((1 2) (1 1) (2 1) (2 2) (1 3) (3 1)) '(1 2 3))) ;;; DOMAIN ;;; -------------------------- ;;; INPUT: RELN ;;; OUTPUT: Domain of the RELN (define domain (lambda (reln) (map first reln))) ;;; Still need to remove duplicates. (tester '(domain '((1 2) (2 1) (2 3) (2 4) (1 3) (3 3)))