zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.auc.dk
Subject: A few words about kshautoload
Date: Tue, 1 Aug 2000 07:53:01 +0000	[thread overview]
Message-ID: <1000801075301.ZM30126@candle.brasslantern.com> (raw)

I was reading a posting on comp.unix.shells a few weeks ago in which the
author was explaining that it's possible to implement job control and a
number of other "advanced" shell features by appropriate programming of
pure Bourne shell.  (If I recall correctly, the only concession was that
the shell had to implement user-defined functions if you didn't like to
call your shell functions with a leading `$' on the name.)

Probably it should have been obvious to me before, but it took reading
this article to make me realize that the ksh autoloading model is designed
so that the files can be parsed with the `.' command without the result of
executing the function body in the context of the caller.  Because in the
absence of an `autoload' builtin, the way to implement your own autoloader
is to create function stubs that read in the "real" definition with `.',
and then call the redefined function iff the parse is successful.

Thus in ksh the autoload command is nothing more than a conversion of a
useful scripting idiom into C code, and uses the syntax of the original
shell programming technique.

Zsh, on the other hand, takes the view that the files should be executable
as standalone shell scripts.  This spoils the `.' trick, because the code
begins executing immediately; you don't get to attempt a full parse first.
You can still implement your own autoloader if you're willing to scarf up
the whole file into a parameter and `eval' it, but it's messier than the
ksh-equivalent version.  In the zsh model, autoload can be efficient only
as a builtin.

Which is why we needed to invent `autoload -X' and `autoload +X', and is
also why those options work badly-if-at-all for kshautoload-ed functions.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


                 reply	other threads:[~2000-08-01  7:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1000801075301.ZM30126@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).