Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
zsh at perl conference and few questions
- X-seq: zsh-users 23361
- From: Marc Chantreux <eiro@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: zsh at perl conference and few questions
- Date: Mon, 23 Apr 2018 11:24:12 +0200
- Dkim-filter: OpenDKIM Filter v2.10.3 aurora-borealis.phear.org 730AFFFBB
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=phear.org; s=20180217; t=1524475454; bh=SPr0IHEqCRfjRd/O9BtwOO3wS7nQSxYv4NM02gUejUE=; h=Date:From:To:Subject:From; b=jBXzmWUulKIGJ8VaV25khpDZ0WtZfwjKHbdpcCPDzmp9OAmojLZrnAnwv5uX1V4Nv pVLV9p3icoctWmP8zp99XXXWQkvGt87Lg2TRyBA8PCXCAx8P/4DRZ2IXmKuwqYnSyn Ghjxq2A7YjBU6hucysyeA8OTrdNaNEazrR085+WPl4U9/wi/sgIewS3uISvx6CF/ua GFAIlJBEw2LNUE+2bp61kZ+8I9pwNc/JYKsF7EdClUIKMCSAbCSy7FS2Aulsvjvvtj DA3pUyRuJPUSqDtO2T4naFNeTUchbn5IsMax5Xd1WSpHKVVv8flurhOw4dXRPDNFQp iCCuH5YNMeP+Q==
- 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
hello people,
i'm happy to annonce i'll talk about zsh during the european edition of
the perl conference (glasgow)
http://act.perlconference.org/tpc-2018-glasgow/talk/7338
as i prepare my slides those days, some questions came to me. some of
these are (detailed below):
a) can someone tell me why isn't the "alternative" syntax more used ?
b) why the while loop can't take (( )) or single instruction as do list ?
c) it seems the (+) syntax can't be used outside file expansions
d) is there a plan to have something like namespaces ?
any comment/feedback/thought would be really appreciated.
regards
marc
a) can someone tell me why isn't the "alternative" syntax more used ?
i felt in love with zsh about 20 years now and one of the reason is
the alternative syntax. so can someone explain to me why the "old"
one seems to be prefered even nowdays ?
for x in {1..20}; do
print "$x * 2 = $[x * 2]"
done
seems terrible to me compared to
for x ({1..20}) print "$x * 2 = $[x * 2]"
as time passed, i added those alias in my .zshenv
alias @='for it'
alias @-='while {read it}'
so i daily (hourly ...) write those kind of thing
@ (*.txt) gzip $it
b) why the while loop can't take (( )) or single instruction as do list ?
those works fine
if {true} print ok
if (( 2 == 2 )) print ok
for ((count=3; count; count--)) print $count
while ((count)) {print $[count--]}
so why not those ?
while ((count)) print $[count--]
while {read it} ((sum+=it))
c) it seems the (+) syntax can't be used outside file expansions
(or did i miss something?)
as you can write
by_word_count () REPLY=$( wc -w < $REPLY )
print -l *.html(.o+by_word_count)
why shouldn't i write
by_word_count () REPLY=$( wc -w < $REPLY )
files=( *.html(.) )
print -l ${(o+by_word_count)files}
or filter with something like
large () (( $( wc -w < $REPLY ) > 200 ))
files=( *.html(.) )
print -l ${(+large)files}
d) is there a plan to have something like namespaces ?
using setopt pathdirs, you can put functions into files
in your path and reuse the name of it into the function
names. i use it to create a poor man namespace.
so if i have net/utils in my path i can fill it with
net/utils/running\? ()
ping -W 1 -c 1 ${1?ip or hostname to ping} \
&> /dev/null
net/utils/report () {
local status="missing"
net/utils/running\? ${1?ip or hostname to ping} &&
status="online"
print -u2 "$1 is $status"
}
so now i can write
$ . net/utils
$ net/utils/report prometheus
prometheus is online
in uze.zsh, i created something to export a function into the main
namespace (just copy the values of $functions )
so i can write
$ . net/utils report
$ prometheus
prometheus is online
so for the user of the net/utils lib, that's fine ...
*but* when i write functions, i have to be careful about
the current namespace. the thing i dream about is the ability
to rewrite
net/utils/report () {
local status="missing"
net/utils/running\? ${1?ip or hostname to ping} &&
status="online"
print -u2 "$1 is $status"
}
as "the report function of this namespace"... if a // prefix
could exist, i could write something like
//report () {
local status="missing"
//running\? ${1?ip or hostname to ping} &&
status="online"
print -u2 "$1 is $status"
}
this should be awesome but i don't know if realistic as zsh
don't have syntax closure as well.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author