Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Source mangling in $functions_source and typeset -f



On Sat, Nov 27, 2021, at 2:25 PM, Ray Andrews wrote:
> On 2021-11-27 9:47 a.m., Bart Schaefer wrote:
>>
>> With the exception of the contents of strings (including
>> here-documents), the original source of a function is not kept in
>> shell memory.  Instead a parse tree is stored and used to regenerate
>> the function definition by "typeset -f" et al.
> That's most interesting, it seems circular so there must be a good 
> reason for it, but why take the source as written, then parse it down to 
> 'clean code' and then construct whatever internal representations zsh 
> uses and then reconstruct clean code from that when one could just 
> repeat the first step?

Are you asking why ''typeset -f'' and its ilk don't reread the
original source code?

> Is it perhaps faster to perform the 3d step than 
> repeat the first step?

Surely it is, if the first step involves disk I/O.

> But repeating the first step would surely preserve more?

Don't assume code comes from a file that can be read again.  What
if the original file is no longer available?  What if the function
was defined using standard input and didn't originate from a file
at all?

-- 
vq




Messages sorted by: Reverse Date, Date, Thread, Author