help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Closure concept in bash


From: Dan Douglas
Subject: Re: [Help-bash] Closure concept in bash
Date: Sat, 28 Jan 2012 15:25:52 -0600
User-agent: KMail/4.7.4 (Linux/3.1.6-pf; KDE/4.7.4; x86_64; ; )

On Thursday, January 26, 2012 11:39:47 PM Peng Yu wrote:
> Hi,
> 
> I'm wondering if there is any concept like closure in bash.

Bash functions (and most shells with locals) always are scoped based upon 
where they're called. There's no way of emulating closures and continuations 
short of saving the entire environment and then sourcing it later (probably in 
a subshell). Given how limited functions are to begin with in terms of 
"passability", I can't think of many cases where it would be useful without  
modifying a whole lot of other things about how functions work.

An exported function doesn't come packaged with the environment in which it 
was declared or exported. Exported functions are really only useful to avoid 
having to redefine them in child shells. I mostly use them for testing small 
things and almost never in a useful script.

Newfangled ksh93 user-defined types probably give you some function-object-like 
behaviors you might use. I haven't tested them extensively.

-- 
Dan Douglas

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]