PasteRack.org
Paste # 3861
2019-04-25 14:30:11

Fork as a new paste.

Paste viewed 169 times.


Embed:

  1. #lang racket
  2.  
  3. ; a card has a suit and a rank
  4. ; suit = 'hearts | 'diamonds | 'spades | 'clubs
  5. ; rank = 2-10 | 'jack | 'queen | 'king | 'ace
  6. (struct card (suit rank) #:transparent)
  7.  
  8. (define aceOfSpades (card 'spades 'ace))
  9. (define threeOfHearts (card 'hearts 3))
  10. (define alsoThreeOfHearts (card 'hearts 3))
  11. (define jackOfDiamonds (card 'diamonds 'jack))
  12. (define sevenOfClubs (card 'clubs 7))
  13.  
  14. ;
  15. ; 1. Rearrange the lines of the cardColor function to work correctly
  16. ; the function cardColor takes a card as an argument and returns its color (spades and clubs are black; diamonds and hearts are red)
  17. ;
  18.  
  19. ;(define (cardColor c)
  20. ;          (eq? (card-suit c) 'diamonds))
  21. ;  (if (or (eq? (card-suit c) 'hearts)
  22. ;      'black))
  23. ;      'red
  24.  
  25. (define
  26.     (if (or (eq? (card-suit c) 'hearts)
  27.         (eq? (card-suit c) 'diamonds))
  28.         'black))
  29.         'red
  30.  
  31.  
  32.  
  33. (cardColor aceOfSpades)
  34. (cardColor threeOfHearts)
  35. (cardColor jackOfDiamonds)
  36. (cardColor sevenOfClubs)

=>