Permalink
Cannot retrieve contributors at this time
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?
CSE1729-Mimir-Testing-Scripts/utilities.scm
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (39 sloc)
1.29 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |