unrepl

discussing specification of an edn-based repl and its implementations.
cgrand 2017-11-13T11:03:44.000084Z

Has anybody been working on a spec-guided completion?

cgrand 2017-11-13T11:11:41.000234Z

what I mean: you can compute the firsts set of a regular expression and you can also compute its derivative towards a prefix

cgrand 2017-11-13T11:14:04.000304Z

(defn firsts 
  ([re] (firsts re (s/form re)))
  ([re form]
    (case (::s/op re)
      ::s/pcat (if-let [[p & ps] (:ps re)]
                 (into (firsts p (first (:forms re)))
                   (when (s/valid? p nil)
                     (firsts (-> re (assoc :ps (vec ps))
                               (update :ks (comp vec next))
                               (update :forms (comp vec next)))
                       ’???)))
                 #{})
      ::s/alt (into #{} (mapcat firsts (:ps re) (:forms re)))
      ::s/accept #{}
      #{form})))

=> (firsts (s/cat :name symbol? :meta map?))
#{clojure.core/symbol?}

=> (firsts (s/cat :name (s/? symbol?) :meta map?))
#{clojure.core/symbol? clojure.core/map?}

cgrand 2017-11-13T11:15:31.000106Z

^^ rough poc

pesterhazy 2017-11-13T13:28:54.000094Z

what is this sorcery

cgrand 2017-11-13T14:24:42.000019Z

@pesterhazy given a regular expression you can know what are the valid inputs for the first transition (“firsts set”)

cgrand 2017-11-13T14:25:25.000527Z

given a regular expression and a prefix you can compute the remaining regular expression after having consumed prefix

cgrand 2017-11-13T14:26:24.000439Z

together they allow to offer completion on macros that are specced

cgrand 2017-11-13T14:29:20.000130Z

you can have the following interactions (pipe being the caret)

(if-l| 
(if-let [|] ; autompletion automatically creates the vector because it’s the only valid input, a hint may say that a binding is epxected
...

cgrand 2017-11-13T20:02:42.000499Z

@pesterhazy anything against the use of spec in unravel?

pesterhazy 2017-11-13T21:25:08.000020Z

Might slow lumo down significantly

anmonteiro 2017-11-13T21:25:50.000634Z

why?

anmonteiro 2017-11-13T21:25:57.000012Z

spec is precompiled in Lumo

anmonteiro 2017-11-13T21:26:00.000302Z

AOTed to JS

cgrand 2017-11-13T21:41:11.000006Z

so I can use it for cmdline args parsing?

ghadi 2017-11-13T22:07:41.000563Z

do it

ghadi 2017-11-16T14:07:04.000249Z

Beautiful

ghadi 2017-11-13T22:07:53.000024Z

(I'm here in the peanut gallery)

cgrand 2017-11-13T22:37:57.000026Z

@ghadi wouldn’t spec derivatives be your kind of thing?

ghadi 2017-11-13T22:38:31.000427Z

i'm more of a PEG kinda guy

ghadi 2017-11-13T22:39:00.000066Z

but yeah, 100% behind what you said

ghadi 2017-11-13T22:39:42.000262Z

this is funny to me -- it's like the dual to your original 2010 conj talk on partial parsing

ghadi 2017-11-13T22:39:51.000291Z

except it's not parsing, it's partial generation