TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

HCSL: Hand coded stringy lisp

26 pointsby 0x3444ac53almost 2 years ago

9 comments

evrimoztamuralmost 2 years ago
It&#x27;s a good idea to reduce templating languages into a simpler form, I&#x27;ll agree to that, but the issue here is that you still need loops and data input.<p>For example, the test script has a &#x27;li&#x27; function but &lt;li&gt;s are list <i>items</i> and they reside, usually more than one, inside &lt;ol&gt; or &lt;ul&gt; 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&#x27;re just writing whatever markup you want as the output, with an additional layer, and nothing of added value.<p>Otherwise what, template the slisp in Jinja too?
评论 #37226147 未加载
评论 #37231780 未加载
gumbyalmost 2 years ago
While Lisp is my preferred normally my go-to language, tbh I think sed or awk are probably adequate and, already being installed, probably in some sense “better”.<p>That being said, thanks for posting this; it made me think.
评论 #37226367 未加载
chriswarboalmost 2 years ago
Seems similar in spirit to Lips, a pre-processor which can evaluate Lisp and splice it into the output (Common Lisp <a href="https:&#x2F;&#x2F;github.com&#x2F;zc1036&#x2F;lips">https:&#x2F;&#x2F;github.com&#x2F;zc1036&#x2F;lips</a> or Scheme <a href="https:&#x2F;&#x2F;github.com&#x2F;rbryan&#x2F;guile-lips">https:&#x2F;&#x2F;github.com&#x2F;rbryan&#x2F;guile-lips</a> )
lkutyalmost 2 years ago
I am not happy with the &quot;joke&quot; in the README and if I could I would report it but it looks like it doesn&#x27;t fall into Github categorization of abuse. Keep your bad jokes to yourself, inside your head, where nobody can see them.
评论 #37225631 未加载
评论 #37225796 未加载
mhitzaalmost 2 years ago
Based on the rationale given I think the author could have used GNU m4. While I&#x27;m definitely not fond of the syntax, it can get the job done. I don&#x27;t think many (if any) projects use it (excluding autoconf).<p>Here&#x27;s the manual on one page <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;m4&#x2F;manual&#x2F;m4.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;m4&#x2F;manual&#x2F;m4.html</a><p>An m4 example, similar with the snippet within the README<p><pre><code> define(`foo&#x27;, `$1&#x27; `$2&#x27;) foo(hello, world) define(`bar&#x27;, hello) foo(`bar&#x27;, world) esyscmd(`.&#x2F;executable-path&#x27;) esyscmd(`cat &#x2F;tmp&#x2F;file&#x27;)</code></pre>
0x3444ac53almost 2 years ago
I wrote a lisp
kazinatoralmost 2 years ago
There is a port of the CL-WHO HTML templater or TXR Lisp called TL-WHO.<p>It has a <i>deftag</i> macro for defining new tags.<p><pre><code> $ txr -i tl-who.tl If you get your macros hot enough, you get syntactic caramel! 1&gt; (in-package :tl-who) #&lt;package: tl-who&gt; </code></pre> We can define :atag, which destructures the first two items of its body as url and class:<p><pre><code> 2&gt; (deftag :atag other-attrs (url cls . body) ^(:a :href ,url :class ,cls ,*other-attrs ,*body)) #&lt;interpreted fun: lambda (#:g0203 . other-attrs)&gt; </code></pre> Then use that in the definition of :page:<p><pre><code> 3&gt; (deftag :page () (url . body) ^(:atag ,url &quot;pages&quot; ,*body)) #&lt;interpreted fun: lambda (#:g0217 . #:g0232)&gt; </code></pre> So now that we have :page, wrap that in :li:<p><pre><code> 4&gt; (with-html-output (*stdout*) (:li (:page &quot;.&#x2F;writing&quot; &quot;My writing&quot;))) &lt;li&gt;&lt;a href=&#x27;.&#x2F;writing&#x27; class=&#x27;pages&#x27;&gt;My writing&lt;&#x2F;a&gt;&lt;&#x2F;li&gt; </code></pre> 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.<p>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.<p>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.<p>Side-effecting code can explicitly write into the HTML stream; the output will go to the right place in the generated HTML:<p><pre><code> 5&gt; (with-html-output (*stdout*) (:div :class &quot;foo&quot; (:pre (:code (sh &quot;ls -l &#x2F;etc&#x2F;a*.conf&quot;))))) &lt;div class=&#x27;foo&#x27;&gt;&lt;pre&gt;&lt;code&gt;-rw-r--r-- 1 root root 3026 Dec 16 2019 &#x2F;etc&#x2F;adduser.conf -rw-r--r-- 1 root root 433 Oct 1 2017 &#x2F;etc&#x2F;apg.conf -rw-r--r-- 1 root root 769 Apr 4 2018 &#x2F;etc&#x2F;appstream.conf &lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt; </code></pre> Note that the output of &quot;ls -l&quot; isn&#x27;t being HTML escaped; this example just shows how something can write to the stream as an alternative to interpolation, not that it&#x27;s a good idea to dump ls -l into that HTML stream.
fsmvalmost 2 years ago
Have you thought about adding car, cdr, and cons? You wouldn&#x27;t need to shell out to subprocesses if you had the full list of minimal lisp primitives.<p>Technically you also need cond, eq?, and pair? (because car and cdr only take pairs not symbols).
评论 #37226299 未加载
okkdevalmost 2 years ago
Why does the readme open with an incel joke?
评论 #37228170 未加载
评论 #37225254 未加载
评论 #37225661 未加载