From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7414 invoked by alias); 30 Apr 2018 13:00:17 -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: List-Unsubscribe: X-Seq: 23377 Received: (qmail 1963 invoked by uid 1010); 30 Apr 2018 13:00:16 -0000 X-Qmail-Scanner-Diagnostics: from aurora-borealis.phear.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(94.242.205.164):SA:0(-1.9/5.0):. Processed in 3.548696 secs); 30 Apr 2018 13:00:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: eiro@phear.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: amavisd-new at phear.org DKIM-Filter: OpenDKIM Filter v2.10.3 aurora-borealis.phear.org B239F1059D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=phear.org; s=20180217; t=1525092763; bh=gD/gmkbC6awH7N3W0UZIORtadaPoHDPCyrCfyssGePk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Z74jyj7AK+XXrUZ5WVBrR3j9hG0CTKyVb3h8zgng1Y85M0FH9S4ZA1fC5kEi08ZIa Am819eF77oxgaWV2Apa0WjJU6mJvE8XgUM4Rqz2EJb4h75DOMslUOwXSku3XXknj1a 7D+c3Rqp+ZFO2b/t2bCd2LnavYAKDo5ds0/1YKNUtz3pfWpXY8hZalJ6jCOj5g0LCW vgcl05KgqC5z/GwA6QoGrAVEdr52uDDijOOSSzWcvJJiV0vnh0xwcBUdcGzNeGE+26 Wb6NOH/C7DIFZHEXcbfRqsmY41TlsANonqjkGyVVLfI7FS+FlS6j2qVERN7oTbS1Xb N+E4qJFYvPMnQ== Date: Mon, 30 Apr 2018 14:52:42 +0200 From: Marc Chantreux To: Sebastian Gniazdowski Cc: Peter Stephenson , Zsh Users Subject: Re: zsh at perl conference and few questions Message-ID: <20180430125242.GA6979@prometheus.u-strasbg.fr> References: <20180422204849.GA30387@prometheus.u-strasbg.fr> <20180423110642.0e0a5ebe@camnpupstephen.cam.scsc.local> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) hello, > It's an occasion to me to tell the observation that function namespaces > would be rather more needed than variable ones. yes, i really asked for namespaces in functions. > plugins like z-sy-h and zsh-autosuggestions copy each widget to hook into > it. So it's ${#widgets}**2 functions out there with those plugins loaded, > and times of "lets see my functions print -rl -- ${(k)functions}" are over. this is the same situation in the uze exporter mechanism and as i said: from the "user" counterpart, everything is ok: uze TAP :all boolean_works () { true ; ok "true is right" : ; ok ": is right" ! false ; ok "false is right" } prove boolean_works renders ok 1 - true is right ok 2 - : is right not ok 3 - false is right 1..3 works because there is a TAP.zsh somewhere in $path that * implements TAP/{ok,prove} * implements uze/export/TAP populating a local variable used by the exporter EXPORT_TAGS=( :all 'prove ok not_ok plan is isnt note note- expected unexpected' ) so when you do uze TAP :all which prove TAP/prove you get prove () TAP/prove "$@" TAP/prove () { typeset -A TAPCTX=(index 0 start 1 plan 0) TAP/start "$@" TAP/done } the boring part is for the implementor: to be consistent, the file this/very/long/and/boring/ns.zsh will contain this/very/long/and/boring/ns/foo () { this/very/long/and/boring/ns/bar echo bye } this/very/long/and/boring/ns/bar () { echo hello } with namespaces, it will contain //foo () { //bar echo bye } //bar () { echo hello } and this should be renamed simply. note that if zsh had closures, we could use the same hack the javascript world use. () { my _P=this/very/long/and/boring/ns $_P/foo () { $_P/bar ; echo bye } $_P/bar () echo hello } which leads me to the real motivation of this mail: zsh is realllly powerfull and simple and in many circonstances, it could be used instead of interpreted langages like python, perl, ruby. some claim that shell miss nested data structures which is right but there are workaround (or alternate way of thinking ?) We have persistant(sic) objects, they’re called files. — Ken Thompson i put a demo here http://eiro.github.io/unix/zsh-oo-demo.txt. when it comes to variables, what i miss the most are lexical variables and closures. see, this code () { local x=12 plus () l $[x++] minus () l $[x--] } plus raise an error message because plus:6: numeric parameter x created globally in function plus and the output is 0 the perl behavior (and recent versions of javascript) is much more superior on this part: * local localize a variable (the way zsh does) * my create a lexical variable * whenever a lexical variable of a scope is used inside a function definition, this create a state preserved through function calls in zsh, it could be counter () { my x=${2-0} $1/+ () { let x + $1; echo $x } $1/- () { let x + $1; echo $x } } counter c 2 c/+ 2 to return 4. this case is obviously useless because it's about one variable but it could be a way to capture a complex context. for the moment, the only way to do this is to create subshells and fifo to have coroutines. but it can be painful to write. i don't know how much this topic is relevent to zsh implementation but i really think closures and namespaces are the 2 missing features to make zsh reasonable on larger codebases. plus: we need something like cpan (https://metacpan.org/) or or pypi, crates, epm, ctan, npm, ... regards marc