zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: autoload
Date: Tue, 22 Sep 2015 10:33:40 -0700	[thread overview]
Message-ID: <560190F4.8020404@eastlink.ca> (raw)
In-Reply-To: <150921201943.ZM707@torch.brasslantern.com>

On 09/21/2015 08:19 PM, Bart Schaefer wrote:
> 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.
I understand, I just chose the wrong word.
>    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.
Ok.  I admit that my notion does presume a table linking functions with 
their
.zwc:

raysfunc    /directory/raysfunc.zwc    line1
somefunc  /directory/all/allfunc.zwc  line40
otherfunc  /directory/all/allfunc.zwc  line200
...

I get a glimpse of how you did what you did within existing structures. 
If I understood
that fully I'd grok the limitations of the system.  I guess it's a bit 
outrageous of me,
but I presumed that in the hash table that links functions to where ever 
they are,
a sort of pointer to a line in a .zwc file would not be a huge problem.
>
> 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.

That is so insightful, cuz I had exactly the opposite as the supposed 
goal--to
have functions available but not sourced *just in case* you might need them.
I never understood:

     autoload -U colors && colors

... because I'm thinking to myself: 'Why would you 'autoload' something 
that
you are just going to plain vanilla load anyway? Why not just load it 
and be
done with it?' (It doesn't work with compinit.  It seems because 
compinit will
be looking on FPATH for the rest of itself autoloaded, so it's committed to
that method--but you understand my thought.)
>
> 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.

But ... if we have several functions packed in one .zwc it is not 
logically possible
for the name of the file to match the name of more than one of the 
functions which
breaks my head as far as this one-to-one function-file thing.  You tell 
me that
there is this function name - file name requirement but then violate that
commandment by packing in several functions to one .zwc.  I get that if 
a script
is autoloaded it will/must be 'named' after the file it came from. One 
script!
But with functions?  The rule is not followed.

> 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.
Well therewego.  Previously you're saying that these .zwc should not be 
in the same
dir, now they should be in the same dir. Nuts, they are created in the 
same dir.  I
tested that by touching the files--as you say, it finds the newest. But 
then you tell
me that best practice is to move the thing :-(  And, speaking of 
philosophy, here
is a case of hand-holding.  The first command found on the path is the 
one used,
and too bad for you if a newer version exists somewhere lower down. It 
doesn't
scan the whole path and load the newest file.  I'm expecting that if I 
autoload
something then it's active and too bad if there's a newer file:

     $ autoload my_function
     $ source /functions/myfunction

... I get the sourced version.

     $ source /functions/myfunction
     $ autoload my_function

... I get the version in the .zwc  found on FPATH.  If I want the newer 
version
then I should source it.

>
> (**) "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.
>
When I revisit this, I'll read your posts backwards.  This one is the 
one that would come first
in the HOWTO.  The first thing to understand is why, when and where we'd 
want to
use autoload.  What is it for?  Why did God make it on the seventh day?  
Then, it's
constraints and why they are what they are, then the implementation with 
examples.

Looking back, I've misunderstood the whole point of the thing.  Like the 
C-head
that I am, I'm thinking: 'What a good idea!  We can boil down our 
functions to
'.obj' files for faster loading, pack them together into one file for 
more speed yet, and
best of all, have them unloaded in memory until they are actually called 
at which time
they are 'autoloaded' automagically.  How elegant, I says to myself, 
it's like a .zip--all
compressed and packed together, and just as you can extract a single 
file from a .zip
so you can source a single function from a .zwc and zsh will even do it 
automatically
for you if you autoload that function cuz zsh will keep a table of where 
that
function is found and source it only when you call for the function.

It's all Sebastian's fault ;-)

