mbishop changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | Grab Ocaml 3.10.0 from http://caml.inria.fr/ocaml/release.html (featuring new camlp4 and more!)
seafoodX has joined #ocaml
pantsd has joined #ocaml
_PenPen_ has joined #ocaml
szs1 has quit [Read error: 104 (Connection reset by peer)]
buluca has quit [Read error: 113 (No route to host)]
_PenPen_ has quit [Remote closed the connection]
Jedai has joined #ocaml
baruk has quit [Read error: 110 (Connection timed out)]
dbueno has quit ["This computer has gone to sleep"]
lde has quit [Read error: 113 (No route to host)]
lde` has joined #ocaml
seafoodX has quit []
G_ is now known as G
ygrek has joined #ocaml
oc13 has joined #ocaml
l_a_m has joined #ocaml
Torment has joined #ocaml
Tetsuo has joined #ocaml
leo037 has joined #ocaml
pantsd has quit [Read error: 110 (Connection timed out)]
pantsd has joined #ocaml
G_ has joined #ocaml
Jedai has quit [Read error: 110 (Connection timed out)]
G has quit [Read error: 110 (Connection timed out)]
jlouis has joined #ocaml
jlouis_ has quit [Read error: 110 (Connection timed out)]
jonafan has joined #ocaml
pantsd has quit [Read error: 110 (Connection timed out)]
jonathanv has quit [Read error: 110 (Connection timed out)]
pantsd has joined #ocaml
bluestorm_ has joined #ocaml
Tetsuo has quit ["Leaving"]
smimou has joined #ocaml
buluca has joined #ocaml
olegfink has joined #ocaml
<olegfink> came across a question: does ocaml standard library allow for formatted input (in the style of scanf probably)?
<olegfink> or any other way to read certain types of values from in_channel?
<olegfink> ah, there's Scanf
Tetsuo has joined #ocaml
<ulfdoz> olegfink: scanf/printf are actually hacks. Imho not a recommendation for more than debugging.
<olegfink> what would you recommend?
<ulfdoz> olegfink: read_line, read_int, read_float, probably in combination with a parser-function.
<olegfink> but they operate on a stdin?
<olegfink> for instance, I just want to sum two integers found in a file and write their sum to another one.
<olegfink> (round 0 task on any programming contest)
<ygrek> why printf/scanf are hacks?
<olegfink> my solution is:
<olegfink> let fin = open_in "sum.in" and fout = open_out "sum.out" in
<olegfink> Printf.fprintf fout "%d\n" (Scanf.fscanf fin "%d %d" (+))
skal has joined #ocaml
<ulfdoz> olegfink: There is also input_value in Pervasives.
<olegfink> yeah, saw it, but thought it is a special structure which I have to output before?
<bluestorm_> i don't see any problem with using printf/scanf
<bluestorm_> i mean
<ulfdoz> olegfink: No, its more important, that you read the correct type. e.g. you can read a decimal number as string and then convert it to an int with string_from_int.
<bluestorm_> they're not as hacky as C ones (type safe and so one)
<bluestorm_> -e
<olegfink> I like function argument to scanf
<olegfink> so that ocaml solution doesn't contain any insanity like scanf("%d %d",&a,&b); result=a+b; ...
<bluestorm_> hm
<ulfdoz> bluestorm_: imho it is not typesafe to combine any conversion-specifier with an arbitrary type.
<olegfink> in other words, ocaml way looks natural for me: i want to sum two integers, so I write fscand "%d %d" (+)
<bluestorm_> in general you write something like let x, y = scanf "%d %d" (fun x y -> x, y), so the function is not that useful
<ulfdoz> bluestorm_: Printf.mkprintf looks rather ugly.
<bluestorm_> haha
<bluestorm_> to say the truth, i never quite understood the documentation of these pages
<bluestorm_> (there is the "hack")
<bluestorm_> but considering a printf/scanf function _with it's format string_, it's rather sane
<bluestorm_> sssk
<bluestorm_> s/it's/its/
<ulfdoz> bluestorm_: I'm from the rather small group of people preferring string concatenation and explicit conversion.
<bluestorm_> hm
<bluestorm_> i don't know the internals of the printf module, but it's likely to be more efficient than concatenation
<bluestorm_> (of course if you only concatenate small bits before printing, that does not really matter most of the time)
<ulfdoz> I always considered printf/scanf as a convenience function, meant to be used, when a line of debug output or the like is needed.
<bluestorm_> hm
<bluestorm_> i never used input/output for important stuff anyway ^^
<olegfink> I suppose programming contest context, where i/o is not part of algorithm but is needed
<olegfink> so, how do you suggest me to read N integers from a file?
<olegfink> for example, forming a list of them
<olegfink> using scanf or input_value?
<bluestorm_> olegfink:
<bluestorm_> are you having trouble with the space-separated integers ?
<bluestorm_> for this particular problem (i encoutered with people doing algorithmic problems on USACO-like websites) i have a "hacky" solution
<bluestorm_> let read_int () = Scanf.scanf " %d" (fun i -> i);;
<bluestorm_> (this might raise nasty problems with other input function like read_line (), but if you're only reading ints, it'll just work)
baruk has joined #ocaml
seafoodX has joined #ocaml
dbueno has joined #ocaml
oc13 has quit ["Leaving."]
postalchris has joined #ocaml
buluca has quit [No route to host]
buluca has joined #ocaml
<ulfdoz> olegfink: I quickly coded an example, which may help you. http://rafb.net/p/MwaxaA38.html
<olegfink> ah, thanks, contains all the constructs I wondered about
skal has quit [Remote closed the connection]
<magius_pendragon> hey everyone, if i have a ocamllex file in blah.mll, and run ocamllex on it, and ocamlc on the resulting file (blah.ml). Open up the ocaml toplevel, and type open Blah;;, and then tried to do Blah.token;;, why would it be giving me a Refenece to undefined global `Blah'?
<magius_pendragon> hmm apparently this is happening with any compiled file i open from the toplevel...
<pango> ulfdoz: String.make 1 and string concatenation generates a lot of garbage, you could at least have used a Buffer.t... Also, you example fails if input file doesn't end with an \n...
<ulfdoz> I know, its far away from perfect. some lines definitely avoid nicer solutions to make the code shorter.
<ulfdoz> My testcase actually was "seq -s ' ' 1 10 > intlist.txt"
<ulfdoz> the atoi-implementation, c uses for converting a string to integer could be even more efficient, as it completely avoids copies.
love-pingoo has joined #ocaml
postalchris has quit [Read error: 113 (No route to host)]
postalchris has joined #ocaml
pango has quit [Remote closed the connection]
pango has joined #ocaml
<pango> from the "there's more than one way to do things" department, http://pastebin.com/fe794759
<pango> magius_pendragon: "open" just changes the way identifiers are resolved; it means that if an identifier cannot be found in current module namespace, it should be searched in "Blah" module namespace too
<pango> magius_pendragon: it allows you to use things defined in Blah without 'Blah.' prefix, but linking in this module is a separate issue
<magius_pendragon> pango: thanks, i read a bit more and figured out i wanted #load instead
<pango> yes, or add blah.cmo to toplevel arguments
<magius_pendragon> awsome, i hadn't noticed that; thanks
<pango> np
postalchris has quit [Read error: 113 (No route to host)]
seafoodX has quit []
replore has joined #ocaml
dbueno has quit ["Leaving"]
<ulfdoz> pango: very nice.
iratsu has joined #ocaml
<iratsu> what's a good source to learn ocaml?
<iratsu> pango: thanks
<iratsu> pango: which would you start with?
<pango> I mainly learned using the book (http://caml.inria.fr/pub/docs/oreilly-book/), because it matches the way I like learning things. It's a bit dated by now, but still worth reading I guess
gaja has quit ["leaving"]
gaja has joined #ocaml
<iratsu> ah, ok
<iratsu> thanks
<pango> np
<iratsu> oh i guess i could read the original frenchversion
<pango> sure
<pango> some of the restrictions mentionned in the book (vs. polymorphism/monomorphism) have been relaxed since then. Also some recent features (private types, polymorphic variants,...) are missing. Nothing to worry about when learning the core of the language
dbueno has joined #ocaml
buluca has quit [No route to host]
love-pingoo has quit ["Connection reset by pear"]
buluca has joined #ocaml
ita has joined #ocaml
tty56_ has quit [Read error: 110 (Connection timed out)]
skal has joined #ocaml
buluca has quit [Read error: 113 (No route to host)]
Torment has quit [Read error: 110 (Connection timed out)]
ita has quit ["installing a 10.3rc1 distro"]
kelaouchi has quit ["leaving"]
pantsd has quit [Read error: 110 (Connection timed out)]
hagman has joined #ocaml
hagman has quit [Client Quit]
buluca has joined #ocaml
pantsd has joined #ocaml
Mr_Awesome has joined #ocaml
bluestorm_ has quit ["Konversation terminated!"]
ygrek has quit [Remote closed the connection]
skal has quit [Remote closed the connection]
Tetsuo has quit ["Leaving"]
buluca has quit ["Leaving."]
<jdavis_> Can you execute ocaml code from C, i.e. embed the Ocaml interpreter?
postalchris has joined #ocaml
postalchris has quit [Client Quit]
ita_ has joined #ocaml
buluca has joined #ocaml
Mr_Awesome has quit [Read error: 110 (Connection timed out)]
<hcarty> jdavis_: You can call ocaml routines from C, but I don't know about embedding the VM and/or toplevel. I'm sure it's possible, but it may take some extra work.
l_a_m has quit [Remote closed the connection]
<jdavis_> hcarty: Oh, ok.
<jdavis_> To call ocaml routines from C, do you just compile to native code and call the routines directly?
<jdavis_> or is there some other interface?
<ita_> jdavis_: caml_register && callbacks
<ita_> works well
<jdavis_> ita_: Oh, cool.
<ita_> you have to be careful with memory allocation (use camlparam) but other than that it is easy as pie
<jdavis_> ita_: ok, I'll check it out
<ita_> i never used the camlp4 mapping for c++ (map objects to caml types), it looked harder and i never had more than 2-3 functions
jlouis has quit [Read error: 110 (Connection timed out)]
<jdavis_> ita_: I'm new to ocaml and I'm going through ocaml-tutorial.org right now.
<ita_> interfacing with c is probably the last thing you want to check out for now
<jdavis_> ita_: yeah, I'm about halfway through the tutorial. I'm mostly just getting used to the functional nature.
<jdavis_> I'm not entirely new... I learned a little ocaml a while ago, but I don't think I really understood it then. It makes a lot more sense now.