1. ; def MyException:
  2. ;   def message() = "".
  3. (def MyException {
  4.   :message (fn [return, error] #(return ""))
  5.   })
  6.  
  7.  
  8. ; def consolePuts(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 (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(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. ;     return();
  52. (defn fn_loop [n, out, return, error]
  53.   (strictly-ascending [n, 7]
  54.       (fn []
  55.         (console-puts out "Hello World!"
  56.             #(fn_loop (+ 1 n) out return error)
  57.             (fn [e]
  58.               ((:message e)
  59.                   (fn [msg]
  60.                     (println msg)   ;log error
  61.                     return)
  62.                   error))))
  63.       return))
  64.  
  65.  
  66. ; def Start:
  67. ;   struct instance
  68. ;   Start() =
  69. ;     loop(0, __Clojure__ System/out) ->
  70. ;     return( () ).
  71. (def Start {
  72.   :instance nil
  73.   :new (fn [self, return, error] (fn_loop 0 System/out #(return {}) error))
  74.   })
  75.  
  76.  
  77. ; Start() -> newInstance
  78. ;   new Start(instance: newInstance) -> Start
  79. ;   0;
  80. ; | e
  81. ;   e.message -> msg
  82. ;     __Clojure__ (throw (new RuntimeException msg))
  83. ;   |   #ignore argument
  84. ;     __Clojure__ (throw (new IllegalStateException "Error getting exception message!"));;
  85. (trampoline
  86.   ((:new Start)
  87.     Start
  88.     (fn [newInstance] (assoc Start :instance newInstance) 0)
  89.     (fn [e]
  90.       ((:message e)
  91.           (fn [msg] (throw (new RuntimeException msg)))
  92.           (fn [_] (throw (new IllegalStateException "Error getting exception message!")))))))