Seriously sir, I exhaust your patience.  For now the one thing I know is 
that I don't
want to autoload anything, it's too obscure.


  reply	other threads:[~2015-09-22 17:33 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-17 15:54 autoload Ray Andrews
2015-09-17 17:34 ` autoload Bart Schaefer
2015-09-17 19:22   ` autoload Ray Andrews
2015-09-17 20:40     ` autoload Bart Schaefer
2015-09-17 23:06       ` autoload Ray Andrews
2015-09-17 23:20         ` autoload Bart Schaefer
2015-09-18  1:20           ` autoload Ray Andrews
2015-09-18  4:04             ` autoload Bart Schaefer
2015-09-18  5:00               ` autoload Ray Andrews
2015-09-18  5:52                 ` autoload Bart Schaefer
2015-09-18 15:49                   ` autoload Ray Andrews
2015-09-18 16:52                     ` autoload Bart Schaefer
2015-09-18 18:29                       ` autoload Ray Andrews
2015-09-18 19:02                         ` autoload Bart Schaefer
2015-09-18 22:57                           ` autoload Ray Andrews
2015-09-19  0:14   ` autoload Bart Schaefer
2015-09-19 15:04     ` autoload Ray Andrews
2015-09-19 16:29       ` autoload Bart Schaefer
2015-09-19 18:13         ` autoload Ray Andrews
2015-09-19 21:22           ` autoload Bart Schaefer
2015-09-19 22:12             ` autoload Ray Andrews
2015-09-20  5:53               ` autoload Bart Schaefer
2015-09-20 15:37                 ` autoload Ray Andrews
2015-09-20 15:59                   ` autoload Bart Schaefer
2015-09-20  0:58             ` autoload Ray Andrews
2015-09-20  5:41               ` autoload Bart Schaefer
2015-09-20 23:21                 ` autoload Ray Andrews
2015-09-21  4:18                   ` autoload Bart Schaefer
2015-09-21 17:03                     ` autoload Ray Andrews
2015-09-21 18:17                       ` autoload Bart Schaefer
2015-09-21 20:09                         ` autoload Ray Andrews
2015-09-22  3:19                           ` autoload Bart Schaefer
2015-09-22 17:33                             ` Ray Andrews [this message]
2015-09-23  4:39                               ` autoload Bart Schaefer
2015-09-23 15:06                                 ` autoload Ray Andrews
2015-09-29 23:16                             ` wheels within wheels Ray Andrews
2015-09-30  2:55                               ` Kurtis Rader
2015-09-30  3:24                                 ` Ray Andrews
2015-09-30  3:40                                 ` Bart Schaefer
2015-09-30  4:03                                   ` Mikael Magnusson
2015-09-30  4:15                                   ` Ray Andrews
2015-09-30  7:05                                     ` Bart Schaefer
2015-09-30 15:06                                       ` Ray Andrews
2015-09-30  8:01                                     ` ZyX
2015-09-30 15:18                                       ` Ray Andrews
  -- strict thread matches above, loose matches on Subject: below --
2015-09-08 12:32 Announce of Zsh Navigation Tools Sebastian Gniazdowski
2015-09-12 17:50 ` Ray Andrews
2015-09-12 19:41   ` ZyX
2015-09-12 21:03     ` Ray Andrews
2015-09-12 22:10       ` Bart Schaefer
2015-09-12 23:03         ` Ray Andrews
2015-09-12 23:43           ` Bart Schaefer
2015-09-14  2:14             ` autoload Ray Andrews
2015-09-14  2:38               ` autoload Bart Schaefer
2015-09-14  3:34                 ` autoload Ray Andrews
2015-09-14 20:21                   ` autoload Bart Schaefer
2015-09-15  2:48                     ` autoload Ray Andrews
2015-09-15  3:48                       ` autoload Bart Schaefer
2015-09-15 16:18                         ` autoload Ray Andrews
2015-09-16  4:09                         ` autoload Ray Andrews
2014-12-23 15:51 autoload Ray Andrews
2014-12-23 17:36 ` autoload Bart Schaefer
2014-12-23 18:19   ` autoload Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=560190F4.8020404@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).