[Top][All Lists]

[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: Tue, 31 Jan 2012 15:52:54 -0600
User-agent: KMail/4.7.4 (Linux/3.1.6-pf; KDE/4.7.4; x86_64; ; )

On Tuesday, January 31, 2012 03:21:02 PM Peng Yu wrote:
> I don't see why closure can not live with current features of bash.
> JavaScript has both local, global variables and closure. I don't think
> that you statement that bash will be broken if closure is added is
> necessarily true. So I will ignore your any further arguments down
> below unless you can prove you statement.
> Also, my philosophy is that no language is static, to improve
> languages it is worthwhile to scrutinize the pros and cons of various
> features. Many languages have changed dramatically over the last a few
> years. Many code written for older versions has to be updated to catch
> up with latest development. There is no reason that bash should not be
> improved just because bash should be 100% backward compatible.
> I'd like to contribute to bash by raising questions to discuss various
> potential features. No matter whether they will accepted or not, I
> believe it worthwhile for discussion, isn't it?

You don't seem to be grasping that Javascript is a very functional language. 
Bash is not. Did you read my previous post? The problem is not so simple as 
"bash lacks support for closures". The shell's notion of what a function is is 
fundamentally incompatable with the notions that make closures useful in other 

All you're talking about here is "partial function application" which this 
isn't really a direct analogue of because you still can't access nonlocal 
positional parameters (short of BASH_ARG{V,C} cheating, which you would need 
to know to enable in advance). That's a very limited use case - The vast 
majority of what closures are really useful for (implementing thunks, 
continuations, currying, various abstractions for code reuse) still don't jive 
with this.

Here's a Korn shell "closure" of sorts. Notice illustrating the difference from 
Bash requires two different kinds of function definitions:

$ ( f() { typeset x=5; function g { echo "$x"; }; }; f; g; )

And this alone still doesn't allow you to do very much which you can't already 
do in Bash due to the way scoping works - using the context at the time the 
function is called.
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]