timothy235 icon

sicp-2-3-1-quotation

timothy235 | PRO | 12/19/24 01:18:51 AM UTC (Edited) | 0 ⭐ | 370 👁️ | Never ⏰ | []
Racket |

920 B

|

None

|

0 👍

/

0 👎

#lang racket
 
;;;;;;;;;;
;; 2.53 ;;
;;;;;;;;;;
 
(list 'a 'b 'c)
;; '(a b c)
(list (list 'george))
;; '((george))
(cdr '((x1 x2) (y1 y2)))
;; '((y1 y2))
(cadr '((x1 x2) (y1 y2)))
;; '(y1 y2)
(pair? (car '(a short list)))
;; #f
(memq 'red '((red shoes) (blue socks)))
;; #f
(memq 'red '(red shoes blue socks))
;; '(red shoes blue socks)
 
;;;;;;;;;;
;; 2.54 ;;
;;;;;;;;;;
 
(define (my-equal? x y)
  (cond [(and (symbol? x) (symbol? y)) (eq? x y)]
        [(and (list? x) (list? y))
         (or (and (empty? x) (empty? y))
             (and (eq? (first x) (first y))
                  (my-equal? (rest x) (rest y))))]
        [else #f]))
 
(my-equal? '(this is a list) '(this is a list))
;; #t
(my-equal? '(this is a list) '(this (is a) list))
;; #f
 
;;;;;;;;;;
;; 2.55 ;;
;;;;;;;;;;
 
(car ''abracadabra)
;; 'quote
 
;; ''abracadabra is the same as '(quote abracadabra) whose car is the symbol 'quote

Comments