4 ms·
(h1 :disabled Hello world!) (div :class="alert" So long, and (b thanks) for all the (em fish)) I hate that syntax for attributes. :class="alert"
by sph 3y ago
(h1 :disabled Hello world!)
(div :class="alert"
So long, and (b thanks) for all the (em fish))
I hate that syntax for attributes.
:class="alert" is strictly worse than ((class . "alert")) or any other variation that actually leverages s-expressions instead of merging key and value into the same symbol. Ew.
Not a fan of the bare words instead of strings either, which means this cannot be naively evaluated by a Lisp.
I wouldn't say this is producing html from s-exps, rather that it is vaguely inspired by them.
- ptx 3y agoWith this merged attribute syntax, since each key-value combination is a separate symbol and since symbols are interned, doesn't this mean that all the attribute values (and not just the keys) end up interned? Do Lisp implementations usually garbage-collect interned symbols when they're no longer used?
- kazinator 3y agoFirstly, obviously yes for un-interned. TXR Lisp: This is the TXR Lisp interactive listener of TXR 291. Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet. I'm confused; is this piano recital Rimsky-Korsakov or Wernicke–Korsakoff? 1> (progn [finalize (gensym "foo-") prinl] nil) nil 2> (sys:gc) #:foo-0012 t 3> (sys:gc) t We make a gensym whose name starts with foo-. We register a GC finalizer for it which is the prinl function (print, with newline). Then when we manually invoke GC, it gets collected; we see the print. Internet symbols cannot be collected, normally, because they are always used: they are registered in their package. TXR Lisp has weak packages, though. A weak package will purge a symbol that is not reachable other than through the package. 1> (make-package "abc" t) ;; t argument here means weak #<package: abc> 2> (progn [finalize (intern "xyz" *1) prinl] nil) nil 3> (sys:gc) abc:xyz t 4> (package-symbols *1) nil 5> Don't know if other Lisp people thunk of this one, but there it is. I don't think I exposed this weak property through the defpackage macro. It's intended for specific scenarios, like reading data in the context of a package.
- KRAKRISMOTT 3y agoLike this amirite https://github.com/weavejester/hiccup https://github.com/weavejester/hiccup
- xemoka 3y agoThe thi.ng umbrella has a hiccup variant for JS that looks pretty neat too: https://thi.ng/hiccup https://thi.ng/hiccup
- lelanthran 3y ago> :class="alert" is strictly worse than ((class . "alert")) or any other variation that actually leverages s-expressions instead of merging key and value into the same symbol. Ew. I hear you, but I wasn't aiming for leveraging the power of macros. Using `((class . "alert"))` does not provide any benefits over :class="alert". > Not a fan of the bare words instead of strings either, which means this cannot be naively evaluated by a Lisp. I traded off ergonomics against "Evaluation by a Lisp processor".Instead of (div "My first " (b "hello") (em " world")) I'd rather do (div My first (b hello) (em world)) Thank you for your input.
- kazinator 3y agoIf My and first just stand for themselves, you're not interpolating variables; where is the templating? Also, what if you don't want a space between the bold hello and emphasized world? Or between first and <b>hello</b>?
- lelanthran 3y ago> If My and first just stand for themselves, you're not interpolating variables; where is the templating? Templating wasn't mentioned (yet. looking at the feedback I got, some avenues are open for some sort of templating). > Also, what if you don't want a space between the bold hello and emphasized world? Then you don't put one in? $ echo "(div My first (b hello)(em world)) " | ./l2h -s <div>My first <b>hello</b><em>world</em></div> > Or between first and <b>hello</b>? Again, don't put one in: echo "(div My first(b hello) (em world))" | ./l2h -s <div>My first<b>hello</b> <em>world</em></div> I think that that is is intuitive as it can get for people who know HTML: space-emission matches what you would expect for HTML. If you look at the git history, I spent a lot of time making sure that the parsing of whitespace and newlines made sense from an HTML perspective, not from a Lisp perspective.
- kazinator 3y agoThat's not S-exprs then because there is no symbolic difference between )( and ) ( or between foo( and foo (. But it's a better representation for HTML, that we would have had if Berners-Lee hadn't been a supreme goofball.
- messe 3y ago> Not a fan of the bare words instead of strings either It is consistent with HTML however, especially the fact that both collapse whitespace.
- giraffe_lady 3y agoPollen's tagged xexp is probably the most sophisticated approach to this I've seen. Though hiccup is about as good and easier to work with. https://docs.racket-lang.org/txexpr/index.html https://docs.racket-lang.org/txexpr/index.html
- Zambyte 3y ago> Not a fan of the bare words instead of strings either, which means this cannot be naively evaluated by a Lisp. Most Lisps (all that I know of) have a way to convert symbols to strings. The hard part is resolving the ambiguity between what should be text, and what should be treated as an HTML node. Like, what if I wanted to actually write the string "(b thanks)" on a page? R7RS could probably do this with the pipe identifier syntax[0], but I think R7RS is fairly unique in its capability for identifiers (and thus symbols) with such a wide range of supported characters. [0] https://standards.scheme.org/corrected-r7rs/r7rs-Z-H-4.html#TAG:__tex2page_sec_2.1 https://standards.scheme.org/corrected-r7rs/r7rs-Z-H-4.html#...
- sph 3y agoBare words are fine until you have a variable with the same name as your bare word, so you need additional syntax to determine if you're referencing a variable, or it is just text.
- lelanthran 3y ago> Bare words are fine until you have a variable with the same name as your bare word, so you need additional syntax to determine if you're referencing a variable, or it is just text. This doesn't have variables. Or functions.
- mtreis86 3y agoThe space you embed it into might
- em-bee 3y agoyou would normally quote the whole s-expression to make sure it is interpreted as data only. '(look at this: no variables)
- Zambyte 3y agoTo expand on this, Lisps also usually have a quasiquotation system to make it easy to embed data from the host system into an s-exp. `(look ,(get-parent): some variables like ,x)