Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
(define (ref-bool-equal? a b)
; tests whether a and b have same truth value
; double negation forces true thing to be #t
; useful for boolean functions
(not (not (or (and a b)(and (not a)(not b))))))
(define (ref-approx-=? a b tol)
; tests whether a is within tol of b
; a, b, and tol are numbers
; useful for floats
(< (abs (- a b)) tol))
(define (ref-general-equal? x y) ;; works for numbers, strings, symbols, lists
(cond ((eq? x y) #t)
((and (number? x)(number? y))
(= x y))
((and (string? x)(string? y))
(string=? x y))
((and (pair? x)(pair? y))
(and (ref-general-equal? (car x)(car y))
(ref-general-equal? (cdr x)(cdr y))))
(else
#f)))
(define (ref-general-member? x y)
(cond ((null? y) #f)
((ref-general-equal? x (car y))
#t)
(else
(ref-general-member? x (cdr y)))))
(define (ref-remove-one x lst)
(cond ((null? lst) lst)
((ref-general-equal? x (car lst))
(cdr lst))
(else
(cons (car lst)(ref-remove-one x (cdr lst))))))
(define (ref-permutation? x y)
(cond ((null? x)(null? y))
((null? y) #f)
((ref-general-member? (car x) y)
(ref-permutation? (cdr x)(ref-remove-one (car x) y)))
(else #f)))