repeat and replicate

20 views
Skip to first unread message

Shawn Hoover

unread,
Jan 27, 2009, 8:53:47 PM1/27/09
to clo...@googlegroups.com
Why do we have both repeat and replicate? I can sort of keep them straight, but as they only differ by arity I wonder if they can be combined... or if I'm missing a subtle reason for separate names. A user in IRC threw out the possibility of infinite vs. finite functions, but interleave and map seem to blur that line.

Shawn

Albert Cardona

unread,
Jan 28, 2009, 7:36:59 AM1/28/09
to clo...@googlegroups.com

From clojure/core.clj :

(defn replicate
"Returns a lazy seq of n xs."
[n x] (take n (repeat x)))


--
Albert Cardona
http://albert.rierol.net

Vincent Foley

unread,
Jan 28, 2009, 9:20:07 AM1/28/09
to Clojure
repeat returns an infinite seq; replicate returns a finite one.

Mark Volkmann

unread,
Jan 28, 2009, 9:23:09 AM1/28/09
to clo...@googlegroups.com
On Wed, Jan 28, 2009 at 6:36 AM, Albert Cardona <sapr...@gmail.com> wrot>

Right. Why not add a version of replicate that just takes x and have
it create an infinite, lazy sequence? Then repeat could go away.

--
R. Mark Volkmann
Object Computing, Inc.

Christian Vest Hansen

unread,
Jan 28, 2009, 10:17:39 AM1/28/09
to clo...@googlegroups.com
Or replicate could go away.

More likely, I think one of them could take multiple arities and make
the other obsolete.

>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> >
>



--
Venlig hilsen / Kind regards,
Christian Vest Hansen.

Stephen C. Gilardi

unread,
Jan 28, 2009, 4:36:05 PM1/28/09
to clo...@googlegroups.com

On Jan 28, 2009, at 10:17 AM, Christian Vest Hansen wrote:

Or replicate could go away.

More likely, I think one of them could take multiple arities and make
the other obsolete.

I like "repeat" with multiple arities and remove "replicate".

--Steve

Shawn Hoover

unread,
Jan 28, 2009, 4:56:34 PM1/28/09
to clo...@googlegroups.com
Me too. I'm just waiting for some hammer to drop about args ordering or partial application or something...

Chouser

unread,
Jan 28, 2009, 5:38:10 PM1/28/09
to clo...@googlegroups.com

+1 from me, for what it's worth.

(repeat obj) and (repeat n obj) look good.

--Chouser

Jason Wolfe

unread,
Jan 28, 2009, 5:49:40 PM1/28/09
to Clojure
> +1 from me, for what it's worth.

Ditto. Every time I want replicate, I type "repeat", remember that it
only takes 1 arg, and then have to search for "replicate" because the
name just won't stick in my head.

-Jason

Rich Hickey

unread,
Jan 28, 2009, 5:57:45 PM1/28/09
to Clojure


On Jan 28, 5:38 pm, Chouser <chou...@gmail.com> wrote:
> On Wed, Jan 28, 2009 at 4:56 PM, Shawn Hoover <shawn.hoo...@gmail.com> wrote:
>
> > On Wed, Jan 28, 2009 at 4:36 PM, Stephen C. Gilardi <squee...@mac.com>
> > wrote:
>
> >> I like "repeat" with multiple arities and remove "replicate".
> >> --Steve
>
> > Me too. I'm just waiting for some hammer to drop about args ordering or
> > partial application or something...
>
> +1 from me, for what it's worth.
>
> (repeat obj) and (repeat n obj) look good.
>

Patch welcome for this.

Rich

Timothy Pratley

unread,
Jan 28, 2009, 6:34:53 PM1/28/09
to Clojure
Reply all
Reply to author
Forward
0 new messages