zsh-users
 help / color / mirror / code / Atom feed
From: Marc Chantreux <eiro@phear.org>
To: Zsh Users <zsh-users@zsh.org>
Subject: zsh at perl conference and few questions
Date: Mon, 23 Apr 2018 11:24:12 +0200	[thread overview]
Message-ID: <20180422204849.GA30387@prometheus.u-strasbg.fr> (raw)

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.


             reply	other threads:[~2018-04-23  9:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180423093610epcas4p2248cf6f0e76bd3e81ff6fa0ef55f5c25@epcas4p2.samsung.com>
2018-04-23  9:24 ` Marc Chantreux [this message]
2018-04-23 10:06   ` Peter Stephenson
2018-04-28 10:14     ` Marc Chantreux
2018-04-30  3:30     ` Sebastian Gniazdowski
2018-04-30 12:52       ` Marc Chantreux
2018-04-30  5:28     ` Bart Schaefer
2018-04-30 12:57       ` Marc Chantreux
2018-04-30  3:06   ` Sebastian Gniazdowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180422204849.GA30387@prometheus.u-strasbg.fr \
    --to=eiro@phear.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).