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

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

Re: Easy to add with push but not to the end of a list


From: Michael Heerdegen
Subject: Re: Easy to add with push but not to the end of a list
Date: Fri, 09 Dec 2022 00:15:03 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Emanuel Berg <incal@dataswamp.org> writes:


> In practice I didn't use them since these were better
> suited ...
>
> (defun file-to-string (file)
>   "A string with the contents of FILE."
>   (interactive "Ffile: ")
>   (with-temp-buffer
>     (insert-file-contents file)
>     (string-trim
>       (buffer-substring-no-properties (point-min) (point-max)) )))
>
> (defun file-to-integer (file)
>   (string-to-number (file-to-string file)) )

Yes, I wondered why you preferred a macro there at all.

> > A second (related) problem is that FILE must be a string -
> > a function call like (expand-file-name "my-file"
> > "/some/path") will not behave as expected, because your
> > helper functions don't expect an expression.
>
> Okay, but how do you check if it's an expression?

That macro argument should better be evaluated (since not only strings
make sense there), so it's _always_ an expression, even when it's a
string (that happens to be a self-evaluating expression in this
context).

And you don't want to evaluate it at expansion time.  That was your
mistake several times.  What's code normally goes into the expansion,
maybe in the original or in a transformed form.  Or it's dismissed.  The
macro is there to transform code, not to evaluate it, not even
partially.  Unless it's code actually needed to produce the expansion.
These cases are rare.  Be careful not to mix them up.

> Also take a look at this, one should have a cache function and
> a function to store arbitrary data and datastructures and the
> corresponding to load seam-/losslessly into the same Lisp
> datastructures all tho these are not the same/unaware of the ones
> that was used (refered to) when saving ...

What in particular is your question?

You don't need to reinvent `eieio-persistent' btw because it already
exists!  It allows to save and restore more or less arbitrary objects
and data; the implementation already supports a lot of different types.


Michael.



reply via email to

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