slashvar[lri] has quit [Read error: 104 (Connection reset by peer)]
cjohnson has joined #ocaml
_JusSx_ has joined #ocaml
<mflux>
araujo, repl?
cjohnson has quit [""We live like penguins in the desert...""]
vodka-goo has joined #ocaml
_JusSx_ has quit ["leaving"]
mrvn has joined #ocaml
pango__ has joined #ocaml
[TSP]Aradorn has joined #ocaml
<[TSP]Aradorn>
wow there is an actual ocaml chan =p
mrvn_ has quit [Read error: 110 (Connection timed out)]
<[TSP]Aradorn>
anyone know a good tutorial on reading in files and parsing them?
<[TSP]Aradorn>
i can open the file and read line by line, but cant figure out how to automate the process on an unknown file size
pango_ has quit [Read error: 110 (Connection timed out)]
<mflux>
actually, that's somewhat tricky :-o, because input_line throws an exception at the end of the data, and catching that exception must be done before a new recursion level in the loop
<mflux>
basically the logic goes like: let rec loop () = let i = input_line stdin in process_line i; loop () in loop ()
<mflux>
and that can go inside a try ... with End_of_file -> ()
<mflux>
but if you need to return a value from the loop, you need to catch the exception earlier
<[TSP]Aradorn>
complicated much =p
Submarine has joined #ocaml
<[TSP]Aradorn>
k ill give that a try on the top lvl
<mflux>
such as: let rec loop lines = match try Some input_line stdin with End_of_file -> None with Some line -> loop (line::lines) | None -> lines in loop ()
<mflux>
Some input_line stdin -> Some (input_line stdin)
<mflux>
(writing the code to an editor and reindenting might be useful)
<[TSP]Aradorn>
heh yeah
<[TSP]Aradorn>
im a java user and im trying to learn ocaml to help out my functional programming skills and god its difficult =p
<mflux>
and loop () -> loop []
<mflux>
so what kind of tutorials have you been reading?
<[TSP]Aradorn>
i do alot of Natural language processing and functional languages are great for that so im going to pickup ocaml to add to my knowledge base
<mflux>
atleast the title fits your description ;)
[TSP]Aradorn is now known as Aradorn
<Aradorn>
ah I have looked at that tut
gim has joined #ocaml
<Aradorn>
ok im trying to decipher what you gave me earlier
<Aradorn>
so basically its a recursive function that goes to the end of the file and builds a list of strings backwards?
<Aradorn>
until its back at the start of file (which is the first recursive call)
Snark has joined #ocaml
<Aradorn>
word of advice dont tell the toploop to scan a 30 meg text file =p
Msandin has joined #ocaml
<mflux>
araujo, the problem with your code is that it isn't tail recursive
<mflux>
aradorn even
<Aradorn>
yeah got a tail recursive version too just working on learning the ropes of how each works compared to what i know from java
<mflux>
aradorn, let rec foo () = try .. foo () with .. means there is a 'catch'-block still around after entering the function again
<Aradorn>
right
<mflux>
here's something I've used:
<mflux>
type ('a, 'b) value = Value of 'a | Exception of 'b
<mflux>
let valuefy s = try Value (s ()) with exn -> Exception exn
<mflux>
actually let valuefy s arg = try Value (s ararg) with exn -> Exception exn could be better
<Aradorn>
so you recurse with the exception and the string each time?
<mflux>
so it allows you to write let rec loop lines = match valuefy input_line stdin with Value line -> loop (line::lines) | Exception End_of_file -> lines | Exception exn -> raise exn
<mflux>
I imagine most of the time the exception is the cue to finish recursion