Guest User

Untitled

a guest
Jan 15th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.86 KB | None | 0 0
  1. ;; ** collect-prop-variables **
  2. ;; This function collects the variables of a logical formula from a given list
  3. (define collect-prop-variables
  4.   (lambda (l)
  5.     (cond
  6.       ;; If the list is null, we've gone through everything so return an empty list
  7.       ((null? l) `())
  8.       ;; If the first item in the list is an atom...
  9.       ((atom? (car l))
  10.        (cond
  11.      ;; If it's not a logical operator, keep it and keep going through the rest of the list
  12.      ((eq? (operator? (car l)) #f) (flatten (cons (car l) (collect-prop-variables (cdr l)))))
  13.      ;; Otherwise, ignore it and keep going through the list
  14.      (else (collect-prop-variables (cdr l)))
  15.        )
  16.       )
  17.       ;; If the first item is a list recurse through it and through the rest of the list
  18.       (else (remove-duplicates (flatten (cons (collect-prop-variables (car l)) (collect-prop-variables (cdr l)))))))))
Add Comment
Please, Sign In to add comment