4 ms·
Seems like a really silly lisp with string operators and is incredibly hard to read when not trivial. This will probably be the first and last time I ever ask t
by millerm 5y ago
Seems like a really silly lisp with string operators and is incredibly hard to read when not trivial. This will probably be the first and last time I ever ask this question, but why not just use something like clojurescript?
- eevilspock 5y agoThank you. I'm going to take a look at this for the project I mentioned in my other comment.
- sebmellen 5y agoI’m trying to define a matrix for the conditions under which a given “credential” can be accepted/is valid. The goal is to embed that matrix within the credential schema itself, such that it’s almost self-verifying, depending on the context of the credential’s usage/presentation. (A bit hard to explain without diagrams.) Using JSON to do this would allow schema portability throughout the different languages in our stack, but of course it’s an imperfect solution. Open to hearing any other options (I have looked into YAML as well but that’s a whole other ball of wax)...
- mixedCase 5y agoS-expressions do all of this, which is why everyone is suggesting you've reinvented Lisp. They're trivial to parse and easier to read than JSON for this use case.
- sebmellen 5y agoThe problem with s-expressions is that you can’t include them within an already extant JSON schema.
- mixedCase 5y agoYes you can, simply as a string. Here's your parsingMatrix from your other comment: { "if":[ { "or":[ { "===":[ { "var":"credentialData.rapidSarsCov2PCRTest.testResult" }, "negative" ] }, { "===":[ { "var":"credentialData.covid19Vaccination.hasVaccination" }, true ] } ] }, "valid", "invalid" ] } Here it is rewritten in a way more similar to how a human writes Lisp: { "if": [{"or": [{"===":[{ "var":"credentialData.rapidSarsCov2PCRTest.testResult" }, "negative" ]}, {"===":[{ "var":"credentialData.covid19Vaccination.hasVaccination" }, true ]}]}, "valid", "invalid"]}; Here it is as an s-expression, which you can store in a string: (if (or (= (var "credentialData.rapidSarsCov2PCRTest.testResult") "negative") (= (var "credentialData.covid19Vaccination.hasVaccination") #t)) "valid" "invalid") But, if you really have an intense hatred for adding an additional parsing step on top of the JSON, you can still improve over JsonLogic with just JSON primitives used in a cleaner way that more directly represents that s-expression. ["if", ["or", ["=", ["var", "credentialData.rapidSarsCov2PCRTest.testResult"], "negative"], ["=", ["var", "credentialData.covid19Vaccination.hasVaccination"], true]], "valid", "invalid"] It's still uglier than s-expressions where you can tell symbols and strings apart with more ease, but without all the syntactical noise of JSON objects combined with arrays.
- sebmellen 5y agoThanks for the formatting, it's a lot better this way. I was using Prettier to make sure everything made sense as I a rather limited time to write the comment. Auto-formatting definitely comes with downsides... I guess that last example you demonstrated works, but I fail to see an appreciable advantage of using that over JsonLogic. It seems quite similar aside from being "cleaner," and comes with the disadvantages of not being as well defined a spec as JsonLogic. Really interesting though!
- renewiltord 5y agoI might be misunderstanding, of course, but would you be able to use the JSON protobuf serializers and just define your conditions as Protocol Buffers? Might be heavyweight.
- sebmellen 5y agoI think it's best to direct your attention here as the comment is rather lengthy and takes up a lot of vertical space: https://news.ycombinator.com/item?id=27307631 https://news.ycombinator.com/item?id=27307631.
- jimsimmons 5y agoThis is not a bad idea. But coupling with protocol buffers is an issue and JSON doesn’t have a standardised way to parse expressions
- joshlemer 5y agoClojureScript does not complete in a deterministic amount of time, on account of it being a turing-complete programming language.
- deleted 5y ago[deleted]