pangloss / pure-conditioning

A simple, fast, purely functional condition / restart system for Clojure.
Apache License 2.0
53 stars 0 forks source link

result! and retry! do not work as qualified imports #2

Open yuhan0 opened 2 months ago

yuhan0 commented 2 months ago

I've always been interested to explore CL-style condition systems, thanks for bringing some form of it over to Clojure :)

Here's a repro (adapted from the readme)

(require '[pure-conditioning :as pc])

(defn do-something [x] x)

(manage [:x (pc/result! "nevermind")]
  (do-something 3))
;; => Execution error (ExceptionInfo) at pure-conditioning.core/result! (core.clj:277).
;;    result! must be used within manage, retryable or retryable-fn* blocks.

It appears that the library macros (manage, retryable) are only able to work when given unqualified symbols: https://github.com/pangloss/pure-conditioning/blob/66061cb5075ffaf4f488d8bb7957d62b12d7a62e/src/pure_conditioning/core.clj#L192

Figuring this out was pretty confusing, as there are actual result! and retry! vars defined in the pure-conditioning.core namespace (I assume for dev tooling affordances?) But it turns out that the library doesn't care whether they exist or were imported in the current namespace, essentially treating the bare symbols as anaphors.

Not that unhygenic DSLs are a bad thing, but perhaps this fact should be made more explicit in the docstrings / Readme? From a syntax perspective I guess there would be less of a surprise if they were given more DSL-y names like !retry or $retry.. Going the pseudo-hygenic route might be possible too by somehow resolving the vars using &env at macroexpansion time.

yuhan0 commented 2 months ago

Side note: the Clojars link in the readme points to an outdated version of the library with the conditions namespace, also used by the Nextjournal tutorial.