Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: autoload
OK, one last.
On Sep 21, 1:09pm, Ray Andrews wrote:
}
} I'd just expect the precompiled function to behave exactly as a
} sourced function would behave, all that's different is that the file
} being parsed is ... is this where I go off the rails?
Yes.
You're not asking for a precompiled function to act like a sourced
function. A sourced function, to the extent that means anything at all,
does nothing but become defined. But "sourcing" a function (which you
actually can't do, you can only source a *file*) and "calling" a
function are two completely distinct things. Rather, you ask for
compiling a whole file full of defined functions, to behave like
creating a bunch of undefined ones.
An undefined function (created with "functions -u" aka autoload) does
both of the source and call operations, but it only knows the one name
(its own). So the file (to be sourced) and the function (to be called)
both have to be identified by that single name.
Could we have created an entire distinct data structure that stores
both a file name and a function name, and means "oh by the way, when
you try to run foo, you actually have to go read the file bar" ?
Yes, we could. We didn't. We re-used the existing data structure
of a function, because one field for the name seemed like enough,
and the path-search mechanism seemed like a good existing model for
finding the file.
Further, the point of autoloading was to read into memory exactly
those functions that are actually used. If to get foo you have to
source bar and do everything bar contains, you may end up reading
(and storing) a hundred functions in order to call one of them.
Not what we wanted to encourage. So, one function per file.
zcompile lets you do two things: compile a single file to be read by
source (*) or pack multiple files into an archive to be processed
by autoload. But the latter doesn't change the fact that autoload
needs to match one file (one thing packed in the archive) to one
function name. And the former doesn't magically grant the ability
to explode the single file into multiple archive entries. (**)
(*) But this is constrained in that both the original file and the
compiled file have to exist size-by-side, so that source can choose
the newer of the two. This constraint isn't strictly necessary.
(**) "zcompile -c" can explode functions that are already in memory
into multiple "files" that then go into the archive, but that's as
close as it gets.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author