<uzdav>
Anyone there? Is it safe for two threads to write into the same array at different indicies without locking?
<malc>
should be
sb98052 has quit ["Client Exiting"]
malc has quit [Remote closed the connection]
nudedude has quit ["sleepo"]
* lament
is away: my tarantula is molting!!!!
Kinners has quit ["leaving"]
lament has quit ["PROSECUTORS WILL BE TRANSGRESSICUTED."]
gehel has joined #ocaml
notkoza2 has joined #ocaml
notkoza_ has quit [Read error: 110 (Connection timed out)]
asqui has quit [Read error: 110 (Connection timed out)]
systems has joined #ocaml
systems has left #ocaml []
rgrig has joined #ocaml
rgrig has left #ocaml []
foxen5 has quit [Connection reset by peer]
foxen has joined #ocaml
aleksi has joined #ocaml
<aleksi>
hello
<aleksi>
what is the "right way" to return multiple values from a function?
<aleksi>
let foo = let a = 1 in let b = "text" in (a, b);; ??
<aleksi>
but then, how should I handle the return value, and separate the parts of the tuple?
<xtrm>
# let (a,b) = foo;;
<xtrm>
val a : int = 1
<xtrm>
val b : string = "text"
uzdav has quit [Read error: 110 (Connection timed out)]
<aleksi>
xtrm, yes, ok
<aleksi>
that's actually quite good
<aleksi>
any idea how costly this will be? with optimizations?
<aleksi>
I mean, is it better to write let a = foo_a in let b = foo_b in ... than the one above?
<aleksi>
ie. is there any memory allocations going to happen for foo's last line (a, b)?
<aleksi>
(of course there might be other considerations as well, but I'd guess the memory allocation is the slowest operation, even slower than function call.)
<aleksi>
what I might be doing wrong when my code says print_newline;; and everything is just printed together on screen?
<aleksi>
hmm... for some (obvious to others, very) weird reasons (to me) print_newline needs to have () after it to work. I wonder why.
<aleksi>
hmm... now this program got really weird
<aleksi>
the format of the program is like:
<aleksi>
let foo = ... ;;
<aleksi>
let bar = ... ;;
<aleksi>
...
<aleksi>
let zak = ... ;; (* here's first odd thing *)
<aleksi>
let f1 = ... ;;
<aleksi>
for i=0 to 10 do f1; done;; (* here's second odd thing *)
<aleksi>
the first oddness is, that zak is actually called and evaluated once, but it's never called
<aleksi>
likewise for f1
<aleksi>
whereas it should be called 10 times
<aleksi>
I'm really baffled
<aleksi>
ok.. finally solved problem
<aleksi>
and I have to say, this was quite a trap for me, and probably there exists plenty of good reasons, but stil... very hard one for me
<aleksi>
you can say let succ x = x + 1;; but in a same way you can't say (imperatively) let print_space = print_string " ";;
<aleksi>
it causes you to print the space immediately and print_space gets value () of type unit
<aleksi>
one can't either write let print_space = function -> print_string " ";; but it has to be let print_space = function () -> print_string " ";;
<aleksi>
now we have the function, thanks to the interactive ocaml, I managed to find this on my own
<aleksi>
then the call was a problem, simple print_space;; didn't work, as print_space ();; was required...
docelic has joined #ocaml
steele has joined #ocaml
mattam_ has joined #ocaml
docelic has quit ["Client Exiting"]
mattam has quit [Read error: 110 (Connection timed out)]
asqui has joined #ocaml
lament has joined #ocaml
lament has quit ["PROSECUTORS WILL BE TRANSGRESSICUTED."]
lament has joined #ocaml
uzdav has joined #ocaml
<uzdav>
are there any additional multi-threading issues to consider due to the code generation in ocaml? Specifically, is it safe to have two different threads access the same array at different offsets without locking?
olczyk has joined #ocaml
<olczyk>
What does: let () = mean?
<olczyk>
What does: let () = mean?
<olczyk>
Sorry.
docelic has joined #ocaml
<olczyk>
What does: let () = mean?
<whee>
olczyk: it looks like bad code :)
<whee>
() is the return type of things with side-effects, so it's probably used in a fashion like "let () = print_string "doop" in .."
<olczyk>
In big brother, let () - Agency.initialize begin_fun term_fun;;
<olczyk>
and let () +list.iter ( function other -> Agency add( JobInitial other) ) Settings.anonymus
<olczyk>
and other stuff like that.
<whee>
those both look like functions with side-effects, so that'd be why
<olczyk>
Ok.
graydon has joined #ocaml
foxen has quit []
foxen5 has joined #ocaml
olczyk has quit []
Dalroth has joined #ocaml
Zadeh_ has joined #ocaml
lament has quit ["PROSECUTORS WILL BE TRANSGRESSICUTED."]
Zadeh has quit [Connection timed out]
<aleksi>
whee, do you mind telling why let print_space = print_string " ";; doesn't work
<aleksi>
but let print_space () = print_string " ";; works
<aleksi>
and why print_space;; doesn't but print_space ();; does
<whee>
let print_space = print_string "blah" does work, it prints "blah" and sets print_space to ()
<aleksi>
I mean I understand that the first definition generates a value () and stores it to print_space.
<whee>
while with let print_space _ = print_string " " will create a function print_space that takes a single argument, so the print_string isn't evaluated unless the function is called
<aleksi>
whee, why let succ x = x + 1 doesn't call function x, add + 1 the value, store it in somewhere (let's call it y) and then assign function x -> y to the value of succ?
<aleksi>
I mean, I understand there's logic in both cases, but for me they seem inconsistent
<whee>
because succ is defining a function, not binding a value
<whee>
well it's binding a function to succ
<aleksi>
what makes the difference?
<whee>
let succ x = x + 1 is shorthand for let succ = function x -> x + 1
<aleksi>
is it so, that if there's a parameter in let <name> <param1> =, then it has to be a function definition
<whee>
yes
<aleksi>
ok, so if there're no parameters then it isn't a shorthand to form let ps = function -> print_string " ";;
<aleksi>
weird
<aleksi>
but I can see the utility
<steele>
function -> .. is no valid caml syntax
<aleksi>
this case was my first trap in ocaml
<steele>
there is only function x -> ..
<aleksi>
with what editor do you guys write your code?
<whee>
there's no inconsistancy, it's just a syntax difference
<whee>
I use vim
<aleksi>
ok, so I'm not going to talk to you :)
<whee>
haha
<aleksi>
steele, do you use emacs with ocaml-mode?
<steele>
xemacs
<aleksi>
ok, are there any special notations that one should adopt with it to make everyday life easier?
<aleksi>
like "write begin...end to every then and else"?
<whee>
you don't always need a begin/end, that'd be overkill
<whee>
which is better, emacs or xemacs?
<aleksi>
today we had a good long discussion about languages with my pals. One claimed he can come pretty close coding in C as with Perl, and he does both very well. So my question
<whee>
my definition of better is userbase and development activity, usually
<aleksi>
what's your experience of your development speed compared to something other, and with what experience of both?
<steele>
it's only a problem for nested match, and there i use | .. -> ( ..)
<whee>
I think C has a disadvantage when compared to any high level language
<aleksi>
steele, ok, so my begin..end thingie today was just myself messing up
<whee>
there's a lot of time spent debugging
<whee>
with ocaml, if something compiles, it probably works (assuming the logic is correct)
<steele>
and other languages (besides c++) have a disadvantage on the toolkit side to ocaml
<aleksi>
whee, you can adopt good style, and use libs for all datastructures, so you end up spending time on writing good error checking instead of debugging
<aleksi>
steele, what do you mean?
<steele>
they have no compiler at all, or a compiler that is difficult to bootstrap
<whee>
but that's up to the programmer aleksi, most programmers don't do things like that
<steele>
or it's difficult to distribute static binaries etc
<whee>
it's easier if you don't have to do it in the first place
<steele>
and c not having exceptions doesn't make it easier
<aleksi>
whee, I agree, I don't like coding in low-level. And I like things like maps and closures in Perl so that's why I'm at ocaml land.
<whee>
I haven't done C programming as a hobby for that reason
<aleksi>
steele, otoh, recent trend has been that exceptions are most of the time wrongly used goto wannabies. The idea is to restrict them to really exceptional situations and use return values and error checking as people did on 70es.
<whee>
you end up checking for errors where you really can't deal with it anyway
<aleksi>
So, what's ocaml's stance on this regard. As far as the English French book says, they should be used even to break calculation with ease.
<whee>
exceptions should be used whenever the function can't return what's requested
<aleksi>
whee, most of the time just keep passing things up in the stack, I agree
<uzdav>
Is there an efficency overhead using exceptions in ocaml? (They're expensive in C++, for exmplae.)
<uzdav>
in the docs I've seen, they suggest prematurely breaking out of a loop using an exception, but that feels wrong. (Though I know no other way to stop a for loop in ocaml.)
<aleksi>
uzdav, so you get the same feeling
<aleksi>
are you a beginner too?
<aleksi>
maybe the model we're used to is wrong. So what are the downsides of overusing exceptions all the time?
<whee>
for loops are useless :)
<uzdav>
I'm a beginner in ocaml, but pretty experienced in C++, and I carry my prejudices around. (Though I've done a lot of functional programming with Scheme.)
<steele>
aleksi: they can be misused, but I don't see a better model for error handling in other languages
<aleksi>
steele, for error handling they are good, but uzdav and I get feeling that they're used also in premature calculation disruption
<whee>
As rought approximations, I would say that raising an exception costs
<whee>
no more than, say, two calls to unknown functions, and installing an
<whee>
exception handler costs no more than one such call.
<steele>
erlang uses the approach of returning tuples {ok, 5} or {error, 4} but you have to use pattern to get the value out all the time
<whee>
(This is from Xavier Leroy)
<whee>
I really like erlang's method
<steele>
s/pattern/pattern matching/
<whee>
it gives you the opportunity to handle it right there (with case .. of ..), or to handle it elsewhere by doing {ok, Value} = somefunction
<aleksi>
whereas other languages use commonly things like "break"
<steele>
in C, using some special convention for the returned value is just plain broken
<uzdav>
so, hypothetically speaking <g>, if you use a for loop and need to break out, what do you do without an exception?
<steele>
you don't do that ;)
<whee>
you could create a reference and change that (including it in the for loop test)
<steele>
use tail recursive functions and pattern matching
<whee>
but I would recommend not using for loops unless you're dealing with arrays
<aleksi>
why "Invalid element for Array.get" exception message (or something like that) doesn't incorporate anything helpful information. Like with what index it was called?
<uzdav>
that's my situation... I'm iterating through an array, but I might need to stop. Processing each element can take a minute or more. (The overhead of the exception is miniscule in this case, but I just like to know the costs of things.)
<aleksi>
Or which array (at which address), created and accessed on which row etc.?
<uzdav>
As much as I like ocaml, I find the error messages to be only vaguely helpful. Some pattern matching errors give hints, but the syntax errors frequently give no help at all, exceptions are not reported where they originate, etc.
<aleksi>
uzdav, you should implement map_with_break which calls given func, and if the return value of tuple (real mapped return value, boolean should be still continue) contains false, then exit
<uzdav>
In fact, with only a little experimentation in the debugger, I was not able to make it break when an exception was thrown. Is this possible? (I had no idea where it was coming from.)
<steele>
about the last thing export OCAMLRUNPARAM="b=1", compile to bytecode and use ocamlerror on the backtrace
<uzdav>
cool, thanks. (BTW, what does that mean? "b=1")
<whee>
hrmf
<steele>
i guess b stands for backtrace
<uzdav>
does the map_with_break return an array or a list?
<uzdav>
Sorry, my references are not handy... :)
<whee>
I don't understand the problem with the Array module exceptions
<aleksi>
uzdav, it was just an idea. Take original map and add the tuple handling and check there in the middle.
<whee>
when you try to get something, you should know what index you called it with
<steele>
and about the syntax: use _many_ braces until you get used to it or an editor that indents your code for you
<steele>
when it wont indent "right" you see there must be a mistake
<aleksi>
whee, I wrote my first program today. I tried to find the place my code was calling Array with too high index for an hour. Too long. It would have been easier if the error message could have pointed the place from code.
<whee>
I went with using the revised syntax, I dislike the original syntax
<whee>
that's what the debugger is for :P
<aleksi>
steele good point, thanks
<whee>
because the debugger allows you to step both forward and backwards in time, finding the cause of that is just setting a breakpoint near the problem and going back to figure out where it originates
<whee>
if the exception did return everything it knew about something (even things that you already know before you make the call), then there might be added overhead of passing all that information around
<uzdav>
seems like that could be a compiler option?
<aleksi>
yes, during development I don't mind having that kind of info around
<aleksi>
of course if it makes 10MB program 60MB there might start to be some difference on opinion
<aleksi>
but even then, a compiler option and modular code should make the life easier
<steele>
i think most people catch exceptions where they happen and give a usefull message
karryall has joined #ocaml
<steele>
but i see your point with the "imperative" data structures like arrays or strings
two-face has joined #ocaml
<two-face>
yo
<karryall>
salut two-face
<whee>
aleksi: were you iterating over the entire array and had an off-by-one?
<two-face>
salut karryall
<two-face>
karryall: bien reçu (release often :-)
<aleksi>
I had for loop, the devil of everything.
<aleksi>
Nope. So I thought. The problem was actually that I had one too few handmade entries in one array.
<karryall>
two-face: ouais, avec la nouvelle année, tout ça, hop une release !
<two-face>
D00D!!!1!!1111! OCAML IS ONLY 2 TIMES FASTER THAN JAVA !!!11!!
<two-face>
karryall: super
<whee>
aleksi: I'd recommend using functions like Array.iter or Array.iteri or map/mapi and friends for doing things involving entire arrays, as well
<whee>
it's usually easier to use a list for data, though
<aleksi>
are they faster?
<whee>
unless you absolutely need the constant time access of an array
<aleksi>
for this thing I need speed
<whee>
lists are a lot more flexible
<karryall>
two-face: bon, et kamel, ocaml-qt ça en est où ?
<aleksi>
I usually prefer high-orderness, I like it more and I had to fight myself to write this in imperative mode
<whee>
what exactly does the program do?
<two-face>
karryall: je vais relancer sur la liste
<karryall>
two-face: 'tain, c'est cool le type là il trouve plein de bugs dans ocamlsdl
<two-face>
karryall: au départ, il veulent faire un générateur de bindings
<karryall>
two-face: je pense qu'ils ont raison
<two-face>
karryall: oui et non
<karryall>
c'est vraiment énorme sinon
<aleksi>
are you sure you guys aren't speaking english, as there are so many english words in your language :)
<aleksi>
actually it's great to see something else written too
<two-face>
aleksi: sorry we speak French :)
<aleksi>
it's all ok
<aleksi>
I could show you some Finnish :)
<two-face>
aleksi: it is rude but you all would n't be interested in what we are talking about :)
<two-face>
aleksi: olen ranskalainen
<karryall>
aleksi: do you know why are there so many scandinavian people in this channel ?
<whee>
heh, I can't even think of a usage for arrays in the programs I write
<two-face>
karryall: en faisant des macros en C comme jacques, tu fait 1 ligne par fonction
<karryall>
two-face: je sais mais dès que tu as des truc compliqués (pas que des ints et des floats) ça devient plus compliqué
<karryall>
two-face: et du coup il y a plus de boulot du côté ML
<two-face>
karryall: même avec des macros?
<two-face>
karryall: le problème ici aussi c'est C++
<karryall>
two-face: des macros bien velues alors
<aleksi>
two-face: Comme on fait son lit on se couche.
<aleksi>
it's your fault!
<karryall>
two-face: y'a quoi comme générateurs de bindings pour C++ ? SWIG et c'est tout je crois ?
<two-face>
aleksi: :)
<two-face>
karryall: oui mais c pas au point
<karryall>
two-face: j'ai jamais essayé
<two-face>
karryall: je me demande tout compte fait si ça ne sera pas prise de tête :)
<aleksi>
you french people do such a great language and good implementation that all we people living here cold have to keep warm by utilising the greatest heat dissipator (our head) by trying to learn french tricks.
<uzdav>
I used to speak french (un peu) but j'ai oublier tout.
<two-face>
aleksi: swedish people invented Erlang which is great too, isn't it? :)
<karryall>
two-face: quoi, SWIG ou les macros ?
<two-face>
karryall: kde/qt :)
<aleksi>
I wouldn't say so.
<whee>
americans are too used to accepting things as they are, and not fixing problems :P
<aleksi>
They use it at Ericsson, and look how it started to go for it after they started to use Erlang.
<whee>
erlang owns, though
<aleksi>
Nokia rules, and ruled over it. :)
<whee>
I'm using erlang for an irc bot (hooray) that I'm writing
<uzdav>
does ocaml's implementation use setjmp/longjmp anywhere?
<two-face>
whee: manderlbot.tuxfamily.org
<whee>
uzdav: yes, it's used in exceptions for one
<whee>
two-face: I saw that, I didn't like the design
<aleksi>
(actually I've looked at it twice but neither time got enought momentum to make me jump over the threshold. So I like it, but not yet enough. :)
<two-face>
whee: i had course from franscesco cesarini about OPT
<two-face>
whee: OTP
<two-face>
karryall: je me demandesi je ne vais pas revenir à mon binding X11 :)
<whee>
I based my decision on an earler version fo manderlbot, though
<uzdav>
I see something about C++ and SWIG, and it makes me want to warn about longjmp over a C++ object destructor is undefined and very dangerous. So wrapping C++ code to call into ocaml must be done *very* carefully.
<karryall>
two-face: c'est intéressant aussi
<two-face>
karryall: un WM en ocaml, j'en rêve
<whee>
mine uses supervisors and gen_event for all the fun, it's all independent and any process can die without screwing anything up
<karryall>
uzdav: I know about that, it's tricky yes
<karryall>
two-face: ben ça existe déjà
<two-face>
karryall: je sais, mais pas comme je veux :)
<karryall>
arf
<two-face>
karryall: disons que l'approche de réimpl x en ocaml n'est pas bonne à mon sens
<karryall>
two-face: 'faut se méfier de l'empilage de couche aussi
<karryall>
X -> X11 -> GDK -> GTK -> LablGTK (en 3 couches)
<karryall>
ça fait bcp
<two-face>
karryall: ça marche bien non ? :)
<karryall>
two-face: bien mais pas vite
<whee>
heh, now I really don'y like manderlbot's design
<whee>
it's not quite as modular as mine :)
<karryall>
whee: the name's pretty cool, though
<two-face>
karryall: tu trouves que c lent?
<karryall>
oui
<two-face>
karryall: même en natif ?
<karryall>
ouais
<two-face>
whee: well, it is a matter of taste :)
<whee>
I suppose
<two-face>
karryall: comment résoudre le pb?
<karryall>
two-face: si je le savais ...
<two-face>
karryall: à mon avis en natif les couches sont applaties, côté ocaml
<karryall>
two-face: pas tellement, y'a des objets partout
<karryall>
parfois il faut parcourir 3 objects pour aller appeler le stub C