Live data from Hacker News

Produce HTML from S-Expressions

github.com

1–10 of 63 posts

Re: Produce HTML from S-Expressions

#2

    (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.

Re: Produce HTML from S-Expressions

#3
post #2

(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…

Like this amirite

https://github.com/weavejester/hiccup

Re: Produce HTML from S-Expressions

#4
post #2

(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…

> :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.

Re: Produce HTML from S-Expressions

#5
post #2

(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…

> Not a fan of the bare words instead of strings either

It is consistent with HTML however, especially the fact that both collapse whitespace.

Re: Produce HTML from S-Expressions

#6
post #2

(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…

Pollen'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

Re: Produce HTML from S-Expressions

#7
post #2

(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…

> 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#...

Re: Produce HTML from S-Expressions

#10
post #2

(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…

> :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 e…

> Using `((class . "alert"))` does not provide any benefits over :class="alert".

Of course it does. It is a s-exp, like everything else in this language, so it's just another list you can map, apply or otherwise transform. The keyword approach instead requires a weird incantation of

    (string-trim (cadr (string-split (keyword->string :class="alert") ?=)) ?")
to extract the value from the attribute. For what benefit? If the goal is using s-exps, why not use s-exps for everything?
Post reply on HN