Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Repeat argument N times?



# p.stephenson@xxxxxxxxxxx / 2014-07-30 09:56:57 +0100:
> On Tue, 29 Jul 2014 23:48:30 -0700
> Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > There are other ways, e.g.
> > 
> >     upload-files file2(e{'repeat 10 reply+=($REPLY)'})
> > 
> > though the latter requires "file2" to actually exist, which sometimes
> > might be a good thing.
> 
> If you don't mind a limited repertoire of counts explicitly constructed,
> you can make this method look close to what you want.
> 
> % define-x() { eval "x$1() { typeset -ga reply; repeat $1 reply+=(\$REPLY) }" }
> % define-x 3
> % print .zshrc(+x3)
> .zshrc .zshrc .zshrc

it looks like the alternative syntax permits generalization:

  function x
  {
    typeset -ga reply
    repeat $1 do
      reply+=($REPLY)
    done
  }

  print :)(e:x 3:)
  print :)(e:x 30:)

-- 
roman



Messages sorted by: Reverse Date, Date, Thread, Author