help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to tame compiler?


From: tomas
Subject: Re: How to tame compiler?
Date: Sun, 2 May 2021 14:24:27 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Sun, May 02, 2021 at 02:18:23PM +0300, Jean Louis wrote:
> * tomas@tuxteam.de <tomas@tuxteam.de> [2021-05-02 12:08]:

[...]

> > I tried to offer an explanation which you chose to ignore [1] . I
> > think the problem is more subtle, and thus difficult to explain in
> > just a few words.
> 
> As I am asking questions it is demonstration that I am not ignoring
> it. In background I am running business, so the templating engine does
> help me, it works, I have sent now quite number of messages to
> people. But in foreground, here, I am interested for any kinds of
> suggestions.

Well, I offered a suggestion. Write your limited version of eval,
which makes available the substitutions (values or functions)
you intend to use in your template, for example in a dictionary
(aka hash). That's what other templating systems do, even in
languages which do have eval (that's why I provided examples in
Perl and Python).

> It is not the option to change text to sex-pressions, as that would
> cause way too much work and minimize collaborative capacity, as that
> demands teaching people not only how to write text, but how to write
> kind of Lisp.

The S-expression proposal is orthogonal to the problem at hand.
That's why I didn't propose it (although it does have some advantages
of its own).

> Purpose of it is to interpolate values into text, to pre-process text
> or templates. Usually both are pre-processed, the text first, then
> text and variables are interpolated into the template. It could be for
> letters, it could be like for LaTeX or other markup, mostly HTML,
> emails and SMS message.

[...]

> > It's not as clear-cut as "should not be used". Rather something along
> > the lines of "should be used with care" [2].
> 
> It may be evil, just that I don't find practical evilness, but I would
> like one simple example how it can be evil.

It's too subtle to be covered by "just one simple example", that's why
I proposed you do some research.

> IMHO, functions are here, if you see something wrong with it, let me
> know. It is in a package that does not have lexical-binding t, and it
> is one particular case where it should stay so, as I wish to
> interpolate any variables.

[...]

I haven't the time to go through your code, sorry.

> > Template expansion is one of those borderline cases, but if you look
> > at all those modern template expanders out there [3], you'll realise
> > that they all have some kind of "custom evaluator", where you
> > explicitly provide an environment, instead of just punting to `eval'
> > and saying "use... uh, whatever".
> 
> For string expansion they will provide environment and "manually"
> replace some words into provided alist for example. CL-EMB in Common
> Lisp uses `read-from-string'.
> 
> So far I see the use of it and I used it years before, just with
> Common Lisp.
> 
> Here is one example page with its source that uses `rcd-template-eval':
> 
> https://hyperscope.link/3/7/1/3/6/Emacs-Lisp-interpolation-of-embedded-PostgreSQL-queries-within-plain-text.html
> 
> Purpose of it is to give liberation to HTML, SMS, email templates and
> make static HTML pages kind of dynamic, as some dynamically generated
> data can be expanded before publishing HTML pages.
> 
> I understand so far:
> 
> - there are opposing arguments to `eval', but...

Let me put that this way: to do a good job, the compiler makes assumptions
on things like variable bindings ("this variable can only be seen in
this part of the code I analysed right now"). When an eval is in the
middle of things, the compiler can't "see through": the code therein
can change at run time. All bets are off.

Just imagine a (let ((x 5) ...) and then an eval whithin that with
a form (setq x 6).

> - there is no replacement for `eval' in the context of templates with
>   programming code; or other contexts;

There is. See my examples.

> - `eval' is already heavily used in Org mode and Muse, so many other
>   large number packages;
> 
> Those contradictions are confusing.

Because the topic is not that simple :)

Cheers
 - t

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]