Advertisement
timothy235

sicp-2-3-1-quotation

Feb 23rd, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.92 KB | None | 0 0
  1. #lang racket
  2.  
  3. ;;;;;;;;;;
  4. ;; 2.53 ;;
  5. ;;;;;;;;;;
  6.  
  7. (list 'a 'b 'c)
  8. ;; '(a b c)
  9. (list (list 'george))
  10. ;; '((george))
  11. (cdr '((x1 x2) (y1 y2)))
  12. ;; '((y1 y2))
  13. (cadr '((x1 x2) (y1 y2)))
  14. ;; '(y1 y2)
  15. (pair? (car '(a short list)))
  16. ;; #f
  17. (memq 'red '((red shoes) (blue socks)))
  18. ;; #f
  19. (memq 'red '(red shoes blue socks))
  20. ;; '(red shoes blue socks)
  21.  
  22. ;;;;;;;;;;
  23. ;; 2.54 ;;
  24. ;;;;;;;;;;
  25.  
  26. (define (my-equal? x y)
  27.   (cond [(and (symbol? x) (symbol? y)) (eq? x y)]
  28.         [(and (list? x) (list? y))
  29.          (or (and (empty? x) (empty? y))
  30.              (and (eq? (first x) (first y))
  31.                   (my-equal? (rest x) (rest y))))]
  32.         [else #f]))
  33.  
  34. (my-equal? '(this is a list) '(this is a list))
  35. ;; #t
  36. (my-equal? '(this is a list) '(this (is a) list))
  37. ;; #f
  38.  
  39. ;;;;;;;;;;
  40. ;; 2.55 ;;
  41. ;;;;;;;;;;
  42.  
  43. (car ''abracadabra)
  44. ;; 'quote
  45.  
  46. ;; ''abracadabra is the same as '(quote abracadabra) whose car is the symbol 'quote
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement