apastinen has quit [Read error: 104 (Connection reset by peer)]
<hcarty>
What is the equivalent of the Perl $output = `some_program` in OCaml? The Unix module seems to have functions which run some_program in parallel, but I just want to wait for the output
<rwmjones>
hcarty, Unix.open_process_in
<rwmjones>
hcarty, but also try this ...
<rwmjones>
let rec input_all_lines chan =
<rwmjones>
try
<rwmjones>
let line = input_line chan in
<rwmjones>
line :: input_all_lines chan
<rwmjones>
with
<rwmjones>
End_of_file -> []
<rwmjones>
let pget cmd =
<rwmjones>
let chan = Unix.open_process_in cmd in
<rwmjones>
let lines = input_all_lines chan in
<rwmjones>
let stat = Unix.close_process_in chan in
<rwmjones>
(match stat with
<rwmjones>
Unix.WEXITED 0 -> ()
<rwmjones>
| Unix.WEXITED i ->
<rwmjones>
failwith ("command failed with code " ^ string_of_int i)
<rwmjones>
| Unix.WSIGNALED i ->
<rwmjones>
failwith ("command killed by signal " ^ string_of_int i)
<rwmjones>
| Unix.WSTOPPED i ->
<rwmjones>
failwith ("command stopped by signal " ^ string_of_int i));
<rwmjones>
lines
<hcarty>
rwmjones: Excellent, thanks!
<rwmjones>
obviously, output = pget "my command"
<rwmjones>
I mean
<rwmjones>
let output = pget "my command"
<flux>
it's a bit more complicated to have a tail-recursive input_all_lines, though, but I suppose that serves as an example..
<rwmjones>
unlike perl, output will be a list of lines (string list)
<rwmjones>
yeah, that input_all_lines isn't the best
<hcarty>
That should work for what I need now though, so thank you very much
<hcarty>
I just want to catch output from cpp at the moment
<hcarty>
Some slightly-automated camlidl binding generation. The code is currently in quickly-hacked Perl.
<rwmjones>
hcarty, that input_all_lines function will probably blow the stack if you call it on a large file
<rwmjones>
hcarty, also did you know about perl4caml?
diakopter has joined #ocaml
<hcarty>
rwmjones: Yes, I've seen perl4caml. I may end up using that if something is too hairy in OCaml.
<hcarty>
The header file I'm working with at the moment is 812 lines, so I think non-tailrecursive is ok for the time being
ikaros_ has joined #ocaml
<hcarty>
rwmjones: I just gave it a quick test, and it works beautifully for what I currently need
<hcarty>
Thank you again
ikaros has quit [Read error: 110 (Connection timed out)]
<apastinen>
hi, i am studing ocaml language, and i have started to thing where do you ever need to use this language? is there some commercial support or any other reasons? the grammar is also very exotic compared to other languages so i can think that legacy code is also very hard to maintain..
<RobertFischer>
1) You should use Ocaml whenever you need safety in your code, and C++-equivalent speeds.
<RobertFischer>
2) There is no business that backs Ocaml (like 37Signals backing Rails or Sun backing Java), but there is a fair amount of freelance support.
<RobertFischer>
3) The grammar is not that exotic compared to "other languages". It is exotic compared to Algol-derivative languages (like C++/Java). And, even that, it's not *that* exotic once you get past the few semicolons, brackets, and parenthesis.
<RobertFischer>
4) The powerful type system and functional style of development makes legacy code a lot easier to maintain than other languages. This is coming from a long-term Perl and Java hack.
<RobertFischer>
Any other questions?
<apastinen>
ah ok, thanks.
<apastinen>
this is good for now. thanks :)
<RobertFischer>
There's a pretty strong learning curve to Ocaml (although not as bad as, say, Haskell). Thankfully, it has imperative and OO training wheels while you're learning.
<apastinen>
yeah, i just compare is languages, which is familiar for me, like Java, C, ruby, lisp etc. but i think this is quite different.. but i will continue studying so maby it will open one day..
<RobertFischer>
It's not exceedingly different from Lisp once you get past superficialities.
<RobertFischer>
Don't think programming when you're coding Ocaml.
<RobertFischer>
Think Maths.
<apastinen>
cool, well actually i am not even Lisp master, i just did some emacs stuff with it years ago..
<apastinen>
i like to use ocaml to do native code, for windows and linux, and i think it should work for that?
<RobertFischer>
What do you mean "native code"?
<apastinen>
elf & exe..
<apastinen>
:)
<RobertFischer>
Sure, it will do that. Ocaml will compile to native, at which point it has C++-levels of performance.
<apastinen>
very well.
<RobertFischer>
Have at and enjoy. :D
Abo-Marwan has quit [Read error: 104 (Connection reset by peer)]
screwt8 has quit [Read error: 104 (Connection reset by peer)]
bluestorm_ has joined #ocaml
bluestorm_ has quit [Remote closed the connection]
<jonafan>
compared to c++, java, or even c, ocaml's grammar is ludicrously simple
<apastinen>
not for newbies =P Java has tons of code and tutorial and they teach it everywhere all the time and everyone knows it so it is easier get famialiar with it.. :) I don't know anyone in real world who has ever even hear about OCAML..
<jonafan>
maybe so, but popularity is a poor indicator of quality
Abo-Marwan has joined #ocaml
<jonafan>
another way to look at it is that almost everyone knows java, and since most people are poor programmers, most java code sucks and therefore most java examples suck
<apastinen>
you are absolute right.
<jonafan>
those who seek out something like ocaml are wise enough to see that programming could be better, so most ocaml code is higher quality
<jonafan>
(once you get the hang of it!)
<jonafan>
anyway, i find ocaml's compiler infinitely more helpful in identifying problems with my code than java's
<apastinen>
sounds very good. but still i can see domains for all other languages, ruby has web, java has commercial support, C/C++ for native, lisp has emacs, but which is for OCAML? but maby it is because i dont know nothing about its history..
<jonafan>
the errors are weird, but java's compiler really doesn't do much more than bitch about missing semicolons
<jonafan>
ocaml's compiler seems better at showing logical problems
<apastinen>
ok..
<ttamttam>
As a bad programmer, I can't use anything else than OCaml
<jonafan>
true, it isn't used for much
<apastinen>
:D
<jonafan>
the achilles' heel is that it's practically useless!
<apastinen>
is the compiler still maintained and developed?
<jonafan>
nah, i think there's a web dev framework, and you can make command line apps definitely, and i think there are gtk bindings?
<jonafan>
i think the most popular ocaml app is mldonkey
<jonafan>
yeah, the compiler is still maintained
<jonafan>
the latest version came out semi-recently i think
<ttamttam>
And I use it at work: libraries wrapped in C DLL. Users do not notice this is OCaml.
<jonafan>
may i guess
<jonafan>
haha
<jonafan>
i think too many people get scared off by the + +. +/ thing
<ttamttam>
OCaml is not just maintained: this is the work of one INRIA laboratory. It evolves.
<apastinen>
yes that is where i like to use ocaml. to write native code. C is too slow and there is portability issues on linux & windows etc. stuff
<apastinen>
sounds great. maby this is good time to study it, when it is famous, i can find a job as OCAML programmer :)
<jonafan>
haha
<jonafan>
yes
<ttamttam>
Depends.
<ttamttam>
If you choose one very big company, it may be difficult.
<ttamttam>
But in small ones, like mine... That is really a good tool.
<apastinen>
well.. i do program as a freelancer.. but i am so full of that Java and can't get any kicks from it so i like to start something new..
<ttamttam>
Another point before leaving: studying OCaml greatly improved how I used other language as well.
ttamttam has quit ["Leaving."]
<apastinen>
yeps, but now i will go jogging. c ya later.
apastinen has quit ["leaving"]
jeremiah has quit [Read error: 104 (Connection reset by peer)]
jeremiah has joined #ocaml
ikaros_ has quit ["segfault"]
ygrek has joined #ocaml
RobertFischer has joined #ocaml
loufoque has joined #ocaml
<loufoque>
is there a way to debug exceptions with lablgtk? Since exceptions musn't propagate from GTK+ signals it catches them, but gives no useful info.