29 karma · joined Dec 29, 2015 (10y ago) · 18 submissions
1.
Show HN: Transit-format (JSON/MessagePack) reader/writer in C(github.com ↗)
6 points · by delaguardo · 5mo ago · discuss
comment 7mo ago · link · parent
JVM usage (which is the main host for Clojure) as a platform is increasing modestly, driven by modernization (Loom, GraalVM, Valhalla on the horizon)
comment 1y ago · link · parent
more than that: in this reader implementation nil, true, false are also valid identifiers with special handling to turn them into nil and bool.
I encourage you to reread original specification and then continue after "this insanity" :)
comment 1y ago · link · parent
{:pi 3.141_592_653_589
:c 299_792_458
:hex 0xDE_AD_BE_EF
:tb """
#!/usr/bin/env bb
(require '[babashka.http-client :as http])
(defn get-url [url]
(println "Downloading url:" url)
(http/get url))
"""}comment 1y ago · link · parent
yes, any edn reader implementation will read the complete base64 string from the example before giving this string to a custom reader. I understand now what you explain. However, I don't know what I can do about it. I use edn daily, it works great to me, and I have no immediate plans to replace it with something else.
Anyway, the example you shared looks interesting, I'll definitely read more about it. Thank you.
comment 1y ago · link · parent
Sorry, you understand it wrong
There is no enclosing element at the top level. Thus edn is suitable for streaming and interactive applications.
> but I don't know if the existing one does
This implementation does not do streaming for now, but it understands a concept of "reading one complete" element from buffer. The only missing part is buffer managment.
> So, the extensibility is still restricted.
Could you explain how it is restricted if you are allowed to run whatever you want during reading of edn document? You can even do IO, no restrictions at all!
Consider this:
#init/postgres {:db-spec {:host "..." :port 54321 ,,,} :specs {:user ,,,}} [#user/id 1 #user/id 2 #user/id 3]
This allows you to have a program that can lookup postgres database during reading of a document validating every returned object using provided spec (conforming the value)
> In my opinion, ASN.1 (and ASN.1X) does it better.
Please show how it does better. I'm very curious
comment 1y ago · link · parent
> The whole world seems to run on JSON
That is true, and I don't like that :)
From my perspective JSON syntax is too "light" and that translates to many complications typically in the form of convention: {"id": {"__MW__type": "LONG NUMBER", "value": "9999999999999999999999999"}}.
comment 1y ago · link · parent
> I'm curious how much AI was used in the creation of edn.c
A fair amount. This is my first big public project written in pure C. I did consult LLM about best practices for code organisation, memory management, difference in SIMD instructions between platforms, etc. All the things Clojure developer typically don't think about (luxury of a hosted language). Ultimately, the goal was to learn some part of C programming, working reader is a side effect of that.
> These days, I like to get a measure of that for every library I use.
Btw, I'm curious, what kind of measuring you are looking for?
comment 1y ago · link · parent
Yes, EDN is a textual format intended to be human-readable. There is also a format called Transit used to serialise EDN elements. Unlike raw EDN, Transit is designed purely for program-to-program communication and drops human readability in favor of performance. It can encode data into either binary (MessagePack) or text (JSON), but in both cases, it preserves all EDN data types and originates from the Clojure language.
comment 1y ago · link · parent
The best part of EDN that it is extendable :)
#binary/base64 "SGVsbG8sIHp6bzM4Y29tcHV0ZXIhIEhvdyBhcmUgeW91IGRvaW5nPw=="
This is a tagged literal that can be read by provided (if provided) custom reader during reading of the document. The result could be any type you want.
comment 1y ago · link · parent
comment 1y ago · link · parent
you can run it locally with `make bench bench-clj bench-wasm`
Let me know if I can do anything to help you with support in jank.
comment 1y ago · link · parent
tl;dr first element of the vector is a tag, second is a map of attributes test are children nodes:
[:h1 {:font-size "2em" :font-weight bold} "General Kenobi, you are a bold one"]
17.
A fast EDN (Extensible Data Notation) reader written in C11 with SIMD boost(github.com ↗)
112 points · by delaguardo · 1y ago · 38 comments