From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24487 invoked by alias); 30 Sep 2015 02:55:40 -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: 20661 Received: (qmail 4325 invoked from network); 30 Sep 2015 02:55:38 -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,HTML_MESSAGE 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:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Lt/8qFjMd//9JBrUKN4/6PxTET1AKiPWmUjuDFH0N1M=; b=CsYkSE4TFcPBlKH1GHxYPfgpL/a+h7maWgV75B1KPa/db3arwJqUK753+h7l5ZcS66 +/kjJDdyYk0l4hicGRyFqrwFBmQ/H2RVzK4n+GsrF4WQYU7AX66/B1M92MNBdxO+bAhV xoF0LZOKD5ivb3KnySgeuKE6QC+bTDTXUmVrblEe4cRFCddnxugJD5boCVo/7B7+VCrl YD43wcT+8Cvi3enzHPneR6KuYo2ISDMZubqoKEuDOZKqGRD5jutrFkhW+PJVC105MnZP 7IspEfAUpBB4Q7PKEntUa+PkD98H8wNGqt9w4MboHvrrPjus02nc1QPKQXDF0rWgwPBE 7NLw== X-Gm-Message-State: ALoCoQlsoLqFQQmH/nvP7Qny7pdqXF+kUoiuzhC0M+Wkbv19RHVsIRKbQU89Jze/lIIOwjoadULR MIME-Version: 1.0 X-Received: by 10.140.237.209 with SMTP id i200mr1559195qhc.92.1443581736513; Tue, 29 Sep 2015 19:55:36 -0700 (PDT) In-Reply-To: <560B1BE7.8020507@eastlink.ca> 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> <150921201943.ZM707@torch.brasslantern.com> <560B1BE7.8020507@eastlink.ca> Date: Tue, 29 Sep 2015 19:55:36 -0700 Message-ID: Subject: Re: wheels within wheels From: Kurtis Rader To: Ray Andrews Cc: Zsh Users Content-Type: multipart/alternative; boundary=001a113589e49c0bcc0520ee10a6 --001a113589e49c0bcc0520ee10a6 Content-Type: text/plain; charset=UTF-8 On Tue, Sep 29, 2015 at 4:16 PM, Ray Andrews wrote: > I just learned that it's possible to declare a function within another > function. A strange liberty. Why would one want to, and what are the > gotchas of doing so? > Many compiled languages support the concept of "closures". Even those, like Python, which are compiled on the fly into byte-code as they are executed. On the other hand zsh, and in general any shell, based on bash or csh do not support closures or namespaces so I have no idea why someone would nest function definitions in those shell languages. Google "zsh closures" and read this answer: http://unix.stackexchange.com/questions/94129/is-there-something-like-closures-for-zsh In short: don't do it. You can see for yourself that nested, named, function definitions are in fact globally visible (as opposed to visible only to the function in which they're defined) by executing the following script. Anonymous functions defined within another function are a different matter but outside the scope of this question. I've seen some pretty amazing bash/csh/ksh/zsh scripts in my life. Including one that implemented an assembly language compiler. But if you need that level of complexity you should be using a different language. If the only tool you know how to use is a hammer then every problem looks like a nail. #!/bin/zsh function foo { function bar { echo hello from bar } echo hello from foo bar } echo calling foo foo echo calling bar bar -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank --001a113589e49c0bcc0520ee10a6--