This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-19
Channels
- # announcements (1)
- # babashka (26)
- # beginners (42)
- # calva (3)
- # cider (5)
- # cljs-dev (7)
- # cljsjs (1)
- # cljsrn (13)
- # clojure (95)
- # clojure-europe (12)
- # clojure-germany (3)
- # clojure-italy (12)
- # clojure-nl (1)
- # clojure-spec (16)
- # clojure-uk (25)
- # clojurescript (13)
- # clojureverse-ops (5)
- # community-development (1)
- # conjure (8)
- # cryogen (3)
- # datomic (5)
- # deps-new (7)
- # exercism (1)
- # fulcro (34)
- # honeysql (9)
- # hyperfiddle (3)
- # instaparse (2)
- # introduce-yourself (2)
- # jobs (6)
- # kaocha (1)
- # lambdaisland (1)
- # lsp (47)
- # malli (3)
- # membrane (38)
- # off-topic (9)
- # polylith (36)
- # reitit (7)
- # releases (1)
- # remote-jobs (2)
- # shadow-cljs (11)
- # spacemacs (7)
- # sql (7)
- # tools-deps (19)
How would I go about writing a spec for a data structure that detects (disallows) cycles?
Context: As a fun learning project I’ve been writing a state machine for a lexer, as a map from states->inputs->[outputs/->states] (that last part is the transition).
Now as is typical for these, some of the transitions are similar on different states (here because of lexemes). Instead of composing the map programmatically I thought I invent an additional behaviour and add a :with
key on the transition, to say that the output is combined with the output of another transition. This way the state machine is fully described as a plain data-structure. :with
merely points to
The terrible thing here is that I introduced the possibility for recursion/infinite loops. So my intuition is that I can write a spec that detects cycles, but I cannot really wrap my head around it. Is this possible?
My context is just an example, maybe the design is wrong, but I would be generally interested in applying spec this way and how one would go about it.
I think I would probably not write such a spec
but a spec can be any predicate function
so if you can write a function (no-cycles? data-structure), then that's a valid spec
right I was getting stuck somehow in trying to make the spec both check the structure and detect the cycle at the same time
(s/and ::structure no-cycles?)
I just don't think you're getting any value out of using spec to write that :)
spec's sweet spot is describing information structures (maps of attributes) or syntactic structures (sequential regex type things). the more generic or abstract you get from that, the less value you get
I get what you’re saying. But say I used spec during development time with instrumentation I would still get value from this right?
hard for me to say
keep in mind that slow specs can really slow down execution. cycle checking sounds slow. :)
would you be better off preventing a graph with a cycle from being created in the first place?