HCSL: Hand coded stringy lisp
github.com
github.com
For example, the test script has a 'li' function but <li>s are list items and they reside, usually more than one, inside <ol> or <ul> elements. At the very least, there should be a way to take some form of data file (list of blog posts and nested metadata) an iterate over it. Otherwise you're just writing whatever markup you want as the output, with an additional layer, and nothing of added value.
Otherwise what, template the slisp in Jinja too?
`(map li (eval "cat file"))`
Where `file` is newline separated text, and li is applied to each line, and the full string is returned.
For this example ``` (func ul "<ul>{0}< /ul>") (func li "<li>{0}< /li>") (ul (map li (eval "cat file"))) ``` Would return each line of the file nested in a `li` tag nested in a `ul`
That being said, thanks for posting this; it made me think.
Here's the manual on one page https://www.gnu.org/software/m4/manual/m4.html
An m4 example, similar with the snippet within the README
define(`foo', `$1' `$2')
foo(hello, world)
define(`bar', hello)
foo(`bar', world)
esyscmd(`./executable-path')
esyscmd(`cat /tmp/file')It has a deftag macro for defining new tags.
$ txr -i tl-who.tl
If you get your macros hot enough, you get syntactic caramel!
1> (in-package :tl-who)
#<package: tl-who>
We can define :atag, which destructures the first two items of its body as url and class: 2> (deftag :atag other-attrs (url cls . body)
^(:a :href ,url :class ,cls ,*other-attrs ,*body))
#<interpreted fun: lambda (#:g0203 . other-attrs)>
Then use that in the definition of :page: 3> (deftag :page () (url . body)
^(:atag ,url "pages" ,*body))
#<interpreted fun: lambda (#:g0217 . #:g0232)>
So now that we have :page, wrap that in :li: 4> (with-html-output (*stdout*)
(:li (:page "./writing" "My writing")))
<li><a href='./writing' class='pages'>My writing</a></li>
TL-WHO, like CL-WHO, compiles the with-html-output form into something that uses constant string literals that are as long as possible. It closes all your tags, HTML-escapes what has to be escaped and can pretty-print with indentation.Code can be freely used: attributes and tags are distinguished by virtue of being Lisp keywords. Anything that is not a keyword is evaluated as code.
Only when code produces a string is that string interpolated into the output, making it possible to write code with useful side effects and no HTML output, by not returning a string.
Side-effecting code can explicitly write into the HTML stream; the output will go to the right place in the generated HTML:
5> (with-html-output (*stdout*)
(:div :class "foo"
(:pre (:code (sh "ls -l /etc/a*.conf")))))
<div class='foo'><pre><code>-rw-r--r-- 1 root root 3026 Dec 16 2019 /etc/adduser.conf
-rw-r--r-- 1 root root 433 Oct 1 2017 /etc/apg.conf
-rw-r--r-- 1 root root 769 Apr 4 2018 /etc/appstream.conf
</code></pre></div>
Note that the output of "ls -l" isn't being HTML escaped; this example just shows how something can write to the stream as an alternative to interpolation, not that it's a good idea to dump ls -l into that HTML stream.Technically you also need cond, eq?, and pair? (because car and cdr only take pairs not symbols).