Live data from Hacker News

Produce HTML from S-Expressions

github.com

41–50 of 63 posts

Re: Produce HTML from S-Expressions

#41

Earlier quoted context omitted.

If your goal wasn't "use s-expr" and it isn't a lisp interpreter, the tagline probably shouldn't be "Produce HTML from S-Expressions" and the project shouldn't be named "lisp-to-html"; it should be "Write HTML with parentheses".

> If your goal wasn't "use s-expr" and it isn't a lisp interpreter, the tagline probably shouldn't be "Produce HTML from S-Expressions" and the project shouldn't be named "lisp-to-html"; it should be "Write HTML with parentheses". You're right maybe it shouldn't be called "Lisp-ish". But, the sources really are s-expressions with an additional ':' marker for attributes, just not Lisp s-expressions with the ':' marker…

Who is your target audience? If it’s Lispers then you need to make the format macro-friendly, if it’s not Lispers then you need to figure out who else likes sexprs but not Lisp?

You could replace the = sign with a space, then you can have (a :href “/news”). Perhaps ::required for an empty attribute. This makes it better for macros.

Re: Produce HTML from S-Expressions

#42

Earlier quoted context omitted.

> If your goal wasn't "use s-expr" and it isn't a lisp interpreter, the tagline probably shouldn't be "Produce HTML from S-Expressions" and the project shouldn't be named "lisp-to-html"; it should be "Write HTML with parentheses". You're right maybe it shouldn't be called "Lisp-ish". But, the sources really are s-expressions with an additional ':' marker for attributes, just not Lisp s-expressions with the ':' marker…

Who is your target audience? If it’s Lispers then you need to make the format macro-friendly, if it’s not Lispers then you need to figure out who else likes sexprs but not Lisp? You could replace the = sign with a space, then you can have (a :href “/news”). Perhaps ::required for an empty attribute. This makes it better for macros.

> Who is your target audience?

It's not Lispers.

> If it’s Lispers then you need to make the format macro-friendly, if it’s not Lispers then you need to figure out who else likes sexprs but not Lisp?

Well, it depends. I like Lisp just fine, but all the Lisp ways of producing HTML are extremely unergonomic for those not already in the Lisp ecosystem.

Someone below posted a link to the clwiki page (I think, not sure) for a list of HTML-generation libraries. I've used some of these before, and they require the user to actually know Lisp well enough to program in Lisp.

I wanted something I can hand off to a junior who doesn't know any Lisp (and doesn't really want to), while still having something that makes it easier to type out HTML.

The `l2h` program is a compromise of sorts between ergonomics and flexibility. It's more effort to use actual Lisp, but you get more in return when you do. It's less effort to use `l2h`, but there are more limits when you do.

> You could replace the = sign with a space, then you can have (a :href “/news”). Perhaps ::required for an empty attribute. This makes it better for macros.

I made a note of this. You're correct about it being better for Lispy macros. Another responder elsethread pointed out a few things that could benefit the usage (imports, macros) while maybe not adding too much "cognitive overload" (AKA Too Much Lisp).

This project has only had about 6hrs thrown at it so far, so it is still early days.

I do appreciate your feedback. Thank you.

Re: Produce HTML from S-Expressions

#43

Earlier quoted context omitted.

> If your goal wasn't "use s-expr" and it isn't a lisp interpreter, the tagline probably shouldn't be "Produce HTML from S-Expressions" and the project shouldn't be named "lisp-to-html"; it should be "Write HTML with parentheses". You're right maybe it shouldn't be called "Lisp-ish". But, the sources really are s-expressions with an additional ':' marker for attributes, just not Lisp s-expressions with the ':' marker…

Who is your target audience? If it’s Lispers then you need to make the format macro-friendly, if it’s not Lispers then you need to figure out who else likes sexprs but not Lisp? You could replace the = sign with a space, then you can have (a :href “/news”). Perhaps ::required for an empty attribute. This makes it better for macros.

i learned lisp, but i don't use it actively. so macros don't matter for me as much, but i have written a few parsers for s-expressions in other languages, most notably i have one in javascript. what is critical for that parser is that parentheses () do the grouping, and that whitespace is the separator between keywords and values.

with class=foo you introduce another separator, complicating the code needed to parse this. if you could use a space here, then i could use my already existing parser to convert this into json or even directly into html without needing any additional code to figure out class values.

simple s-expression parsers in many languages can be found here: https://rosettacode.org/wiki/S-expressions

Re: Produce HTML from S-Expressions

#44

Earlier quoted context omitted.

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

The space you embed it into might

you would normally quote the whole s-expression to make sure it is interpreted as data only. '(look at this: no variables)

Re: Produce HTML from S-Expressions

#45
post #21

Earlier quoted context omitted.

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

This might be okay too? (div (class "alert") So long, and (b thanks) for all the (em fish)) or (div {class "alert"} So long, and (b thanks) for all the (em fish))

Yeah I think you want some way to clearly differentiate between tags and attributes as there are some cases where there are attribute and tags with the same name. E.g. does

(body (style "styleinfo")) mean

Or styleinfo?

Re: Produce HTML from S-Expressions

#46
post #44

Earlier quoted context omitted.

The space you embed it into might

you would normally quote the whole s-expression to make sure it is interpreted as data only. '(look at this: no variables)

To 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)

Re: Produce HTML from S-Expressions

#48
post #21

Earlier quoted context omitted.

This might be okay too? (div (class "alert") So long, and (b thanks) for all the (em fish)) or (div {class "alert"} So long, and (b thanks) for all the (em fish))

Yeah I think you want some way to clearly differentiate between tags and attributes as there are some cases where there are attribute and tags with the same name. E.g. does (body (style "styleinfo")) mean Or styleinfo ?

second example using { } could imply the attribute and ( ) could imply the tag

Re: Produce HTML from S-Expressions

#49
post #39
post #17

I your aready using a scheme you can use SXML. The tooling makes XML fun.

> The tooling makes XML fun. High praise indeed.

Well, it is because you can do most transformations using a tree fold. You get the speed and flexibility of SAX but with the nice interface of DOM parsing.

Apart from scheme, I have only done XML things in Python and C#, and that was a less than stellar experience.

Re: Produce HTML from S-Expressions

#50
post #43

Earlier quoted context omitted.

Who is your target audience? If it’s Lispers then you need to make the format macro-friendly, if it’s not Lispers then you need to figure out who else likes sexprs but not Lisp? You could replace the = sign with a space, then you can have (a :href “/news”). Perhaps ::required for an empty attribute. This makes it better for macros.

i learned lisp, but i don't use it actively. so macros don't matter for me as much, but i have written a few parsers for s-expressions in other languages, most notably i have one in javascript. what is critical for that parser is that parentheses () do the grouping, and that whitespace is the separator between keywords and values. with class=foo you introduce another separator, complicating the code needed to parse t…

To keep the rules simple (i.e. people shouldn't need to learn Lisp to write the source input) I don't want context to determine what `(foo :bar baz)` means.

With the current two rules, the symbol after any `(` is always the tagname. There are no exceptions based on context. The input `(foo (bar baz))` has meaning `baz`.

This meant I needed a different way to indicate attributes. I used the ':', resulting in needing a way to specify the optional attribute value, so I used the '='.

I still have to decide on a few more things, so I'm still considering changing the way attributes are specified, but I don't think I will ever make it contextual.

Post reply on HN