[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: |
Sat, 1 May 2021 09:34:06 +0300 |
User-agent: |
Mutt/2.0.6 (2021-03-06) |
* Stefan Monnier <monnier@iro.umontreal.ca> [2021-05-01 06:50]:
> > Independent from the question whether your usage of `eval' is good or
> > valid - there must be some real problem here: if the compiler tells that
> > the lexical variables are unused, their values will not be available in
> > you `eval' call - you would have to create dynamical bindings for that.
>
> I know I sound like a broken clock, but I think a better answer is to
> avoid `eval`: instead of taking expressions (that you'd pass to `eval`)
> arrange to receive functions (which you'd pass to `funcall` or `apply`).
> Then you can pass those functions the data they need (e.g. the value of
> things like `unsubscribe-text`).
I have to understand it in this example:
The HTML template is following and it is string:
<html>
<head>
<title>⟦ xml-escape title ⟧</title>
</head>
<body>
<p>Today is one US dollar this many euros: ⟦ usd-eur 1 ⟧</p>
</body>
</html>
> I know I sound like a broken clock, but I think a better answer is to
> avoid `eval`: instead of taking expressions (that you'd pass to `eval`)
> arrange to receive functions (which you'd pass to `funcall` or `apply`).
> Then you can pass those functions the data they need (e.g. the value of
> things like `unsubscribe-text`).
Does that mean I should now extract maybe function `xml-escape' and use apply
with rest of arguments?
Maybe instead of:
<title>⟦ xml-escape title ⟧</title>
I should make:
<title>⟦ xml-escape title ⟧</title>
And then apply xml-escape with "title".
Then I would convert first word into function, that somehow
works, but all the remaining parts of string still need to be
converted. How is program to know that things in a string are for
example other variables or other Lisp functions?
(let* ((lisp (buffer-substring-no-properties
(1+ (match-beginning 0)) (1- (match-end 0))))
(lisp (split-string lisp))
(function (pop lisp))
(_ (message "%s" function))
(value (apply (intern function) lisp)) ;; I am stuck here
(value (string-or-empty-string value)))
For simplest use case like converting string to variable, or something like:
⟦ var hello-name ⟧
I think that would work, but then if I only use variables, I
would not need "var" there, I could just interpolate it into
variable without eval.
For the case where there is even slightly complex Lisp like ⟦ (usd-eur
(gold-price-kg)) ⟧
I would not know what to do there.
Maybe it could look like:
⟦ usd-eur (gold-price-kg) ⟧
But then again program would receive string "(gold-price-kg)" and
how would I know that string is another function? I would need to
extract that string and basically make small Lisp reader, again
we come to kind of eval-ing it.
I want to know if there is way to do it.
--
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/