fork(1) download
  1. #lang racket
  2. ;; Total Order ADT used by Ordered Set ADT
  3.  
  4. ;; Must provide:
  5. ;; a membership predicate
  6. ;; a total order
  7. ;; min and max functions with identities
  8. ;; user-defined associative operator and identity
  9. ;;
  10. ;; any other operations required by the user
  11. ;; e.g. to-hide and to-unhide
  12.  
  13. (provide to? to< to<= to> to> to>= to= to!= to-min to-min-ident
  14. to-max to-max-ident to-op to-op-ident to-hide to-unhide)
  15.  
  16. ;; For this example, we use a number hidden in a struct
  17.  
  18. (define-struct to-rep (hidden ) #:transparent)
  19. (define (to-unhide x) (to-rep-hidden x))
  20. (define (to-hide x) (make-to-rep x))
  21.  
  22. ;; membership predicate
  23.  
  24. (define (to? x) (and (to-rep? x) (or (string? (to-rep-hidden x))(number? (to-rep-hidden x)))))
  25.  
  26. ;; defining relation must be total, reflexive, transitive
  27.  
  28.  
  29.  
  30. (define (to<= a b)
  31. (cond
  32. [(equal? (to-rep-hidden a) "?") #t]
  33. [(equal? (to-rep-hidden b) "+inf.0") #t]
  34. [(equal? (to-rep-hidden a) "+inf.0") #f]
  35. [(equal? (to-rep-hidden b) "?") #f]
  36. [(and (number? (string->number (to-rep-hidden a))) (number? (string->number (to-rep-hidden b))))
  37. (<= (string->number (to-rep-hidden a)) (string->number (to-rep-hidden b)))]
  38. [else (string<=? (to-rep-hidden a) (to-rep-hidden b))]))
  39.  
  40. ;; derived relations
  41. (define (to> a b) (not (to<= a b)))
  42. (define (to= a b) (and (to<= a b) (to<= b a)))
  43. (define (to>= a b) (to<= b a))
  44. (define (to< a b) (to> b a))
  45. (define (to!= a b) (not (to= a b)))
  46.  
  47. ;; min/max functions and identities
  48.  
  49. (define (to-min a b) (if (to< a b) a b))
  50. (define to-min-ident (make-to-rep "+inf.0"))
  51.  
  52. (define (to-max a b) (if (to< a b) b a))
  53. (define to-max-ident (make-to-rep "?"))
  54.  
  55. ;; user-defined associative operator and identity
  56.  
  57. ;; for this example we just add the secret numbers
  58.  
  59. (define (to-op a b)
  60. (cond
  61. [(and (string? a) (string? b)) (to-hide (string-append (to-rep-hidden a) (to-rep-hidden b)))]
  62. [else (to-hide (string-append (to-rep-hidden a) (to-rep-hidden b)))]))
  63.  
  64. (define to-op-ident (to-hide ""))
  65.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:2: error: invalid preprocessing directive #lang
prog.cpp:18: error: stray ‘#’ in program
prog.cpp:32: error: stray ‘#’ in program
prog.cpp:33: error: stray ‘#’ in program
prog.cpp:34: error: stray ‘#’ in program
prog.cpp:35: error: stray ‘#’ in program
prog.cpp:2: error: ‘Total’ does not name a type
prog.cpp:4: error: ‘Must’ does not name a type
prog.cpp:5: error: ‘a’ does not name a type
prog.cpp:6: error: ‘a’ does not name a type
prog.cpp:7: error: expected constructor, destructor, or type conversion before ‘&&’ token
prog.cpp:8: error: expected constructor, destructor, or type conversion before ‘-’ token
prog.cpp:10: error: ‘any’ does not name a type
prog.cpp:11: error: expected constructor, destructor, or type conversion before ‘.’ token
prog.cpp:16: error: expected constructor, destructor, or type conversion before ‘this’
prog.cpp:22: error: ‘membership’ does not name a type
prog.cpp:26: error: ‘defining’ does not name a type
prog.cpp:40: error: ‘derived’ does not name a type
prog.cpp:47: error: expected constructor, destructor, or type conversion before ‘/’ token
prog.cpp:55: error: expected constructor, destructor, or type conversion before ‘-’ token
prog.cpp:57: error: expected unqualified-id before ‘for’
stdout

Standard output is empty