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: Jean Louis
Subject: Re: How to tame compiler?
Date: Sun, 2 May 2021 21:17:01 +0300
User-agent: Mutt/2.0.6 (2021-03-06)

* tomas@tuxteam.de <tomas@tuxteam.de> [2021-05-02 15:25]:
> 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).

I did use that for years. The new approach seem so much simpler and
liberating, it lessens the work.

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

As my system supports any type of markup, I can include that as
well. Again I would be reading it with `read-from-string' straight
from the database, and then using `eval'.

S-expression text has to be stored somewhere, right? It has to be
loaded from somewhere, so majority would be loading it from file I
guess, I am loading it from the database and again I have to use
`eval'. The purpose not to use `eval' defeats itself how I see it as I
have to use `eval'.

Let us say database table is named: pages, there is column pages_text,
if it contains string like "(p \"Hello there\")" -- I have to
`read-from-string` and `eval' or maybe there exists some other way?

What would you do? Would you load it from file?

I am thinking, what would be the difference of loading it from file,
or using `eval', I cannot find the difference, I wish I could.

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

I did that research years ago. Do we have any practical use of
declining to use specific function without being able to tell why?

On the other hand, thousands of people use `eval' in Org mode as a
good example, and not for Emacs Lisp only.

If we wish to remedy the situation we would need maybe to find safer
`eval' but before finding safer `eval' we have to know why exactly is
this one not safe as compared to whatever proposed replacement
methods. 

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

I understand, compiler will not be able to see through.

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

Good example, thank you.

That would be `eval' within a program. My `eval' takes place within a
text. It does not necessarily change program, I do not know if it
would be possible, I can try.

(let ((variable "Gully")
      (my-value 0)
      (template "⟦ variable ⟧ ⟦ (setq my-value 1) ⟧"))
  (rcd-template-eval template)) ⇒ "Gully 1"

Now I can see that I can change program values from within `eval'
in the template. On the other hand, I can change values also
within the program. The safety is thus in the decision making of
authors, not in `eval' itself.

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

Do you mean example of passing a hash?


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




reply via email to

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