From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26173 invoked by alias); 22 Sep 2015 03:19:53 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20619 Received: (qmail 28482 invoked from network); 22 Sep 2015 03:19:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=y4KanxeoG7kkrXvWFrOBMVofSuYkSiI++9McyumLm7I=; b=iW8GKS7CDZpTrP2Hp0j80I7IBB3F9iQwQgxhWS8Zu1JFvMxMKWO38NyDw/Chu9QjdL 1+2dLmJNOHPVbHrPGyESqzxfQk0qk/RpOE/No6ZXMpO8esDXF1cGo6cJ/xlgg7/kCJHY lA0VL5TwK7qF1s5nftKVUviysiTG0ao3Qp02BRScI26aA7ay/CcryFTRuRrUEiqs/LLb MEGFmO0NL0Ss7FtLkD20sHkcigdEZ06tWqbYeM89Ped0riyKG16logABB7YgatUBlNHw ayPaU7XUyWTRe3pTaPUOT7Wqbt1lgJiNAjwcOVZMtrKqcL/winAtglMTaCfgHQwiLdJZ MVRw== X-Gm-Message-State: ALoCoQnPjkIu7DiCZOHw1EyMMujxohuRKzV5wMi1PycerbGMtsqEYsmPs5m/KCbygmGWCBKg7JE1 X-Received: by 10.60.45.201 with SMTP id p9mr13436766oem.22.1442891987302; Mon, 21 Sep 2015 20:19:47 -0700 (PDT) From: Bart Schaefer Message-Id: <150921201943.ZM707@torch.brasslantern.com> Date: Mon, 21 Sep 2015 20:19:43 -0700 In-Reply-To: <56006401.5060902@eastlink.ca> Comments: In reply to Ray Andrews "Re: autoload" (Sep 21, 1:09pm) References: <55FAE223.2080502@eastlink.ca> <150917103419.ZM10067@torch.brasslantern.com> <150918171441.ZM27212@torch.brasslantern.com> <55FD7982.9030505@eastlink.ca> <150919092922.ZM28214@torch.brasslantern.com> <55FDA5D3.9020304@eastlink.ca> <150919142243.ZM23634@torch.brasslantern.com> <55FE04AD.1070304@eastlink.ca> <150919224120.ZM4736@torch.brasslantern.com> <55FF3F7E.4060906@eastlink.ca> <150920211840.ZM31871@torch.brasslantern.com> <5600386E.7060201@eastlink.ca> <150921111746.ZM388@torch.brasslantern.com> <56006401.5060902@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: autoload MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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.