Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh at perl conference and few questions
- X-seq: zsh-users 23377
- From: Marc Chantreux <eiro@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Subject: Re: zsh at perl conference and few questions
- Date: Mon, 30 Apr 2018 14:52:42 +0200
- Cc: Peter Stephenson <p.stephenson@xxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- 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==
- In-reply-to: <CAKc7PVAMYg0ALgaFSiLReJydBQFN5_-BFX2WU90MpS=YO6Hbog@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CGME20180423093610epcas4p2248cf6f0e76bd3e81ff6fa0ef55f5c25@epcas4p2.samsung.com> <20180422204849.GA30387@prometheus.u-strasbg.fr> <20180423110642.0e0a5ebe@camnpupstephen.cam.scsc.local> <CAKc7PVAMYg0ALgaFSiLReJydBQFN5_-BFX2WU90MpS=YO6Hbog@mail.gmail.com>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author