If Using nth Creates Dependencies, What Is The Best Way To Pull Data Elements From A Sequence

63 views
Skip to first unread message

octopusgrabbus

unread,
May 18, 2012, 11:03:26 AM5/18/12
to clo...@googlegroups.com
In our production development environment, we perform a lot of data transfers between diverse systems, and most of those transfers involve comma-delimited (.csv) data. So my first small Clojure applications have revolved around the clojure-csv library.

While learning Clojure I have seen the comment that using nth "stinks", because it creates dependencies. Wanting to do things in a Clojure way, I have a question.

If I need to extract a number of columns of a spreadsheet to minimize the dataset and this happens as the application is reading in and initializing its data, what should I use to extract those columns other than nth? And, if I use a series first and rest, isn't that also positional?

I've thought of ways to re-position the data initially, so comparison columns between two different spreadsheets that have one unique key column in common would be accessible with first, for example. However, I would still need to get at that data by column in order to reposition it, hence the need for nth.


David Nolen

unread,
May 18, 2012, 11:05:55 AM5/18/12
to clo...@googlegroups.com
There's nothing wrong with using nth far as I know.




--
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

Alex Robbins

unread,
May 18, 2012, 11:37:12 AM5/18/12
to clo...@googlegroups.com
I wonder if the idea was that you are better off using a hash-map and
key lookups so the positions are labeled. Some csv libs return a seq
of maps where the keys are the column header values. That way you'd be
able to select data by name instead of a sometimes arbitrary position.

Just a guess.
Alex

Tim Visher

unread,
May 18, 2012, 4:35:26 PM5/18/12
to clo...@googlegroups.com
On Fri, May 18, 2012 at 11:03 AM, octopusgrabbus
<octopus...@gmail.com> wrote:
I think the point of the parts of the discussion that I've been privy
to so far is mostly that `nth` is something that a novice clojurist
might reach for because they don't have a grasp of the sequence
abstraction as well as stream operations and laziness, in the same way
that many people immediately reach for loop/recur when some form of
list comprehension would've solved the problem better.

Once you have your mind around these other concepts (or perhaps even
before, this is a practical language after all) there's absolutely
nothing wrong with `nth`. It just probably shouldn't be everywhere in
your code unless your domain (like, say, a domain heavy in csv data,
perhaps?) supports the need for it.

It does tie you to ordering so it may be worth the effort to pour your
non-tagged csv data into maps so that your implementation code can be
happily ignorant if the order of the fields ever changes. You may know
things about your domain that would be good counterarguments to that.

Anyway, good to know you're still soldiering on. ;)

--

Timmy V.

http://twonegatives.com/
http://five.sentenc.es/ -- Spend less time on mail.

octopusgrabbus

unread,
May 18, 2012, 5:51:57 PM5/18/12
to clo...@googlegroups.com
Thanks for your comment, Tim. You provided a good example and comments on my blog.

octopusgrabbus

unread,
May 18, 2012, 5:53:28 PM5/18/12
to clo...@googlegroups.com
Pulling the data out of each csv row as a map would eliminate nth. That is a good idea, and I'll add it to my tool bag.
>> clojure+unsubscribe@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
> --
> 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+unsubscribe@googlegroups.com
Reply all
Reply to author
Forward
0 new messages