Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.10 KB | None | 0 0
  1. ;; Ćwiczenie 3.
  2.  
  3. (define (more e)
  4.   (define (iter acc expr)
  5.     (match expr
  6.       [(op s l r) (match s
  7.                     ['+ (iter (iter (inc acc) l) r)]
  8.                     ['* (iter (iter (dec acc) l) r)])]
  9.       [_ acc]))
  10.   (let ([res (iter 0 e)])
  11.     (cond [(= res 0) "="]
  12.           [(> res 0) "+"]
  13.           [else "*"])))
  14.  
  15. ;; Ćwiczenie 4.
  16.  
  17. (struct text (title author chapter-sequence) #:transparent)
  18. (struct chapter (title element-sequence)     #:transparent)
  19. (struct subchapter (title element-sequence)  #:transparent)
  20. (struct paragraph (string-sequence)          #:transparent)
  21.  
  22. (define (istext? book)
  23.   (match book
  24.     [(text t a c-s)     (and (string? t)
  25.                              (string? a)
  26.                              (andmap (lambda (x) (istext? x)) c-s))]
  27.     [(chapter t e-s)    (and (string? t)
  28.                              (andmap (lambda (x) (istext? x)) e-s))]
  29.     [(subchapter t e-s) (and (string? t)
  30.                              (andmap (lambda (x) (istext? x)) e-s))]
  31.     [(paragraph s-s)    (andmap (lambda (x) (string? x)) s-s)]
  32.     [_                 false]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement