|
21 | 21 | [clojure.string :as string] |
22 | 22 | [clojure.core :as core] |
23 | 23 | [active.clojure.macro :refer [if-cljs]]) |
24 | | - :cljs (:require [active.clojure.condition :refer-macros [define-condition-type throw-condition]] |
25 | | - [cljs.core :as core])) |
| 24 | + :cljs (:require-macros [active.clojure.condition :refer [define-condition-type throw-condition]] |
| 25 | + [cljs.core :as core])) |
26 | 26 | #?(:clj (:import clojure.lang.ExceptionInfo))) |
27 | 27 |
|
28 | 28 | (defn condition? |
|
227 | 227 | (nth (:arguments comp) i) |
228 | 228 | (throw (new Error (str cond " is not a condition of type " type))))))) |
229 | 229 |
|
230 | | -#?(:clj |
231 | 230 | (defmacro define-condition-type |
232 | 231 | " (define-condition-type <condition-type> |
233 | 232 | <supertype> |
|
278 | 277 | m |
279 | 278 | (assoc m :arglists `'(~arglist))))))) |
280 | 279 | name-doc (fn [field] |
281 | | - (if-let [doc (:doc (meta field))] |
282 | | - (str " (" doc ")") |
283 | | - "")) |
| 280 | + (if-let [doc (:doc (meta field))] |
| 281 | + (str " (" doc ")") |
| 282 | + "")) |
284 | 283 | reference (fn [name] |
285 | 284 | (str "[[" (ns-name *ns*) "/" name "]]"))] |
286 | 285 | `(do |
|
311 | 310 | (str "Access the `" ?field-name "`" (name-doc ?field-name) |
312 | 311 | " field from a " (reference ?condition-type) " condition.")) |
313 | 312 | (condition-accessor ~?condition-type '~?field-name))) |
314 | | - ?field-pairs)))))) |
| 313 | + ?field-pairs))))) |
315 | 314 |
|
316 | 315 | ; These standard condition types correspond directly to R6RS Scheme |
317 | 316 |
|
|
374 | 373 | (and (not-empty irritants) (make-irritants-condition irritants)) |
375 | 374 | conditions))) |
376 | 375 |
|
377 | | -#?(:clj |
378 | 376 | (defmacro throw-condition |
379 | 377 | "Throw a condition. |
380 | 378 |
|
381 | 379 | For internal use." |
382 | 380 | [?base ?who ?message ?irritants] |
383 | | - `(throw (build-condition ~?base ~?who ~?message ~?irritants)))) |
| 381 | + `(throw (build-condition ~?base ~?who ~?message ~?irritants))) |
384 | 382 |
|
385 | 383 | (defn error |
386 | 384 | "Throw an exception that signals that an error has occurred. |
|
410 | 408 | [who message & irritants] |
411 | 409 | (throw-condition (make-assertion-violation) who message irritants)) |
412 | 410 |
|
413 | | -#?(:clj |
414 | 411 | (defmacro assert |
415 | 412 | "Evaluates expr and throws an exception if it does not evaluate to |
416 | 413 | logical true." |
417 | 414 | ([x] |
418 | | - (when *assert* |
419 | | - (let [?ns (str *ns*) |
420 | | - ?file (let [f *file*] (when (not= f "NO_SOURCE_PATH") f)) |
421 | | - ;; TODO Waiting on http://dev.clojure.org/jira/browse/CLJ-865: |
422 | | - ?line (:line (meta &form))] |
423 | | - `(when-not ~x |
424 | | - (assertion-violation (if-cljs |
| 415 | + (when *assert* |
| 416 | + (let [?ns (str *ns*) |
| 417 | + ?file (let [f *file*] (when (not= f "NO_SOURCE_PATH") f)) |
| 418 | + ;; TODO Waiting on http://dev.clojure.org/jira/browse/CLJ-865: |
| 419 | + ?line (:line (meta &form))] |
| 420 | + `(when-not ~x |
| 421 | + (assertion-violation (if-cljs |
425 | 422 | nil |
426 | 423 | (stack-trace-who (.getStackTrace (Thread/currentThread)))) |
427 | | - (str "Assertion failed") |
428 | | - (make-location-condition '~?ns ~?file ~?line) |
429 | | - '~x))))) |
| 424 | + (str "Assertion failed") |
| 425 | + (make-location-condition '~?ns ~?file ~?line) |
| 426 | + '~x))))) |
430 | 427 | ([x message] |
431 | | - (when *assert* |
432 | | - (let [?ns (str *ns*) |
433 | | - ?file (let [f *file*] (when (not= f "NO_SOURCE_PATH") f)) |
434 | | - ;; TODO Waiting on http://dev.clojure.org/jira/browse/CLJ-865: |
435 | | - ?line (:line (meta &form))] |
436 | | - `(when-not ~x |
437 | | - (assertion-violation (if-cljs |
438 | | - nil |
439 | | - (stack-trace-who (.getStackTrace (Thread/currentThread)))) |
440 | | - (str "Assert failed: " ~message) |
441 | | - (make-location-condition '~?ns ~?file ~?line) |
442 | | - '~x))))))) |
| 428 | + (when *assert* |
| 429 | + (let [?ns (str *ns*) |
| 430 | + ?file (let [f *file*] (when (not= f "NO_SOURCE_PATH") f)) |
| 431 | + ;; TODO Waiting on http://dev.clojure.org/jira/browse/CLJ-865: |
| 432 | + ?line (:line (meta &form))] |
| 433 | + `(when-not ~x |
| 434 | + (assertion-violation (if-cljs |
| 435 | + nil |
| 436 | + (stack-trace-who (.getStackTrace (Thread/currentThread)))) |
| 437 | + (str "Assert failed: " ~message) |
| 438 | + (make-location-condition '~?ns ~?file ~?line) |
| 439 | + '~x)))))) |
443 | 440 |
|
444 | 441 |
|
445 | | -#?(:clj |
446 | 442 | (defmacro condition |
447 | 443 | [?base ?message & ?irritants] |
448 | 444 | `(combine-conditions ~?base |
449 | 445 | (if-cljs |
450 | | - nil |
451 | | - (make-who-condition (stack-trace-who (.getStackTrace (Thread/currentThread))))) |
| 446 | + nil |
| 447 | + (make-who-condition (stack-trace-who (.getStackTrace (Thread/currentThread))))) |
452 | 448 | (make-message-condition ~?message) |
453 | | - (make-irritants-condition [~@?irritants])))) |
| 449 | + (make-irritants-condition [~@?irritants]))) |
454 | 450 |
|
455 | | -#?(:clj |
456 | 451 | (defmacro raise |
457 | 452 | [?base ?message & ?irritants] |
458 | | - `(throw (condition ~?base ~?message ~@?irritants)))) |
| 453 | + `(throw (condition ~?base ~?message ~@?irritants))) |
459 | 454 |
|
460 | 455 | #?(:cljs |
461 | 456 | (def Throwable js/Object)) |
462 | 457 |
|
463 | | -#?(:clj |
464 | 458 | (defmacro guard |
465 | 459 | "Guard against specific conditions (with an optional default case), similar |
466 | 460 | to `catch`. |
|
481 | 475 | (let [?id (first ?handling)] |
482 | 476 | `(try |
483 | 477 | ~@?body |
484 | | - ; If Throwable is not a symbol it means java.lang.Throwable which does not work in ClojureScript. |
| 478 | + ; If Throwable is not a symbol it means java.lang.Throwable which does not work in ClojureScript. |
485 | 479 | (catch ~'Throwable ~?id |
486 | 480 | (cond |
487 | | - ~@(rest ?handling) |
488 | | - ~@(if (= :else (last (butlast ?handling))) |
489 | | - `() |
490 | | - `(:else (throw ~?id))))))))) |
| 481 | + ~@(rest ?handling) |
| 482 | + ~@(if (= :else (last (butlast ?handling))) |
| 483 | + `() |
| 484 | + `(:else (throw ~?id)))))))) |
491 | 485 |
|
492 | 486 | (defn delete-first |
493 | 487 | [pred? l] |
|
0 commit comments