Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion seeking a lazy way to interleave a constant

Received: by 10.42.89.20 with SMTP id e20mr6933896icm.3.1334025312504;
        Mon, 09 Apr 2012 19:35:12 -0700 (PDT)
X-BeenThere: clojure@googlegroups.com
Received: by 10.231.80.74 with SMTP id s10ls4738248ibk.0.gmail; Mon, 09 Apr
 2012 19:35:03 -0700 (PDT)
Received: by 10.42.150.2 with SMTP id y2mr6260887icv.7.1334025303149;
        Mon, 09 Apr 2012 19:35:03 -0700 (PDT)
Received: by 10.42.150.2 with SMTP id y2mr6260886icv.7.1334025303138;
        Mon, 09 Apr 2012 19:35:03 -0700 (PDT)
Return-Path: <b...@benmabey.com>
Received: from mail.onticweb.com (mail.onticweb.com. [184.106.218.17])
        by gmr-mx.google.com with ESMTPS id t9si8410288igb.1.2012.04.09.19.35.02
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 09 Apr 2012 19:35:02 -0700 (PDT)
Received-SPF: neutral (google.com: 184.106.218.17 is neither permitted nor denied by best guess record for domain of b...@benmabey.com) client-ip=184.106.218.17;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 184.106.218.17 is neither permitted nor denied by best guess record for domain of b...@benmabey.com) smtp.mail=...@benmabey.com
Received: from lambda.local (unknown [68.69.166.132])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	(Authenticated sender: bmabey)
	by mail.onticweb.com (Postfix) with ESMTPSA id 8700A2CD7B1
	for <clojure@googlegroups.com>; Tue, 10 Apr 2012 02:35:02 +0000 (UTC)
Message-ID: <4F839C54.5040402@benmabey.com>
Date: Mon, 09 Apr 2012 20:35:00 -0600
From: Ben Mabey <b...@benmabey.com>
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120327 Thunderbird/11.0.1
MIME-Version: 1.0
To: clojure@googlegroups.com
Subject: Re: seeking a lazy way to interleave a constant
References: <1173099.2590.1334025081740.JavaMail.geo-discussion-forums@vbyj26>
In-Reply-To: <1173099.2590.1334025081740.JavaMail.geo-discussion-forums@vbyj26>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

On 4/9/12 8:31 PM, Andrew wrote:
> Given a lazy sequence of numbers is there a way to interleave a 
> constant and get another lazy sequence? Say the first sequence is 1 2 
> 3 4 ... I'd like the second sequence to be 1 0 2 0 3 0 4 0 ....
>
> Thanks in advance!
>

Yep, and it is even called interleave. :)

clojure.core=> (interleave [1 2 3 4] (repeat 0))
(1 0 2 0 3 0 4 0)
clojure.core=> (doc interleave)
-------------------------
clojure.core/interleave
([c1 c2] [c1 c2 & colls])
   Returns a lazy seq of the first item in each coll, then the second etc.
nil
clojure.core=> (doc repeat)
-------------------------
clojure.core/repeat
([x] [n x])
   Returns a lazy (infinite!, or length n if supplied) sequence of xs.