From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26404 invoked by alias); 31 Jul 2014 15:59:34 -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: X-Seq: 19003 Received: (qmail 20698 invoked from network); 31 Jul 2014 15:59:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Fb90kEM5pU1rpHi4L8ynMfgjflVFaLKTD9E5TzJ1o+o=; b=wNpH9NpH4Fo/MMi6gnIHXEDUCcC55930wZ1A+6fcbUuc5UCxjYBTVi7on1/73buWaz tKt69z7mF4udOFRBLiZQLZoKVdS8q5ozNJOJnp1Lu2rOIDKfvCtqIUCeVBuF9VlxUKKS HwT+YjL8yNwGLNx6porG+J6aKYKEK8/QN9zxd1l+d/Ekdilyot17UW/R28AsxOPoz3yT J5a/Ub30rYFaTv8CI8rXlYIRZxk5YTGgOdr7CrvmOk9He59qp9b6MzFSwjH/MBQiCcUb Ewr6Q/sCnrWsw68HJFI4B8etZvLeXtiDlcGsjHmVRmOYJwIuesvEh3EuYwbvlSjoUuJ0 WoDw== MIME-Version: 1.0 X-Received: by 10.224.22.134 with SMTP id n6mr7465722qab.27.1406822366604; Thu, 31 Jul 2014 08:59:26 -0700 (PDT) In-Reply-To: <140729234830.ZM20800@torch.brasslantern.com> References: <140729234830.ZM20800@torch.brasslantern.com> Date: Thu, 31 Jul 2014 17:59:26 +0200 Message-ID: Subject: Re: Repeat argument N times? From: Mikael Magnusson To: Zsh Users Content-Type: text/plain; charset=UTF-8 On 30 July 2014 08:48, Bart Schaefer wrote: > On Jul 29, 11:12pm, Benjamin R. Haskell wrote: > } > } Is there a built-in way to repeat an argument N times? > > Not really. You have to admit it's a rather unusual thing to do. It > can be done by abusing other expansions, as you've discovered. > > } It'd be nice if I could write (something like): > } > } upload-files file1(N3) file2(N10) file3(N4) > > You can create an array of N empty elements just by assigning to the > Nth position: > > N[100]=() > > And then: > > upload-files file1$^N[1,3] file2$^N[1,10] file3$^N[1,4] > > Works up to however much memory you're willing to waste on allocating > empty array slots. > > There are other ways, e.g. > > upload-files file2${^${:-{1..10}}/*/} > > upload-files file2(e{'repeat 10 reply+=($REPLY)'}) > > though the latter requires "file2" to actually exist, which sometimes > might be a good thing. Here's another minor variation on the first one, upload-files file1${(s: :)^${(l:50:)}} -- Mikael Magnusson