Re: How to read a txt file?

2013-02-01 Thread greg r
slurp works well, however, it reads the file in as a single string.  The 
result may not be readily useable depending on what you are doing.
 
I read in text files using clojure.java.io functions plus the core function 
line-seq.  What you get is a sequence whose elements are the individual 
lines of the file.
Then you can apply the power of the Clojure sequence library functions to 
the problem you are trying to solve.
This gets the text file directly to a data structure which is easily 
processed.
 
Here's a quick example function:
 
(use 'clojure.java.io)
 
(defn grab-file [file-path]
 (with-open [text-file-reader (reader file-path)]
   (do-all (line-seq text-file-reader
 
This returns a sequence of strings.  The file-path parameter is a string 
which is the path to the file.
Other functions in clojure.java.io are very useful for dealing with files.
Note the reader function is wrapped in a with-open function to make sure it 
is properly closed.
 
Regards,
Greg
 
 

On Friday, February 1, 2013 7:17:43 AM UTC-5, Roger75 wrote:

> I'd like to read a txt file using clojure. How do I do that? Any examples?

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to read a txt file?

2013-02-01 Thread Andy Fingerhut
Roger, tryclj.com is limited in what it can do.  The Clojure code you type in 
there is running on the web server across the network from you, not on your own 
local machine.  That file isn't accessible there.

Also for that reason many symbols are not allowed to be used in tryclj.com 
expressions, slurp apparently being one of them.  Click on the about link on 
tryclj.com and read the disclaimer.

If you have some version of Java installed on your local machine, or can 
install it, I'd recommend trying to install Leiningen to try out Clojure on 
your own machine, e.g. by following the "Getting Started" instructions on 
clojure-doc.org here: 
http://clojure-doc.org/articles/tutorials/getting_started.html

Andy

On Feb 1, 2013, at 6:12 AM, Roger75 wrote:

> Hi,
> 
> I'm trying to use this console:
> http://tryclj.com/
> 
> the command I wrote:
> (slurp "C:\\Users\\User1\\teste\\teste.txt")
> 
> 
> I get this:
> java.lang.RuntimeException: Unable to resolve symbol: in this context
> 
> On Friday, February 1, 2013 10:17:43 AM UTC-2, Roger75 wrote:
> I'd like to read a txt file using clojure. How do I do that? Any examples?

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to read a txt file?

2013-02-01 Thread Roger75
Hi,

I'm trying to use this console:
http://tryclj.com/

the command I wrote:
(slurp "C:\\Users\\User1\\teste\\teste.txt")


I get this:
java.lang.RuntimeException: Unable to resolve symbol: in this context

On Friday, February 1, 2013 10:17:43 AM UTC-2, Roger75 wrote:
>
> I'd like to read a txt file using clojure. How do I do that? Any examples?

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to read a txt file?

2013-02-01 Thread Zack Maril
Look at slurp. 
http://clojuredocs.org/clojure_core/1.2.0/clojure.core/slurp

On Friday, February 1, 2013 4:17:43 PM UTC+4, Roger75 wrote:
>
> I'd like to read a txt file using clojure. How do I do that? Any examples?

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to read a txt file?

2013-02-01 Thread AtKaaZ
there are some examples here:

http://clojuredocs.org/clojure_core/clojure.core/slurp

http://clojuredocs.org/clojure_core/clojure.java.io/reader



On Fri, Feb 1, 2013 at 1:44 PM, Baishampayan Ghose wrote:

> clojure.core/slurp
>
> Sent from phone. Please excuse brevity.
> On 1 Feb 2013 18:13, "Roger75"  wrote:
>
>> I'd like to read a txt file using clojure. How do I do that? Any
>> examples?
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>  --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Please correct me if I'm wrong or incomplete,
even if you think I'll subconsciously hate it.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to read a txt file?

2013-02-01 Thread Baishampayan Ghose
clojure.core/slurp

Sent from phone. Please excuse brevity.
On 1 Feb 2013 18:13, "Roger75"  wrote:

> I'd like to read a txt file using clojure. How do I do that? Any examples?
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




How to read a txt file?

2013-02-01 Thread Roger75
I'd like to read a txt file using clojure. How do I do that? Any examples?

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.