Yurik changed the topic of #ocaml to: http://icfpcontest.cse.ogi.edu/ -- OCaml wins | http://www.ocaml.org/ | http://caml.inria.fr/oreilly-book/ | http://icfp2002.cs.brown.edu/ | SWIG now supports OCaml| Early releases of OCamlBDB and OCamlGettext are available
sam_ has quit ["I like core dumps"]
j_bravo has joined #ocaml
j_bravo has left #ocaml []
thomas001 has joined #ocaml
<thomas001> hi,may i paste a few(13) lines ?
<gehel> yes
<thomas001> open Printf
<thomas001> let fib n =
<thomas001> let rec fib2 n a b =
<thomas001> if n>0 then
<thomas001> fib2 (n-1) b (a+b)
<thomas001> else
<thomas001> a
<thomas001> in
<thomas001> fib2 n 1 1
<thomas001> printf "%i\n" fib 20
<thomas001> thomas@borg-cube temp $ ocamlopt x.ml
<thomas001> File "x.ml", line 10, characters 8-12:
<thomas001> i started ocaml today,so i'm a total newbie
<gehel> 2s
<thomas001> 2s ?
<gehel> 2 sec
<thomas001> oh,ok
<gehel> ocamlopt thinks that you apply fib2 to n, 1, 1, _and_ printf "%i\n" fib 20
<gehel> in fib2 n 1 1;; printf ...
<gehel> do it
<gehel> if you don't want to use ';;', ocamlopt knows that the def of a function is finished if he parse a new 'let'
<gehel> so
<gehel> let fib ....
<thomas001> thx it compiles now
<gehel> let _ = printf "%i\n" fib 20
<thomas001> printf (fib 20) <-- had to be change to this
<gehel> b
<thomas001> b?
<gehel> wrong buffer :)
<thomas001> *g*
<thomas001> thank you gehel for the help
<gehel> you're welcome
<thomas001> ocaml seems to be not very popular,isn't it ?
<gehel> it depends where
<gehel> i think his popularity is growing
<gehel> in france, some people use/know it
<gehel> it's a university language..
<thomas001> i got to know it from the mldonkey source,it looked pretty interesting
<gehel> it is :)
<thomas001> cool i don't need fib and fib2 i can call fib2 fib
<thomas001> nice scoping ;)
<thomas001> can i write several commands after a in or only one ?
<gehel> i don't understand
<thomas001> sry bad english
<gehel> oh, after "in a"
<gehel> let a = 1 in (print_string "foo"; dummy(); a+1)
<thomas001> parens must be ?
<thomas001> print_string "foo";dummy();a+1;; <-- does this work ?
<gehel> in fact, when you use a block ( parenthesis can be replaced by "begin/end", all the expression except the last must be unit
<gehel> if dummy is : fun blabla -> unit, ocamlopt/ocamlc will accept
<gehel> if not, you'll have a warning, iirc
<gehel> if you don't use parens, 'a' will be defined only in the first expression, so 'a+1' is not defined
Torquemada has quit ["Lost terminal"]
<gehel> (no parens, and no begin/end)
<gehel> 'let a = 1 in print_string "foo"; a' is wrong
<thomas001> hmm..what is the difference between ; and ;; ?
<gehel> use ; between instruction in the same function
<gehel> ;; when you end a function
<gehel> ;; is required when you call 'ocaml' in your shell
<gehel> to ask an evaluation
<thomas001> so ;; closes the innermost function definition ?
<gehel> yes
<gehel> in a file, you don't need it
<gehel> a new let will suffice
<gehel> let/type
<thomas001> on toplevel does it matter if i use ; or ;; to seperate instructions ?
<gehel> ;; is the end of a function
<gehel> ; is the end of an instruction
<thomas001> i replaced my printf:
<thomas001> print_int (fib 20);;
<thomas001> print_newline ();;
<gehel> it's okay
<thomas001> but with ; it works also
<thomas001> so does not matter ?
<gehel> it works, but the type is not the same
<gehel> with ;, the type is the one of all the expression: print_int (); print_newline();;
<thomas001> and with ;; ?
<gehel> with ;;, the toplevel evalue the first and the second expression, and send a type for each
<thomas001> ok,thank you a lot
<gehel> np
<gehel> thomas001 try with some function that don't do side effet.. like this: 1+2; 2+3;;
<gehel> and this one is okay: ();1;; , because () has type unit
<thomas001> oh really newbie question:what is a side effect ? (never encountered this term in C/C++)
<gehel> when you print something, etc..
<gehel> when you don't compute
<thomas001> I/O ?
<gehel> for example
<thomas001> thx
<thomas001> wow braindead ocaml book: let (+)=( * ) ;;
<gehel> :)
<gehel> operator redefinition
<gehel> (+), like ( * _, like (-), is a function
<gehel> 1+2 == (+) 1 2
<gehel> we don't use (*) cuz (* if a comment beginning
<thomas001> works 1 bla 2 == (bla) 1 2 only on + - * / ?
<gehel> i think
<gehel> i think so
<gehel> (and other arithmetic operators_
<gehel> +. -. *. etc
<thomas001> thx
<gehel> let's go to bed now.. 2h40 am, and i must be at university this morning :/
<gehel> good night
* gehel &
<thomas001> gn8
sam_ has joined #ocaml
thomas001 has left #ocaml []
Icosahedron has joined #ocaml
Begbie has joined #ocaml
Icosahedron has left #ocaml []
polin8_ has joined #ocaml
Torquemada has joined #ocaml
aleksi has quit [Remote closed the connection]
aleksi has joined #ocaml
Zadeh has joined #ocaml
Zadeh_ has quit [Read error: 104 (Connection reset by peer)]
Zadeh_ has joined #ocaml
Zadeh has quit [Read error: 104 (Connection reset by peer)]
Zadeh_ has quit [Read error: 104 (Connection reset by peer)]
Zadeh has joined #ocaml
lament has joined #ocaml
docelic has joined #ocaml
docelic has quit ["Client Exiting"]
vegai has joined #ocaml
Begbie has quit [Read error: 60 (Operation timed out)]
mattam_ has joined #ocaml
docelic has joined #ocaml
TachYon26 has joined #ocaml
mattam has quit [Read error: 110 (Connection timed out)]
asqui has quit [Read error: 104 (Connection reset by peer)]
docelic has quit ["okey ppl, later"]
docelic has joined #ocaml
polin8_ has quit ["Now _that's_ a good cup of coffee."]
zack has joined #ocaml
docelic has quit [Read error: 60 (Operation timed out)]
zack has quit ["Client Exiting"]
j_bravo has joined #ocaml
j_bravo has left #ocaml []
lament has quit ["mental mantle"]
lament has joined #ocaml
lament has quit ["mental mantle"]
docelic has joined #ocaml
docelic has quit ["gonna bite some snacks"]
zack has joined #ocaml
aleksi has quit [forward.freenode.net irc.freenode.net]
aleksi has joined #ocaml
aleksi has quit [forward.freenode.net irc.freenode.net]
aleksi has joined #ocaml
aleksi has quit [forward.freenode.net irc.freenode.net]
aleksi has joined #ocaml
Begbie has joined #ocaml
docelic has joined #ocaml
aleksi has quit [forward.freenode.net irc.freenode.net]
zack is now known as zack|away
TachYon26 has quit [Remote closed the connection]
aleksi has joined #ocaml
aleksi has quit [forward.freenode.net irc.freenode.net]
aleksi has joined #ocaml
aleksi has quit [forward.freenode.net irc.freenode.net]
aleksi has joined #ocaml
mattam_ is now known as mattam
aleksi has quit [forward.freenode.net irc.freenode.net]
aleksi has joined #ocaml
zack|away has quit ["Client Exiting"]
intero has joined #ocaml
<intero> hi all
<gehel> 'lo
* intero is away: I'll answer as I come back, I am away now, sorry =(
matkor has joined #ocaml
matkor has quit [Remote closed the connection]
matkor has joined #ocaml
<matkor> Hellou :)
<docelic> (: uolleH
docelic has quit ["okay, enough."]
<matkor> What type would act like Array but would allow to append new values ?
<whee> a list?
<matkor> whee: Yop. Might be :) thanks List in ocaml has constant time access to random element ?
<whee> not constant time access
<whee> you could use arrays and just resize if you require that
<matkor> whee: yes, but I suspect that appending to array is costly (as it returns copy of array) So to do it efficient I would have to implement my type ...
<matkor> Strange that ocaml doesn't have sth like C++ STL vectior<> .... ;)
<whee> arrays are the same as vector
<whee> I don't believe vectors automatically resize themselves either
<matkor> whee: You mean ocaml vector nor C++ STL's vector<> ?
<vegai> STL's vector is an array with a weird name, is it not?
<whee> the STL vector and ocaml's Array module are essentially the same
docelic has joined #ocaml
<sam_> there's nothing strange that there'd be something missing in ocaml standard library, it's more like what you should expect :-)
<whee> sam: it's still not really missing, though :P
<whee> the STL vector is just a fancy api for arrays, which is what the Array module is'
<sam_> whee, well, i don't know exactly what stl vectors are like. i guess i was expecting them to be similar to java vectors
<sam_> as in, with support for mutable extension
<matkor> STL vectors have constant time append elem , which seems not be case with ocaml's arrays (but it's not topic for me to discus as I'm starting to learn ocaml :) )
<whee> matkor: I don't believe they do
<whee> they're really just implemented with C arrays, which don't have the ability to be extended
<matkor> whee: they do , it's in standard.
<whee> they must not use C arrays, then :P
<sam_> matkor, it is?
<whee> which would imply that they aren't constant time access
<whee> which they obviously are
<sam_> matkor, memory block extension surely is in c standard, but array extension? you sure about that?
<matkor> whee: They use. But they allocate twice big array as needed and copy elements to it. It's still constant time append.
<whee> there's no appending going on
<whee> most likely it mallocs double the array size and copies the memory
<whee> which is far from an append
<sam_> matkor, as far as i know, there is no array extension in c standard.. extension for dynamic allocated blocks, yes, but for staticly allocated blocks, no
<sam_> and arrays can be in both
<whee> looking at the source to ocaml's Array module, it's basically a direct interface to C arrays
<matkor> sam_: You are right.
<matkor> whee: And how big memory is allocated when append of element is made ? n+1 ?
<whee> append?
<whee> there is no appending with C style arrays
<matkor> OK. Never mind. I will learn more and than I hope will be able to be more clearer ...
<sam_> matkor, there is no appending one element.. there's appending of two arrays together, which will create an array of size of their sizes together
<sam_> matkor, so, no. there is no 'vector' such as what you are looking for
<whee> if you need to 'resize' you could use a reference to an array and make a new, larger array and blit the values over
<whee> but most likely you'd be better off with a different data structure
<whee> arrays don't have much use with a functional style
<sam_> yes, ocaml has what you want, if you code it yourself
<sam_> :-)
docelic has quit ["later"]
<matkor> How should I access object members ?
<matkor> class myclass =
<matkor> object
<matkor> val mutable member = 3;
<matkor> end;;
<matkor>
<matkor> let m = new myclass;;
<matkor> print_int m.member; (* syntax error *)
clog has joined #ocaml
<sam_> as far as i remember (i don't really use classes / objects), you can't access data members straight, so you'd need to make accessor functions.. and secondly, object members are references with #, not with ".".. so you'd want "m#member", instead of "m.member" (note: m#member won't work in this case either)
<matkor> sam_: Thanks :)
intero has quit ["bye all, thanks and take care"]
<matkor> Is there any C++ printf equvalent in ocaml :) ? I'm bored with print_that that; print_this this; :) ?
Torquemada has quit [Read error: 60 (Operation timed out)]
<sam_> Format.printf
<sam_> if you mix that with the print_ stuff, you might get some unexpected output, as they use different buffers (c standard buffers vs. caml buffers). so if you mix them, you might need to use Format.flush / Pervasives.flush
<sam_> oh, and printf isn't type safe, so if you'll get core dumps, you might want to look into what you give printf as params
<matkor> Thanks again sam :) .
<sam_> hmm, actually, i think i was wrong about Format.printf not being type safe. Looks like they've done some type hack just for it in the language
docelic has joined #ocaml
docelic has quit ["Client Exiting"]
<matkor> yeah, enough for tonight :) thanks for help, sam, and good bye :)
matkor has quit ["Client Exiting"]
sam_ has quit ["I like core dumps"]
j_bravo has joined #ocaml
j_bravo has left #ocaml []