From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 1442 invoked from network); 24 Mar 2022 17:09:44 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Mar 2022 17:09:44 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1648141784; b=S4jE51PKqODrUS0xXjKGtIHaIhL0DWE1mJ0CAVjG5uKavwZCqxwJPaV2tGjxF9rqD/oAzPxxEa J17K8NWxDDwE+nlKlQK+kOa3PtmrPvClGKCpUM7IzQp8z9k95p2r5PCUzrPMAoYssu5RSRsNq1 YrJfltkYAJs1+2M70j7sAgcMsYQNW9oErG5jxR5Dxq6DwWInO8t//FfUp5oSJtE0C80ns8ZZ6r LdxUwBO4d8IJXp246Fq1xD3pZkq6K6aGtEZZExq6qaOW4vsoOINLMHmP0gPAkTE5FoIAHOw7Pg ADdViRrENTjC1U2F1SHDOm9BnrDI12cFiB1pCmVophN5pg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1648141784; bh=poMCX8J4cNUX3Eai5C+Yh/ex3RA1oexkFoUSeOGQfss=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject: References:In-Reply-To:Message-ID:To:From:Date:DKIM-Signature: DKIM-Signature; b=Lz5DDMy8ohsRYeWBAQ0a+fde7BLBcA6asfRKWwbrGgxIrzs0NsQsyLXDGfoBT/kwe/ooS1vUds itYotn/nyRL5f+OEM9FcBQY+tSoMpKPH1TAsGUjU9/NaAENDQr6CNsvoQndmZp3mC1Gz9XZ7MG JxPPRvPEq/WAtAaThkdVjjIBYujXJeukQNImFMhlzMgKaC+P939jpZQ83c8VbucIcPhVR7o44f 264kZCodLZtO9XJK74BZUBG67wnvMazvYY7v2LBjqFMLtNz3mOmMQL2mxvslPZbcJAENkIuhfA s3pZyMkR7wiSqgaxhWDUr6NEIYw8gkQrlL6Umz9J46pKPw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID:To:From: Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=lFICsuORHto6j8qQqxAS3hFbxTtdRXFlm/Z2vOovPwY=; b=M2MYbpAAkOUBqGyKlqvYLV9kRX X/GQ00OprztP+cxn1aHRWy/lAvQZImi7Hlerc62Zac9GIwGqIkWIxEcFJTalzURjjtm1yQiq9OLee Y4WKwsGficvbnrG2MSgB/o2WEXkfad6PhC7J7XwqeuFMybjt/Ak2iUrsL9IHnqOs5MN8yvEescssr p5DOY+zxg3cEUsMtZK84SaWC7IykDYqpb5k6ayazefRnzpqTGtY6WEO8lim8l8QsTWG1bJ0jhat4n vQ71Y+Egnkk/k0/XHf6G1mRmfsN4OsbheXS5J8N28edsLz+K35wgIl1ykCHiFk5Kn6h4GNM6kuzAP 2xRcv3wA==; Received: from authenticated user by zero.zsh.org with local id 1nXQxz-0004e0-Rf; Thu, 24 Mar 2022 17:09:43 +0000 Authentication-Results: zsh.org; iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none Received: from smtpq1.tb.ukmail.iss.as9143.net ([212.54.57.96]:57010) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1nXQu2-0003eg-Bu; Thu, 24 Mar 2022 17:05:39 +0000 Received: from [212.54.57.81] (helo=smtp2.tb.ukmail.iss.as9143.net) by smtpq1.tb.ukmail.iss.as9143.net with esmtp (Exim 4.90_1) (envelope-from ) id 1nXQu2-00034I-3S for zsh-users@zsh.org; Thu, 24 Mar 2022 18:05:38 +0100 Received: from oxbe25.tb.ukmail.iss.as9143.net ([172.25.160.156]) by smtp2.tb.ukmail.iss.as9143.net with ESMTP id XQu1nCYWtfHYvXQu2nHwqn; Thu, 24 Mar 2022 18:05:38 +0100 X-Env-Mailfrom: p.w.stephenson@ntlworld.com X-Env-Rcptto: zsh-users@zsh.org X-SourceIP: 172.25.160.156 X-CNFS-Analysis: v=2.4 cv=Wbkf1mtX c=1 sm=1 tr=0 ts=623ca4e2 cx=a_exe a=NA7IgXeTfPXpJV+SL5V8Rw==:117 a=wbvTLvLwOfMA:10 a=IkcTkHD0fZMA:10 a=7H6ixmLU1AQA:10 a=pGLkceISAAAA:8 a=2-v7tjS9jjPu28lRP2QA:9 a=QEXdDO2ut3YA:10 X-Authenticated-Sender: p.w.stephenson@ntlworld.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntlworld.com; s=meg.feb2017; t=1648141538; bh=poMCX8J4cNUX3Eai5C+Yh/ex3RA1oexkFoUSeOGQfss=; h=Date:From:To:In-Reply-To:References:Subject; b=fsBA0Y1pkt4TquWXWY8cI0vWnj2Mmz5IoS2fZQ9g4xrd1xxM122HLxv53fQtjrS8R RlobIeJp2/ycdM49cDQnwio+efReL7aif/n2/Bb06lQwtrLaRU0mEIC5CA+SzLih6i oIqHrASpQ4BQUxFuh90pufBoVfLkbp/cJnnmGBhQTQEz7eoOEGWsHOz27l4lEa5mPX tNllLZqqYIu5NOyVn4ds8l7LlK8K0xD4jCGFGSiEua10WSHtq3Kfp4fesbDzqI6I2I mlAjHxfULpE63ewMMKe61rKEwzpYWoqoWFepLMORO9jLNTmBxBB91MHCzmHWgjVeJG 8DJHPaZKnAGmA== Date: Thu, 24 Mar 2022 17:05:37 +0000 (GMT) From: Peter Stephenson To: Zsh Users Message-ID: <306931674.638268.1648141537809@mail2.virginmedia.com> In-Reply-To: References: Subject: Re: Load autoloadable function, but only in enclosing function scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.8.4-Rev72 X-Originating-IP: 147.161.167.85 X-Originating-Client: open-xchange-appsuite X-CMAE-Envelope: MS4xfOTIrzp+eVuLVoqH3pJqaL+4QOm7xBYk8gVQutdPtNGoNhhh0tkkEnYhtnFap6zYOp3HqOoZTdJRal7E4FcKuDaKRCGaLbr4SO72knxPcC/0CPRC/loz h5YkFE9GSYLIhjrQLkKwZzwMQrzFRGgAqxu/BJW3tpiyghdrn5NSEIJP2ScUJdHbUHqYROw7tDG3BU42jaMBL2eLDouG8wf+0ux8MhQouyveeTpXUdnkd4Q+ X-Seq: 27611 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: > On 24 March 2022 at 16:29 Mikael Magnusson wrote: > On 3/24/22, Zach Riggle wrote: > > Is there a way to > > > > myfunc() { > > autoload foo && foo > > } > > > > Such that foo and any other functions it declares are local-scope only? > > Functions are never scoped at all, so no. You can manually unfunction > it afterwards (if there was already a function with a conflicting > name, autoload returned success and you ran the wrong function > anyway). If you don't need any other side effects from myfunc, you can > run the whole thing in a subshell of course. With that key limitation --- if you've already got functions with the names of the ones you're creating, you're stuffed --- you can automate it like this. fn() { local -a oldfuncs=(${(k)functions}) { # as a working example --- "autoload subfunc" would work fine subfunc() { print This is subfunc; } subfunc } always { local -a funcs=(${(k)functions:|oldfuncs}) (( ${#funcs} )) && unfunction $funcs } } Note that this won't unfunction subfunc even if it was previously marked for autoload, but not actually loaded. (In any case you'd probably want to mark it for autoload again, to be consistent, so that's an exercise for the reader.) If your functions are all being autoloaded, and your only interest is in getting rid of functions that you've autoloaded specially for this function --- so there's no actual name clash, you just might have already marked the function for autoload and it'll stay loaded --- that might be good enough. pws