SoreEel has joined #ocaml
docelic has joined #ocaml
docelic has quit [Client Quit]
lament has joined #ocaml
lament has quit ["pathetic"]
MegaWatS has quit ["Actually, people sometimes talk about man's "bestial" cruelty, but that is being terribly unjust and offensive to the beasts:]
docelic has joined #ocaml
docelic has quit ["Client Exiting"]
kev has joined #ocaml
<
kev>
I'm getting errors with the following:
<
kev>
fun logon sock =
<
kev>
send sock "NICK mlbot\r\n";
<
kev>
send sock "USER kev\r\n";
<
kev>
ML doesn't appear to like the variable sock in the third line there, and I guess i'm making a mess by trying to use ML in an imperative style...
skylan has quit [Read error: 104 (Connection reset by peer)]
skylan has joined #ocaml
<
SoreEel>
kev, the actual error message might help.
graydon has quit ["xchat exiting.."]
smkl has quit [Remote closed the connection]
smkl has joined #ocaml
jao has left #ocaml []
mrvn has joined #ocaml
mrvn_ has quit [Read error: 60 (Operation timed out)]
zack has joined #ocaml
lament has joined #ocaml
<
kev>
SoreEel: "unbound value identifier sock"
<
kev>
is the error message
two-face has joined #ocaml
two-face has quit ["Client Exiting"]
zack has left #ocaml []
<
smkl>
kev: try fun logon sock = ( send ... ; send ... )
<
kev>
yeah, that works, thanks
docelic has joined #ocaml
docelic has quit ["Client Exiting"]
MegaWatS has joined #ocaml
mattam_ is now known as mattam
lament has quit ["mental mantle"]
systems has joined #ocaml
docelic has joined #ocaml
systems has quit ["Client Exiting"]
docelic has quit ["Client Exiting"]
Torquemada has quit ["Lost terminal"]
Torquemada has joined #ocaml
<
jankr>
hi... does anyone know if that translated ocaml book is going to be printed?
<
kev>
anyone here played with jocaml at all?
docelic has joined #ocaml
<
nkoza>
there are 'scripting languages' over ocaml? i mean, can you script your ocaml applications with a more dynamic language like python or ruby?
<
kev>
you could possibly link python and ocaml modules, but I don't see why you'd want to?
<
MegaWatS>
it`s really easy to write your own scripting language in ocaml :)
<
nkoza>
to use introspection and dynamic binding
<
nkoza>
(note that i'm new to ocaml and what i'm saying maybe has little sense)
<
kev>
nkoza: it probably kinda defeats the point of the language though, no?
<
nkoza>
maybe no, maybe you can 'alternate soft & hard layers"
mattam_ has joined #ocaml
mattam has quit [Connection timed out]
nkoza has quit [Read error: 54 (Connection reset by peer)]
zack has joined #ocaml
zack is now known as zack|away
docelic has quit ["Client Exiting"]
zack|away is now known as zack
taw has joined #ocaml
<
taw>
ocamllex generated lexers keep throwing Failure exception at me
<
taw>
how can i force them to throw something more meaningful
<
taw>
so that i at least know that it's lexing problem
<
taw>
anhd can catch it
<
taw>
and do something useful
skylan has quit [Connection reset by peer]
skylan has joined #ocaml
docelic has joined #ocaml
lament has joined #ocaml
zack has left #ocaml []
<
MegaWatS>
taw: simply make a catch-all rule and put an exception there
<
MegaWatS>
. { raise (MyLexerException Lexing.lexbuf) } or somesuch
<
taw>
but how can i be sure that it's lexer what's throwing these exceptions ?
<
MegaWatS>
enclose the statement calling the lexing function with a try / catch
<
MegaWatS>
try / with srry :)
<
taw>
Lexer isn't called directly
<
taw>
render (Parser.tex_expr Lexer.token (Lexing.from_channel stdin));
<
taw>
print_string "Hurray !\n"
<
taw>
with Parsing.Parse_error -> print_string "Parse error\n"
<
taw>
| Failure "lexing: empty token" -> print_string "Lexing failure\n"
<
taw>
| Failure _ -> print_string "Other failure\n"
<
taw>
yet Failure may be thrown by render() or some other function
<
taw>
and Lexer may have other exceptions, not only "empty token"
<
MegaWatS>
the generated parser can be made to use any lexing function can`t it?
<
taw>
well, parser yes
<
MegaWatS>
then simply make an enclosing function
<
MegaWatS>
let trying_lexer ... = try real_lexer ... with ... -> ...
<
MegaWatS>
and use trrying_lexer instead of the real lexing function for lexing
<
MegaWatS>
it wuill be identical, except you can, there, exactly inspect what exceptions come out of the lexer (and not anywhere else)
MegaWatS has quit ["Actually, people sometimes talk about man's "bestial" cruelty, but that is being terribly unjust and offensive to the beasts:]
MegaWatS has joined #ocaml
docelic has quit ["Client Exiting"]
<
taw>
now how to write that function if it is more than just one ...
<
MegaWatS>
more than just one - what?
<
taw>
there is no single nice function here
<
MegaWatS>
you have several lexers?
<
taw>
Lexer.token is generated
<
taw>
Lexing.from_channel is another function
<
taw>
and they call some Lexing.engine
<
taw>
which one should i enclose ?
<
taw>
(it's one lexer)
<
MegaWatS>
the one you call?
<
taw>
well, i call parser not lexer=
<
MegaWatS>
i dont exactly remember how the parser / lexer interface works
<
MegaWatS>
but I think you give the generated parser a lexing function as an argument, right?
<
taw>
mmm, it seems so
<
MegaWatS>
then enclose the generated lexing function
<
MegaWatS>
and call the parser with your enclosing function instead fo the generated lexing function
<
taw>
exception LexerException of string
<
taw>
let lexer_token_safe =
<
taw>
try Lexer.token
<
taw>
with Failure s -> raise (LexerException s)
<
taw>
render (Parser.tex_expr lexer_token_safe (Lexing.from_channel stdin));
<
taw>
print_string "Hurray !\n"
<
taw>
with Parsing.Parse_error -> print_string "Parse error\n"
<
taw>
| Failure "lexing: empty token" -> print_string "Lexing failure\n"
<
taw>
| Failure _ -> print_string "Other failure\n"
<
taw>
and it doesn't help any
<
taw>
is it wrong function, or is it just catched during generation of closure ?
<
taw>
yup, it's just catched during generation of closure
<
MegaWatS>
you have to pass the arguments
<
MegaWatS>
let lexer_token_safe lexbuf = try Lexer.token lexbuf with Failure s -> raise (LexerException s)
<
taw>
seems to be working now, thanks for help
docelic has joined #ocaml
docelic has quit [Client Quit]
SoreEel has quit []
Yurik has joined #ocaml
<
taw>
dobry wieczur Yurik
* Yurik
finally did ensemble-based communications and is happy now
j_bravo has joined #ocaml
<
j_bravo>
hello everybody
<
Yurik>
j_bravo: hi
<
j_bravo>
im so gald i finally found the ocaml chat
<
j_bravo>
im student from the technical university of munich, germany
<
j_bravo>
studying computer science in the first semester
<
Yurik>
studying ocaml there?
<
j_bravo>
and we started out with functional programming in ocaml
<
j_bravo>
funny isnt it?
<
j_bravo>
where are you from Yurik?
<
Yurik>
j_bravo: Ukraine
<
j_bravo>
are u working with ocaml too?
<
Yurik>
yes, i'm developing in ocaml
<
j_bravo>
because i have a little coding problem here and im looking for help to be honest...
<
j_bravo>
u are...cool ;)
<
whee>
ocaml is god.
SoreEel has joined #ocaml
<
j_bravo>
well it's a pain when u are being taught the wrong way...
<
Yurik>
and what kind of problem do you have?
<
j_bravo>
may I state my problem?
<
j_bravo>
well the task is to code the LZW Algorithm...
<
j_bravo>
starting out with a string table, the alphabet
<
j_bravo>
and of course a string that need to be compressed
<
j_bravo>
i have understood the algorithm but i have problems with the syntax in ocaml
<
taw>
any deobfuscation experts here ?
<
taw>
let render tree =
<
taw>
let outtex = Texutil.mapjoin Texutil.print tree in
<
taw>
let md5 = Digest.to_hex (Digest.string outtex) in
<
taw>
let html = (try Some (Texutil.mapjoin Texutil.html_print tree) with _ -> None) in
<
taw>
let tex_fname = tmppath ^ md5 ^ ".tex" in
<
taw>
let f = open_out tex_fname in
<
taw>
print_string md5;
<
taw>
(match html with Some s -> print_string s | None -> ());
<
taw>
output_string f preface;
<
taw>
output_string f outtex;
<
taw>
output_string f footer;
<
taw>
if (Sys.command ("latex " ^ tex_fname ^ ">/dev/null") != 0)
<
taw>
then (unlink_all (tmppath ^ md5); failwith "latex failed")
<
taw>
else if (Sys.command ("dvips -E " ^ tmppath ^ md5 ^ ".dvi -o - 2>/dev/null | convert -density 150 ps:- "
<
taw>
^ finalpath ^ md5 ^ ".png") != 0)
<
taw>
then (unlink_all (tmppath ^ md5); failwith "dvips failed")
<
taw>
else unlink_all (tmppath ^ md5)
<
taw>
how to make it more functonal ?
<
Yurik>
j_bravo: what is your problem w/ ocaml syntax?
<
taw>
it looks like some ... c !
<
whee>
well you could try splitting it up into more functions
<
Yurik>
yeah, it is really c code ;))))))))
<
whee>
like the whole output part
<
taw>
it is already splited to many function-
<
whee>
make some functions local to render to handle output elsewhere so it at least looks nicer
<
taw>
it's not even correct, it should print md5 and html even if opening file fails
<
whee>
and that looks like a job for exceptions with those failwiths
<
taw>
i would like to move some prints before lets
<
whee>
so maybe split the two Sys.command things into their own functions (perhaps ones that exec and raise an exception on failure)
<
taw>
there are 3 calls to unlink_all
<
whee>
I mean that's one huge block of sideeffects, the only thing you can really do is split it into some reusable functions
graydon has joined #ocaml
<
taw>
let render2 outtex md5 tmppath2 =
<
taw>
let f = (open_out (tmppath2 ^ ".tex")) in
<
taw>
output_string f preface;
<
taw>
output_string f outtex;
<
taw>
output_string f footer;
<
taw>
if (Sys.command ("latex " ^ tmppath2 ^ ".tex >/dev/null") != 0)
<
taw>
then (unlink_all tmppath2; failwith "latex failed")
<
taw>
else if (Sys.command ("dvips -E " ^ tmppath2 ^ ".dvi -o - 2>/dev/null | convert -density 150 ps:- "
<
taw>
^ finalpath ^ md5 ^ ".png") != 0)
<
taw>
then (unlink_all tmppath2; failwith "dvips failed")
<
taw>
else unlink_all tmppath2
<
taw>
let render tree =
<
taw>
let outtex = Texutil.mapjoin Texutil.print tree in
<
taw>
let md5 = Digest.to_hex (Digest.string outtex) in
<
taw>
print_string md5;
<
taw>
(try print_string (Texutil.mapjoin Texutil.html_print tree) with _ -> ());
<
taw>
render2 outtex md5 (tmppath^md5)
<
taw>
looks a bit better now
<
taw>
how can i factor out this unlink_all ?
<
whee>
well it looks like you unlink_all no matter what
<
whee>
so just remove it from both if statements and remove the final else clause, then tack it on to that huge thing :D
<
taw>
yes, but i can't put it last as i raise
<
whee>
which raises?
<
whee>
how about you raise an exception instead of failwith
<
whee>
and enclose that in a try/with block that does unlink_all on exception
<
taw>
it must unlink_all when no exception happens too
<
taw>
ruby has some ensure statement iirc
<
whee>
you keep the unlink_all outside of all the if statements
<
whee>
but have the one on exception as well
<
whee>
yeah ruby does, I don't know if ocaml does :|
<
taw>
does ocaml has something like ensure ?
<
taw>
anyone knows ?
<
whee>
you should probably just not use failwith and handle it with exceptions
<
taw>
failwith is exception
<
taw>
let failwith s = raise (Failure s)
<
taw>
let failwith s = raise(Failure s)
gl has quit [Remote closed the connection]
<
taw>
my memory served me well ;)
<
taw>
that's exact definition
<
taw>
ocamlbrowser rule
<
whee>
I don't really know how else to deal with that other than catching that, unlink_all and reraising
lament has quit ["mental mantle"]
<
taw>
ok, now more silly problem - what was the name for argv in ocaml again ;) ?
gl has joined #ocaml
<
smkl>
perhaps something like: let ... f g = try f (); g () with a -> ( g (); raise a ) ?
<
Yurik>
taw: Sys.argv?
mellum_ has joined #ocaml
<
Yurik>
big party today? A lot of people on #ocaml today! :)
mellum has quit [Read error: 60 (Operation timed out)]
mellum_ is now known as mellum
lament has joined #ocaml
* Yurik
is thinking on new domain protocol for his project
ElCritter has joined #ocaml
<
Yurik>
ElCritter: hi
<
ElCritter>
hope you have a lot of free time...
<
ElCritter>
cause im very new to caml :-)
<
Yurik>
not so much :)
<
Yurik>
÷ÓË äÅË 1 01:23:13 EET 2002
<
Yurik>
it was in russian locale
<
Yurik>
01:23:13 am here, so I should go offline soon :(
<
taw>
russian ? not ukrainian ?
<
Yurik>
taw: yeah. my native language is russian, but I speak both. And there is not so much translations into Ukranian
<
Yurik>
taw: i mean gettext translations
<
lament>
hm, russian locale sounds fun
<
lament>
except perhaps awfully inconvenient
<
taw>
i sometimes even use japanese locale ;)
<
taw>
sometimesn polish
<
taw>
usually english
<
Yurik>
lament: why it sounds fun? :-)
<
lament>
all i18n stuff is a bitch to configure, though
<
lament>
Yurik: fun as in "sick and twisted"
<
taw>
i hope people will adopt utf8 soon
<
Yurik>
and east people will still have problems :-)))
<
Yurik>
but west will be satisfied, of course
<
taw>
japanese works well with utf8
docelic has joined #ocaml
<
Yurik>
taw: really? i thought not
<
taw>
watashi shoushou nihongo to asobimashita yo
<
Yurik>
this way works, yeah :))
<
taw>
well, kanji works well too
<
Yurik>
as I remeber, camomile author is japanese and afair (but i'm not sure) he was saying that utf8 isn't good gor japanese
<
taw>
well, it grows a bit
<
taw>
3 bytes / character
<
taw>
instead of 2 as in EUC
<
taw>
but that can't be helped
<
taw>
the real difference isn't even close to 50%
<
taw>
on average japanese HTML page, 95% is ascii markup
<
taw>
so difference is very small
gl has quit [Read error: 110 (Connection timed out)]
* Yurik
should go offline (6.66 UAH spent ;)) and work with papers... cu later!
taw has quit ["Client Exiting"]
<
Yurik>
aah, missed. 6.72
Yurik has quit ["÷ÙÛÅÌ ÉÚ XChat"]
gl has joined #ocaml
malc has joined #ocaml