Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Local inner functions
- X-seq: zsh-users 15888
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: René 'Necoro' Neumann <lists@xxxxxxxxx>
- Subject: Re: Local inner functions
- Date: Thu, 24 Mar 2011 12:51:19 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=6xv6W/Dn5pRXBgshz8NPaV85auRPX0QyWjNYgJv9OI4=; b=oiIRh53MVS1YdRIlpmpV0QfvBVDznLEJIufd7FgS1+Ags/yoy92oLAiXJvGC9diqZb /6clYPANIKxUSb6bGaU2CogDSy/HK/uYQn9MtLj2VqyQpZ+pcCgK50Fnu3tlZFt6YdhZ K7voQRflDjvRLAjnEKeynjB6MLouu3EOL1eCE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=f43o7l+ziLtpkXY9843EzKW+Cl7wkDy6nMrEjyxBlIPmf4T0ccXIS7IhU+PCRw41Gf PCLDW8Ei7ck7sYZKJ7A326sgNfC4We/OHnYUrPjvIZyZkOhOWuS+OTiRmMT3DDEwLuEA vEr38BhG6niL4wun8LiHlGflgrjj45Rmx4gzg=
- In-reply-to: <4D8B1128.2090405@necoro.eu>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <4D8A810A.3050300@necoro.eu> <AANLkTinognOPQLV6xYNwuqJPJ=bHKs+AOM=suvz7MFY3@mail.gmail.com> <4D8B1128.2090405@necoro.eu>
On 24 March 2011 10:38, René 'Necoro' Neumann <lists@xxxxxxxxx> wrote:
> Am 24.03.2011 02:41, schrieb Bart Schaefer:
>> On Wed, Mar 23, 2011 at 4:23 PM, René 'Necoro' Neumann
> <lists@xxxxxxxxx> wrote:
>>>
>>> foo ()
>>> {
>>> bar () { }
>>> }
>>>
>>> Is there some way of making 'bar' to be local to 'foo'? Using the
>>> 'local' keyword does not work :).
>>
>> The short answer is "no." And you can't make local aliases either.
>>
>> The slightly longer answer is that there are a couple of ways to fudge
>> it, of varying degrees of hackishness.
>
> Thanks for your answer. Instead of your 'always'-block, I tried
> trap 'unfunction bar' EXIT - but of course this is no good in case of
> name clashes :).
>
> So, if nothing like this really works (and local functions are not been
> to be implemented into zsh), I'll just use the $0_bar approach (wasn't
> aware of this), to at least reduce the chance of clashes.
If your function doesn't need to modify the parent environment in any
way, you can simply run it in a subshell:
function bar() { echo stuff }
function foo() {
(
function bar() { echo whatever }
bar
)
}
foo
bar
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author