1. ; def MyException:
  2. ;   def message() = "".
  3. (def MyException {
  4.   :message (fn [return, error] #(return ""))
  5.   })
  6.  
  7.  
  8. ; def consolePuts(def out, text) =
  9. ;   __Clojure__ (.println out text) ->
  10. ;   __Clojure__ (.checkError out) -> x
  11. ;   if (x)
  12. ;     throw(new MyException:
  13. ;       def ^message() = "Unknown I/O error".
  14. ;     )
  15. ;   else
  16. ;     return()
  17. (defn console-puts [out, text, return, error]
  18.   (let
  19.     [_ (.println out text) 
  20.     x (.checkError out)]
  21.     (if x
  22.       (error
  23.         (assoc MyException :message
  24.           (fn [return, error] #(return "Unknown I/O error")))))
  25.       return))
  26.  
  27.  
  28. ; def strictlyAscending = fun (def numbers) => yes(), no():
  29. ;   __Clojure__ (apply < numbers) -> x
  30. ;   if (x)
  31. ;     yes()
  32. ;   else
  33. ;     no()
  34. ; .
  35. (defn strictly-ascending [numbers, yes, no]
  36.   (let [x (apply < numbers)]
  37.   (if x
  38.     yes
  39.     no)))
  40.  
  41.  
  42. ; def loop(def n, out) =
  43. ;   strictlyAscending([n, 7]) ->
  44. ;     (consolePuts(out, "Hello World!") ->
  45. ;       $loop(++n, out)
  46. ;     | e
  47. ;       e.message -> msg
  48. ;       __Clojure__ (println msg) ->
  49. ;       return() #implicit re-throw
  50. ;     )
  51. ;   |
  52. ;     return()
  53. (defn fn_loop [n, out, return, error]
  54.   (strictly-ascending [n, 7]
  55.       (fn []
  56.         (console-puts out "Hello World!"
  57.             #(fn_loop (+ 1 n) out return error)
  58.             (fn [e]
  59.               ((:message e)
  60.                   (fn [msg]
  61.                     (println msg)   ;log error
  62.                     return)
  63.                   error))))
  64.       return))
  65.  
  66.  
  67. ; def Start:
  68. ;   struct instance
  69. ;   make start() =
  70. ;     loop(0, __Clojure__ System/out) ->
  71. ;     return(struct)
  72. ; .
  73. (def Start {
  74.   :instance nil
  75.   :new (fn [self, return, error] (fn_loop 0 System/out #(return {}) error))
  76.   })
  77.  
  78.  
  79. ; Start() -> newInstance
  80. ; new Start(instance: newInstance) -> Start
  81. ; 0
  82. ; | e
  83. ;   (e.message -> msg
  84. ;     __Clojure__ (throw (new RuntimeException msg))
  85. ;   |   #ignore argument
  86. ;     __Clojure__ (throw (new IllegalStateException "Error getting exception message!"));;
  87. ;   )
  88. (trampoline
  89.   ((:new Start)
  90.     Start
  91.     (fn [newInstance] (assoc Start :instance newInstance) 0)
  92.     (fn [e]
  93.       ((:message e)
  94.           (fn [msg] (throw (new RuntimeException msg)))
  95.           (fn [_] (throw (new IllegalStateException "Error getting exception message!")))))))