We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,878 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

CSV File to Vectors in Scheme

Hey, so I'm working on the game set-cubed in Scheme (for those who know the game). Currently, i have a csv file of all the possible dice with dice faces. I'm trying to read this into scheme, and managed to do that with a csvreadermaker. Currently, i can get it into a vector, but i want to pull out individual items in this vector to compare. Preferably, i want something that I can use that acts similarly to a 2 dimensional array. Here's what I have:

(require (planet neil/csv:1:6/csv))


(define set-cubed-csv-reader ;#####Creating our reader for the CSV file#####
  (make-csv-reader-maker
   '((separator-chars #\,)
     (strip-leading-whitespace? . #t)
     (srtip-trailing-whitespace? . #t))))

 (define next-row
    (set-cubed-csv-reader (open-input-file "setcubed.csv"))) ;####We just defined (next-row) to give us the next row in each line of setcubed.csv

This is some output:
> (define v (next-row))
> v
("dienum" "face1" "face2" "face3" "face4" "face5" "face6")

I want to be able to pull each element out of the vector, but also easily be able to get more vectors for the next line down in the csv file.
How do I go about doing this?

2
Contributors
13
Replies
1 Day
Discussion Span
2 Years Ago
Last Updated
14
Views
BobTheLob
Light Poster
34 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

yeah CS3210!

rotflcopter
Newbie Poster
9 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

:P Ha ha, having a similar problem?
I actually managed to get it to work! Turns out that when I did that (above), i get a list instead. It's weird,going back and forth between lists and vectors.

BobTheLob
Light Poster
34 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I'm actually trying to figure out how to read the csv in haha I was using an example in the powerpoint but that wasn't working very well for me so I was looking for a better way to read it...

rotflcopter
Newbie Poster
9 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

but I thought it was pretty funny that I came across this haha

rotflcopter
Newbie Poster
9 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I can't find any of the powerpoints. I'm pretty much on my own :P. But If you want, go here for some info on how to read in CSV files.

http://planet.plt-scheme.org/package-source/neil/csv.plt/1/6/planet-docs/csv/index.html

BobTheLob
Light Poster
34 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Thanks! yeah it's just under slides in the t drive but apparently they're just slowing me down! haha I hope I dont't have to stay up all night...

rotflcopter
Newbie Poster
9 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

did you figure out how to index the list?

rotflcopter
Newbie Poster
9 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

you mean pop it into a vector? I managed to put it inside a vector of a vector, and then went through and grabbed a "dice" and then a "face". My problem now is doing proper equality checks with strings

BobTheLob
Light Poster
34 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

how did you go from list to vector?

rotflcopter
Newbie Poster
9 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

oh nvm figured it out haha

rotflcopter
Newbie Poster
9 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

list->vector

BobTheLob
Light Poster
34 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I don't understand this!! I can't index the vector. it's just stored as one big vector and when I call the 0th index it gives me the exact same vector, I can't access parts of it

rotflcopter
Newbie Poster
9 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

oh wait... nvm I'm an idiot, ignore me haha

rotflcopter
Newbie Poster
9 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1289 seconds using 2.73MB