This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-08
Channels
- # announcements (6)
- # beginners (100)
- # calva (17)
- # cljs-dev (31)
- # cljsrn (2)
- # clojars (3)
- # clojure (137)
- # clojure-australia (1)
- # clojure-europe (41)
- # clojure-gamedev (3)
- # clojure-italy (1)
- # clojure-nl (3)
- # clojure-poland (16)
- # clojure-serbia (7)
- # clojure-taiwan (1)
- # clojure-uk (10)
- # clojurescript (10)
- # cursive (25)
- # data-oriented-programming (4)
- # datomic (26)
- # fulcro (39)
- # graalvm (6)
- # jobs (2)
- # jobs-discuss (2)
- # kaocha (19)
- # klipse (1)
- # leiningen (3)
- # lsp (18)
- # malli (21)
- # meander (26)
- # off-topic (29)
- # pathom (39)
- # polylith (3)
- # practicalli (2)
- # re-frame (11)
- # reitit (8)
- # rewrite-clj (7)
- # sci (11)
- # shadow-cljs (44)
- # sql (8)
- # tools-deps (32)
- # xtdb (3)
user=> (time (m/validate [:cat [:+ [:+ [:enum 0]]] [:enum 1]] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) )
"Elapsed time: 0.582137 msecs"
true
user=> (time (s/valid? (s/cat :zeroes (s/+ (s/+ #{0})) :one #{1}) [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]))
"Elapsed time: 1265.3679 msecs"
(got the example from https://quanttype.net/posts/2021-03-06-clojure-spec-and-untrusted-input.html)Malli's regular expression matching algorithm is fundamentally different, so as far as i know, it does not have the exponential slow down problem. Probably you could still come up with some slow examples, but I don't have insight into what is slow and what is fast.
It does use backtracking, but see the ns docstring for discussion: https://github.com/metosin/malli/blob/master/src/malli/impl/regex.cljc
Sorry for the late response @borkdude @ikitommi, I had an health emergency this week and so I wasn’t able to do anything about it
I’m wondering if m/decode
with the above schema is supposed to produce that result, and if so, I was wondering how to solve this so that I return [1.0 "A"]
from decode?
@arundilipan works on my machine:
(ns sample.core
(:require [malli.core :as m]
[malli.transform :as mt]))
(def GreaterThanZero
[:fn {:decode/string mt/-string->double}
'#(> % 0)])
(def TestEnum
[:enum "A" "B"])
(m/decode
[:catn
[:amount GreaterThanZero]
[:layout TestEnum]]
["1.0" "A"]
mt/string-transformer)
; => [1.0 "A"]
if the result doesn’t match the schema after the transformation, the top-level schema returns the original. this is a feature of the current regex impl, doesn’t support partial transformation:
(m/decode
[:catn
[:amount GreaterThanZero]
[:layout TestEnum]]
["1.0" "C"]
mt/string-transformer)
; => ["1.0" "C"]
In that case I guess the thing to do would be do use something like edn/read-string
instead of decode
? I’d like to make sure that the number is parsed regardless of the result of the rest of the :catn