smimou changed the topic of #ocaml to: OCaml 3.08.3 available! | Archive of Caml Weekly News: http://sardes.inrialpes.fr/~aschmitt/cwn/ | A free book: http://cristal.inria.fr/~remy/cours/appsem/ | Mailing List: http://caml.inria.fr/bin/wilma/caml-list/ | Cookbook: http://pleac.sourceforge.net/
<pango> $ ocaml str.cma
<pango> # Str.string_match;;
<pango> - : Str.regexp -> string -> int -> bool = <fun>
<araujo> i see
<araujo> that's the way to load modules?
<mflux> #load "str.cma";;
<mflux> of course, when you compile, you use ocamlc str.cma yoursource.cmo etc
cjohnson has joined #ocaml
Nutssh has joined #ocaml
cjohnson has quit [Connection timed out]
cjohnson has joined #ocaml
bzzbzz has quit ["leaving"]
Sonarman has joined #ocaml
_JusSx__ has quit ["leaving"]
gim has quit [Read error: 110 (Connection timed out)]
<drz> is there an easy way to open a window just for text output? I'm tempted to just fork an "xterm -e cat /tmp/named_pipe" and write to the pipe
dan2 has quit [Remote closed the connection]
joo has quit [Nick collision from services.]
joo_ has joined #ocaml
cjohnson has quit [Connection timed out]
cjohnson has joined #ocaml
Nutssh has quit ["Client exiting"]
ulfdoz_ has joined #ocaml
ulfdoz has quit [Read error: 145 (Connection timed out)]
<araujo> When i do: # let my_regex = Str.regexp "li";;
<araujo> I am compiling a regular expression?
<ulfdoz_> moin
<araujo> ?
<ulfdoz_> good morning, I meant.
cjohnson has quit [Connection timed out]
kinners has joined #ocaml
cjohnson has joined #ocaml
<araujo> :-P
<araujo> ulfdoz_, do you know how can i run a program from the terminal?
<araujo> ive been running code from the repl so far
<ulfdoz_> araujo: ocamlrun, but normally not necessary, at least on my box, the generated code is smart enough, to call ocamlrun by itself.
Sonarman has quit [Read error: 110 (Connection timed out)]
<araujo> mm.. i see
<araujo> but i also was asking (sorry my question wasn't clear enough) about the entry point of the program
<araujo> For example, i only know to declare functions, but i don't know how to create the main body of the program
<ulfdoz_> I'm also beginner, and for now I'm fighting more with C than ocaml, so that there's not enough time for the nice things of life.
<araujo> hah
<araujo> But i mean, in haskell for example, i do: let main = .....
<araujo> To define the body of the program
<ulfdoz_> let main = print_string "Hello World
<ulfdoz_> " in main;;
<ulfdoz_> Works
<ulfdoz_> At least it does, what it was supposed to.
<kinners> you can use simple expressions in a module (like print_endline "hello", let () = main (), etc.)
<kinners> and they'll get evaluated when the module is loaded
cjohnson has quit [Connection timed out]
cjohnson has joined #ocaml
<araujo> Thanks ulfdoz_
<araujo> Other newbie question, how do i load modules in the source file?
<ulfdoz_> araujo: open <module_name>
<ulfdoz_> At this point I'm recommending ocamlfind. It simplifies the fight with compiler-flags enormously.
<araujo> ulfdoz_, do you know a good tutorial about compiling ocaml programs?
<araujo> how to link to libraries and stuff like that
<ulfdoz_> araujo: No, I learnt it by doing and reading Makefiles of ocamlnet.
<araujo> araujo@dC9F335CF Ocaml $ ocamlc task.ml
<araujo> Error while linking task.cmo: Reference to undefined global `Str'
<ulfdoz_> araujo: Probably you miss an Include to the compiler.
<araujo> ?
<kinners> araujo: ocamlc str.cma task.ml. The ocaml manual has a section on ocamlc, have you read that?
<araujo> No.
<araujo> reading now, thanks
Snark has joined #ocaml
cjohnson has quit [Read error: 110 (Connection timed out)]
cjohnson has joined #ocaml
<Snark> slt
<araujo> there is any error with this:
<araujo> let main =
<araujo> while (let s = read_line()) <> "quit"
<araujo> do
<araujo> match_list elt_list s
<araujo> done
<araujo> in main;;
<kinners> ocaml ain't C ya know :)
<araujo> yeah, slowly grasping at it
<kinners> you're treating s like a variable instead of a binding
<kinners> for evil imperative loops :) you generally need a reference like this, let s = ref "" in while s := read_line (); !s <> "quit" do something !s done
<ulfdoz_> araujo: In general, in fp, recursions are replacing loops, although ML isn't purely functional recursion is preferred over loops.
__DL__ has joined #ocaml
Submarine has joined #ocaml
vezenchio has joined #ocaml
gim has joined #ocaml
kinners has quit [Read error: 110 (Connection timed out)]
<Snark> @+
Snark has left #ocaml []
cjohnson has quit [Connection timed out]
cjohnson has joined #ocaml
b00t has joined #ocaml
Banana has quit [Read error: 145 (Connection timed out)]
Gueben has joined #ocaml
<ulfdoz_> prost
Banana has joined #ocaml
bk_ has joined #ocaml
Msandin has joined #ocaml
smimou has joined #ocaml
Msandin has quit [Read error: 60 (Operation timed out)]
Submarine has quit ["Leaving"]
Tachyon76 has joined #ocaml
shawn_ has joined #ocaml
_shawn has quit [Read error: 110 (Connection timed out)]
Snark has joined #ocaml
_JusSx_ has joined #ocaml
cjohnson has quit [Read error: 104 (Connection reset by peer)]
cjohnson_ has joined #ocaml
pango has quit ["bbl"]
cjohnson_ is now known as cjohnson
pango has joined #ocaml
Submarine has joined #ocaml
Tachyon76 has quit ["Leaving"]
b00t has quit [Remote closed the connection]
<araujo> morning.
<araujo> let main =
<araujo> let r = ref "" in
<araujo> while r := read_line(); !r <> "quit" do
<araujo> match_list !r elt_list
<araujo> done
<araujo> in main;;
<araujo> what's wrong with that?
<araujo> i keep getting:
<araujo> File "task.ml", line 15, characters 15-16:
<araujo> This expression has type string ref but is here used with type string
<araujo> And that's the: match_list !r elt_list
<mrvn> "in main" is wrong in toplevel
<araujo> sorry, this is the error: File "task.ml", line 15, characters 4-26:
<araujo> Warning: this expression should have type unit.
<araujo> mrvn, ?
<mrvn> let in the top level has no in
<mrvn> while is imperative and the things inside should all return unit.
<araujo> mrvn, what i don't understand is "in main" is wrong
<araujo> let main = .... in main;; works fine without the while
<araujo> Other question, can main be a recursive function?
<araujo> Because i can't see a good way to iterate
<mrvn> araujo: you wan't main to be a function?
<mflux> araujo, let rec main () = main () in main ()
<mflux> araujo, do note that infact saying let main = something make something to be executed
<araujo> I just want to iterate the code inside main .. or can't i?... or should i just include that code inside other function?
<mflux> 'in main' just makes that expression to return the value of the last expression in the statement, that is, the value main
<mrvn> Your let main = defines a simple value and the "in main" returns that value.
<mrvn> which is ()
<araujo> Ohh.. i see
<mrvn> Normaly you have something like "let main args = ..." and "let _ = main Sys.args"
<araujo> Isee
<araujo> First time i work with main
<araujo> And what can i do for my iteration?
<araujo> How could i address that?, inside main, or inside other function?
<mrvn> araujo: what does match_list !r elt_list do?
TeXitoi has joined #ocaml
flycat has joined #ocaml
<araujo> mrvn, takes a regexp and a list, and returns a list with the elements containing the regexp
<mrvn> araujo: and what do you want to do with it? Currently you just throw it away.
<araujo> i print it.
<araujo> I print each element to stdout
<mrvn> not in what you pasted
<araujo> mrvn, any ocaml place to paste the code?
<mrvn> If you print it that should return () and give no warnings.
<araujo> i print it from match_list
<araujo> mrvn, you are right, and i can see
<araujo> This works perfect:
<araujo> let main =
<araujo> let r = read_line() in
<araujo> match_list r elt_list;;
<araujo> So match_list returns ()
<araujo> mrvn, the problem is when i try to add a while to it
<araujo> But oddly, when i do:
<araujo> let main =
<araujo> let r = read_line() in
<araujo> for i = 0 to 3 do match_list r elt_list done;;
<araujo> i get:
<araujo> File "task.ml", line 15, characters 20-41:
<araujo> Warning: this expression should have type unit.
<mrvn> because your match_list does not return unit.
<araujo> mrvn, i thought you guys meant that i can only return unit from main....
<mrvn> main can be anything. Nothing special about it.
<araujo> i see
<mrvn> but where do you wan't to return it to?
<mrvn> usualy main ends and the program ends.
<araujo> match_list has side effects, it prints to stdout
<araujo> that is the only thing i care
<mrvn> side effects are not the problem.
<mrvn> if you don't care about the return value use ignore
<mrvn> or make it not return stuff
<araujo> val match_list : string -> string list -> unit list
<mrvn> unit list?
<araujo> mm.. yeah
<araujo> because it prints each element from a list
<mrvn> [(); ();] or [(); (); (); (); ()]. verry informative. :)
<mrvn> maybe change a List.fold_right to List.iter or something.
<mrvn> or map to iter
<araujo> Found it!!!!
<araujo> mrvn, it works if i use ignore
<araujo> because, i really don't care about the return value but the side effects
<mrvn> fixing the code would be better. unit list is quite useless
<araujo> what you mean with fixing the code?
<araujo> isn't ignore a fixing?
<mrvn> no. don't return the unit list, return unit.
<mrvn> ignore just throws the value away. hides the warning
<araujo> I thought ignore returned unit
<araujo> The unit list is created because i map [ string; string ] to something like [ print_string string; print_string string...]
<mrvn> You are still creating an unit list in memory for nothing
<mrvn> Don't map, iter
<araujo> hah, thanks mrvn
<araujo> i see, iter is like the.. imperative friend :-)
<mrvn> doing it recursively is so much nicer.
<mrvn> let rec loop = function "quit" -> () | line -> match_list line elt_list; loop (read_line ()) in loop (read_line ())
<araujo> hah definetly more beautiful
<araujo> mrvn, it's just that.. since this is my first time using main, i didn't know if i could do anything i do with others functions with it
<mrvn> It is just a custom to call the main function main, nothing more.
<mrvn> Just a remnand from programming C I guess.
<araujo> hah yeah
pango has quit ["Leaving"]
<araujo> mrvn, i see recursion got several advantages, for example, one advt could be that recursive functions can return any value ?
<mrvn> the imperative one can too
pango has joined #ocaml
<araujo> mrvn, but in this case, my problem, shouldn't while always return unit?
<mrvn> you have to use other mechanisms to return something when going imperative
<mrvn> e.g. let res = ref [] in ... while ... done; !res
<ulfdoz_> wg #netbsd
<ulfdoz_> srz
<araujo> mrvn, but what is the expr inside the while doesn't return unit
<araujo> ?
<mrvn> then it gets thrown away
osdever666 has joined #ocaml
TeXitoi has quit [Read error: 131 (Connection reset by peer)]
TeXitoi has joined #ocaml
ptolomy has joined #ocaml
* ptolomy yawns.
<ptolomy> Ocaml rules!
* ptolomy looks around awkwardly.
<ulfdoz_> sometimes
araujo has quit ["Programs must be written for people to read, and only incidentally for machines to execute"]
_JusSx_ has quit ["Lost terminal"]
osdever666 has quit [Read error: 110 (Connection timed out)]
cjohnson has quit [Read error: 54 (Connection reset by peer)]
monochrom has joined #ocaml
bk_ has quit ["Leaving IRC - dircproxy 1.1.0"]
vezenchio has quit [""Under democracy one party always devotes its chief energies to trying to prove that the other party is unfit to rule—and bot]
<Snark> good night
Snark has left #ocaml []
mrvn_ has joined #ocaml
mrvn has quit [Read error: 110 (Connection timed out)]
yangsx has joined #ocaml
flycat has left #ocaml []
monochrom has quit ["What is the meaning of "meaning"?"]
yangsx has quit [Remote closed the connection]
TeXitoi has quit ["leaving"]
smimou has quit ["?"]
Smerdyakov has quit [Client Quit]
pattern_ has joined #ocaml
pattern_ has quit [Read error: 54 (Connection reset by peer)]
Submarine has quit ["Leaving"]
lodewijk has joined #ocaml
se7en has joined #ocaml
Smerdyakov has joined #ocaml
Gueben has quit ["plouf"]
se7en has quit []