For example, I know I can do this (indexed is from the contrib
seq_utils library):
(using a short example to
keep it readable)
(indexed "Now is")
-> ([0 \N] [1 \o] [2 \w] [3 \space] [4 \i] [5 \s])
What I would like to do is only index those elements that satisfy
some predicate, such as:
(indexed-pred vowel? "Now is")
-> ([\N] [0 \o] [\w] [\space] [1 \i] [\s])
I want the counter to only increment when the predicate is true,
so just filtering out the index on a fully indexed list isn't what I
need, it will leave holes in the numbering.
I'd be OK with the return result being: ([nil \N] [0 \o] [nil \w]
[nil \space] [1 \i] [nil \s])
since a simple map could strip the nils out.
I can't help feeling that the solution is just on the edge of my
peripheral vision, but I can't see it.
Thanks,
-Doug
P.S. I want to use this to number the instructions in a road rally,
where the sequence of instructions are interspersed with other notes
and items. Numbering the vowels in a string is a nice simplification.
-Per
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to
> clojure+unsubscribegooglegroups.com or reply to this email with the words
> "REMOVE ME" as the subject.
>
-Steve
-Per
On Sat, Mar 20, 2010 at 09:50:12PM +0700, Per Vognsen wrote:
> Aha! I Googled for scan in seq-utils and didn't find anything. It
> would be nice if people stuck to standard terminology that has a
> continuous history going back to the early 60s.
So we use names like car and cdr? This is one of my favorite
non-technical points pro clojure: It blows of the musty smell of the
last 50 years.
(Whether scan falls in this category is a different question. But "the
others use bad names, so we should too" is not a good argument.)
Sincerely
Meikel
As for the matter at hand, the name 'reductions' is perhaps more
descriptive but the con is that it less standard and almost three
times as long as 'scan'. The importance of descriptiveness in names is
often overstated. Someone who has never seen this function before
might perhaps see the name and correctly guess a relationship of some
sort with 'reduce'. But that does not help him much in his quest to
understanding the code if he has no experience with scans. I find
recognizability and memorability is usually a more important metric.
Anyway, I don't want to derail this thread any further. :)
-Per
On Sat, Mar 20, 2010 at 10:16 PM, Meikel Brandmeyer <m...@kotka.de> wrote:
> Hi,
>
> On Sat, Mar 20, 2010 at 09:50:12PM +0700, Per Vognsen wrote:
>> Aha! I Googled for scan in seq-utils and didn't find anything. It
>> would be nice if people stuck to standard terminology that has a
>> continuous history going back to the early 60s.
>
> So we use names like car and cdr?
Perhaps if we were still programming with cons cells as fundamental
building blocks. Cons cells are decidedly not linked list nodes but
binary tree nodes that can be used to build right-leaning cons lists,
left-leaning snoc lists, a-lists and anything in between. In that
hypothetical case, yes, maybe car and cdr would not be so bad,
everything considered. They are short, symmetric (3 characters, one
middle character difference) and memorable once learned. At this point
in time, rejecting them based on their half-forgotten origins in a
computer architecture of yore is a little like rejecting a name on the
basis of its Greek etymology. Every name is a more or less
conventional sign. Convention isn't everything but neither is it
nothing.
For a sequence abstraction though, first and rest are infinitely
better choices. Fortunately that is what Clojure uses them for. In
Common Lisp, they are mere synonyms for car and cdr, though with
admittedly useful connotations.
-Per
> Which looks the same as clojure.contrib.seq/reductions to me...
> On 20 Mar 2010, at 13:54, Per Vognsen wrote:
>
>> Learn to love scan: http://gist.github.com/338682
Thanks Per and Steve! I knew there was catch that I wasn't seeing.
I did see reductions in seq-util (I am using 1.1), but it didn't click.
Not going to get in the middle of what names should be what.
-Doug