<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