5 ms·
I came to Lisp (Scheme/Racket) from that another side (C++, Java, Perl) and it was an enlightening experience. Now I use Lisp nearly everywhere in a form of a
by garganzol 9y ago
I came to Lisp (Scheme/Racket) from that another side (C++, Java, Perl) and it was an enlightening experience.
Now I use Lisp nearly everywhere in a form of a small .NET runtime module.
Lisp is excellent at templating tasks. Just for comparison: StringTemplate for .NET is a whooping 400 kB of compiled binary code while my implementation of Lisp is just 35 kB (!). Sure enough, Lisp does the very same thing as StringTemplate, but in just 1/10 of the code. There is more: Lisp is Turing-complete while StringTemplate doesn't. I can add a .NET function to Lisp environment and then call it in my template. I cannot do that with StringTemplate. I repeat, this is a 35 kB Lisp David vs 400 kB StringTemplate Goliath.
Isn't Lisp beautiful?
But wait, there is more. Lisp is excellent for natural language processing because you can intersperse a human text with Lisp. Suppose the first % character enters into Lisp mode and subsequent % character exits back to text. The example of Lisp NLP would then look like:
"Hello %name%. It is time to do some math. Assume A + B = %(+ a b)%. What is the value of A when B is %b% ?"
You then fill Lisp environment with desirable values:
env["name"] = "David";
env["a"] = 15;
env["b"] = 85;
Evaluating aforementioned template will produce the following result:
"Hello David. It is time to do some math. Assume A + B = 100. What is the value of A when B is 85 ?"
With that tool at hand, you can build a user-configurable quiz system in no time. Or maybe a configurable Virtual Assistant. Or a chat bot. Or anything else, you name it.
Lisp is small as the Universe before Big Bang. Nevertheless it provides nearly endless possibilities when you have a need, a fit and imagination for them.
- dahauns 9y ago>Lisp is Turing-complete while StringTemplate doesn't. Well...C# String interpolation is.
- garganzol 9y agoC# string interpolation is fast and preferable solution that works great at smaller scale (which is probably close to 99.99% of all use cases). Having said that, C# string interpolation is not user-configurable, and you cannot realistically use it to generate, say, 300 lines of highly sophisticated text that is a subject to frequent modifications during product development. One of the popular tasks for a larger scale templating is email generation. Text templates, HTML templates, for signup, for email confirmation, for password reset, for subscription renewal, for ... you name it. As you can see, it quickly goes wild. Not sure one would prefer string.Format() or C# string interpolation to do all of that.
- dahauns 9y agoAh...! Sorry, I misunderstood you there. (Ok,ok. I admit I only skimmed your reply :) ). But why would you want Turing completeness in a user facing templating engine? This is generally considered harmful, leading to all kinds of maintenance horrors. (And that's why StringTemplate deliberately isn't.)
- mattmanser 9y agoErr, or just use Razor cshtml?
- zelos 9y agoAlthough that approach to string creation tends to fall apart quickly in non-English languages: adjectival agreement, plural rules etc.
- garganzol 9y agoNo, no, it doesn't fall apart! Lisp is Turing-complete. You can do (in English): "David has %n% apple%(when (> n 1) "s")%." You can move that rule to function etc. You can tweak that for the language you use in an endless number of ways.
- chii 9y agoso you're going to ask your translater to learn Lisp?
- deleted 9y ago[deleted]
- garganzol 9y agoA generic translator cannot realistically cope with Lisp. It has to be a translator + NLP guy working together in conjunction to bring a high quality localization for the given textual model.
- kazinator 9y agoNo; you just give an example about how to customize the suffix based on the number, but don't say that it is "programming" or "software development" or anything like that. https://www.gnu.org/gnu/rms-lisp.en.html https://www.gnu.org/gnu/rms-lisp.en.html "Multics Emacs proved to be a great success — programming new editing commands was so convenient that even the secretaries in his office started learning how to use it. They used a manual someone had written which showed how to extend Emacs, but didn't say it was a programming. So the secretaries, who believed they couldn't do programming, weren't scared off. They read the manual, discovered they could do useful things and they learned to program.
- wglb 9y agoOk, this is seriously intriguing. Are more details about this magic thing available?
- kazinator 9y agoIf you like that, you will probably enjoy the a language that I made called TXR. It's a Lisp dialect (TXR Lisp) plus a whole-document pattern recognition and generation language. These can be used independently or in combination. This example shows generation (with some very light extraction: munging a copyright header from existing files to stick into a generated file): http://www.kylheku.com/cgit/txr/tree/gencadr.txr http://www.kylheku.com/cgit/txr/tree/gencadr.txr gencadr.txr generates all those caar, cadr, caddr, ... functions down to five levels deep, in C. Plus it generates the Lisp defplace definitions for all of them so they are assignable, as in (set (caddar x) new-value). That part could have been done in Lisp rather than textual generation, but I said what the heck. Generated results: http://www.kylheku.com/cgit/txr/tree/cadr.c http://www.kylheku.com/cgit/txr/tree/cadr.c http://www.kylheku.com/cgit/txr/tree/share/txr/stdlib/cadr.tl http://www.kylheku.com/cgit/txr/tree/share/txr/stdlib/cadr.t...
- tigershark 9y agoSince when string interpolation is a such mysterious and arcane feature?
- RivieraKid 9y agoMany languages have string interpolation. It's a nice feature, but absence of it doesn't make your life hell.