daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest May 27th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (define first car)
  2. (define second cadr)
  3. (define rest cdr)
  4. (define (third list) (car (cddr list)))
  5. (define fourth cadddr)
  6.  
  7. (define initmap '())
  8.  
  9. (define test
  10.   (list (list 'a 1) (list 'b 3))
  11.   )
  12.  
  13. (define (lookup map key default)
  14.   (cond
  15.     ((eq? '() map) default)
  16.     ((eq? (first (first map)) key) (second (first map)))
  17.     (#t (lookup (rest map) key default))
  18.     )
  19.   )
  20.  
  21. (define (add map key val)
  22.   (cons (list key val)  (delete map key))
  23.   )
  24.  
  25. (define (delete map key)
  26.   (delete-help map key '())
  27.   )
  28.  
  29.  
  30. (define (delete-help map key before)
  31.   (cond
  32.     ((eq? map '()) before)
  33.     ((eq? (first (first map)) key) (append before (rest map)))  ;key to delete found
  34.     (#t (delete-help (rest map) key (cons (first map) before))) ;this is not meant to be deleted
  35.     )
  36.   )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top