<tobiasBora>
thizanne: Of course... Thanks a lot !
<thizanne>
no problem, hope you'll beat carl (btw there is a #ocaml-fr channel if you want)
raichoo has joined #ocaml
<tobiasBora>
thizanne: I hope too ^^ I affirme to my little brother that when we have 6 head for exemple, the probabilité of having a head after is 1/2... And he doesn't believe me. So I make this program, but with the default seed I always lose 2000 - 4000... And found it a bit strange ^^
<tobiasBora>
*heads
<tobiasBora>
*I found
ontologiae has quit [Ping timeout: 276 seconds]
ontologiae has joined #ocaml
Anarchos has joined #ocaml
hkBst_ has joined #ocaml
hkBst has quit [Ping timeout: 245 seconds]
Drup has joined #ocaml
nalaginrut has quit [Ping timeout: 272 seconds]
ttamttam1 has joined #ocaml
ttamttam has quit [Ping timeout: 245 seconds]
q66 has joined #ocaml
zpe has joined #ocaml
Neros has quit [Ping timeout: 256 seconds]
SanderM has joined #ocaml
_andre has joined #ocaml
testcocoon has quit [Quit: Coyote finally caught me]
madroach has quit [Quit: leaving]
zpe has quit [Remote host closed the connection]
tane has joined #ocaml
testcocoon has joined #ocaml
Drup has quit [Ping timeout: 260 seconds]
Neros has joined #ocaml
ttamttam1 has quit [Quit: ttamttam1]
tane has quit [Quit: Verlassend]
beginner42 has joined #ocaml
Drup has joined #ocaml
beckerb has joined #ocaml
Neros has quit [Ping timeout: 252 seconds]
mbac has joined #ocaml
dsheets has joined #ocaml
Neros has joined #ocaml
ttamttam has joined #ocaml
hkBst_ has quit [Ping timeout: 245 seconds]
hkBst_ has joined #ocaml
hkBst_ has quit [Changing host]
hkBst_ has joined #ocaml
awm22 has quit [Quit: Leaving.]
awm22 has joined #ocaml
ttamttam has quit [Quit: ttamttam]
travisbrady has joined #ocaml
raichoo has quit [Quit: leaving]
Tobu has quit [Ping timeout: 246 seconds]
Tobu has joined #ocaml
raichoo has joined #ocaml
darkf has quit [Quit: Leaving]
ggherdov has joined #ocaml
yezariaely has quit [Remote host closed the connection]
yezariaely has joined #ocaml
travisbrady has quit [Quit: travisbrady]
travisbrady has joined #ocaml
hkBst_ has quit [Ping timeout: 252 seconds]
hkBst_ has joined #ocaml
hkBst_ has quit [Ping timeout: 245 seconds]
Anarchos has quit [Ping timeout: 264 seconds]
hkBst_ has joined #ocaml
hkBst_ has quit [Changing host]
hkBst_ has joined #ocaml
hkBst_ has quit [Client Quit]
tobiasBora has quit [Quit: Konversation terminated!]
jamii has joined #ocaml
ttamttam has joined #ocaml
cdidd has joined #ocaml
astro73|mal has quit [Remote host closed the connection]
ttamttam has left #ocaml []
dwmw2 has quit [Read error: Connection reset by peer]
tianon has quit [Read error: Connection reset by peer]
dwmw2_gone has joined #ocaml
mika1 has quit [Quit: Leaving.]
tianon has joined #ocaml
Arsenik has quit [Read error: Connection reset by peer]
redfire has joined #ocaml
zpe has joined #ocaml
Arsenik has joined #ocaml
jsvgoncalves has joined #ocaml
madroach has joined #ocaml
Neros has quit [Ping timeout: 245 seconds]
barbapapa has quit [Remote host closed the connection]
beckerb has quit [Quit: Konversation terminated!]
zpe has quit [Remote host closed the connection]
travisbrady has quit [Quit: travisbrady]
Tobu has quit []
rgrinberg has joined #ocaml
SanderM has quit [Remote host closed the connection]
zpe has joined #ocaml
jsvgoncalves has quit [Ping timeout: 248 seconds]
ontologiae has quit [Ping timeout: 256 seconds]
Anarchos has joined #ocaml
awm22 has quit [Ping timeout: 264 seconds]
Fullma has quit [Ping timeout: 245 seconds]
rgrinberg has quit [Ping timeout: 248 seconds]
<wmeyer>
hi
<dsheets>
hola
zpe has quit [Remote host closed the connection]
jamii has quit [Ping timeout: 260 seconds]
<Anarchos>
Is it safe to call twice caml_c_thread_register in the same thread ?
<wmeyer>
Anarchos: I don't know, but I'd think yes. The question is why do you need to do it twice.
ttamttam has joined #ocaml
ttamttam has left #ocaml []
ulfdoz has joined #ocaml
Neros has joined #ocaml
watermind has joined #ocaml
<Anarchos>
wmeyer because i don't know where to call it, so i do it every time i want to make a callback to ocaml
<wmeyer>
this pattern might help you, void my_c_thread_register() { static int initted = false; if (!initted) { caml_c_thread_register(); initted = true; } }
<Anarchos>
wmeyer is this static bool thread safe ??
<wmeyer>
of course it's
<mbac>
that sounds like a disaster
<wmeyer>
mbac: why?
<wmeyer>
it does not, if it's done in a way presented
<wmeyer>
in fact this is standard idiom
<mbac>
oh, general fear of the word threads
<wmeyer>
ok mbac :-)
<mbac>
oh also isn't there a race condition?
<wmeyer>
it's assigned just once to false, and just once to true
<wmeyer>
more over assignment to fals is done in a static section, which means it's done very early
<mbac>
no i mean between the test of initted and the set to true
zpe has joined #ocaml
<wmeyer>
also, both assigments are atomic
<wmeyer>
yes, but it does not switch to true -> false
<wmeyer>
only to false -> true and just once
<ousado>
what does caml_c_thread_register do?
<wmeyer>
every created C thread must call this routine at the init time
<wmeyer>
(I don't know yet what it does in the essence, but I suppose it's something to do with global lock)
<Anarchos>
wmeyer it registers its stack pointers to the ocaml runtime
<wmeyer>
oh hear you go ousado , Anarchos has explained!
<ousado>
shouldn't initted be thread local then?
<Anarchos>
wmeyer but i understand little of the runtime code
<mbac>
what if your thread calls my_c_thread_register during init, is pre-empted by a signal during execution of caml_c_thread_register by signal delivery, your thread has a signal handler for the pre-empting signal, and your signal handler calls my_c_thread_register? ;)
<wmeyer>
ousado: yes, but i assume for each thread, we have different function, or just pass the context
<ousado>
ok
<Anarchos>
mbac you are looking for trouble then :)
<wmeyer>
mbac: that's a complicated use case :-)
<mbac>
don't worry, someone will manage to trip over it
<wmeyer>
ousado: in fact i was looking at a single additional thread
zpe has quit [Ping timeout: 264 seconds]
<ousado>
wmeyer: yup, just wanted to make sure I understand the purpose of the function
<ousado>
since registering the main ocaml thread wouldn't really make sense
<ggole>
wmeyer: that's not thread safe at all O_o
<ousado>
worst case is that a thread is registered twice
<wmeyer>
ggole: show me a case where it's not when calling it in a single additional thread :-)
<wmeyer>
it's too obvious that you have to have different copies of the static variable, if you plan additional threads beside the additional one created
<mbac>
it's not threadsafe but it doesn't need to be. there's no shared resource
<wmeyer>
yes, i was wrong saying: "of course" that's a fair point, but I meant a simple use case
<mbac>
my fear is that it's not re-entrant
<mbac>
but the case where that matters is pathological
<ggole>
wmeyer: it's a data race. Of course it isn't thread safe.
<wmeyer>
in general it should scale to
<mbac>
this non-ocaml discussion is the liveliest discussion happening here today
<wmeyer>
mbac: yeah, it's friday!
<wmeyer>
<Anarchos>
my problem is that the OS , not my app, create threads that calls my C++ code which makes callback to ocaml
<Anarchos>
so i have no idea how to use caml_c_thread_register...
<ousado>
but you trigger the creation of the threads, right?
Drup has quit [Ping timeout: 276 seconds]
<ousado>
Anarchos: which API do you use?
<mbac>
why not have a separate ocaml process that you communicate with via C++ through a serialized pipeline?
<Anarchos>
ousado the native api of my OS
<mbac>
(the combination of threads, C++, ocaml makes me especially fearful)
<Anarchos>
mbac i know
<ggole>
Anarchos: keep a static thread local indicating that the thread has/has not been registered
<ousado>
Anarchos: pthreads? .. so pthread_create?
<ggole>
You'll have to check it on every entry point though, which might suck pretty hard
ontologiae has joined #ocaml
<Anarchos>
ggole isn't it the purpose of the tls_set in caml_c_thread_register ?
<ggole>
Er, not following you
<ggole>
Isn't the purpose for *you* to know whether you need to register a thread?
<ousado>
do your threads have a mainloop of some kind?
<ousado>
or are they "single-purpose"
<Anarchos>
ousado both...
zpe has joined #ocaml
<ggole>
Too late for me, I'm off. Good luck with your problem.
ggole has quit []
<ousado>
for those that have a mainloop, you can make the setup and only enter the mainloop after the thread is registered, from that point on you know that everything is nice and you don't have to care
<ousado>
actually that applies to both.. I'm not sure where the problem is
zpe has quit [Ping timeout: 252 seconds]
ontologiae has quit [Quit: leaving]
ontologiae has joined #ocaml
malfunct has joined #ocaml
chrisdotcode has joined #ocaml
chrisdotcode_ has quit [Ping timeout: 252 seconds]
Drup has joined #ocaml
ontologiae has quit [Ping timeout: 252 seconds]
vext01 has joined #ocaml
<vext01>
howdy
<vext01>
are varargs possible in ocaml?
<vext01>
im not finding hits on google
<ousado>
vext01: pass a list of some data type?
watermind has quit [Quit: Konversation terminated!]
<ousado>
vext01: and maybe take a look at 'labeled arguments'
<vext01>
i guess context may help
<vext01>
for fun im writing a reverse polish calculator
<vext01>
just to learn more about ocaml really
<vext01>
at the moment i have a mapping from operators "string" to a variant function type
<vext01>
the constructors are for example BinaryOp of (Num.num -> Num.num -> Num.num)
<vext01>
enumerating all arities will be lame
<vext01>
so i want to pass the number of arguments and the function to call instead
pkrnj has joined #ocaml
<Cypi>
You can't do exactly what you want, but you could just register a (int, Num.num list -> Num.num) for each operator.
_eko has left #ocaml []
<vext01>
i see
<vext01>
that could work
<vext01>
thanks
<vext01>
one more, i want to print the stack upside down
<vext01>
by the stack, i mean, the calculators stack
<vext01>
iter iterates in the wrong direction
<vext01>
I have a recursive function that prints the stack upside down, but sadly it empties the stack in doing so
<vext01>
so i have to copy the stack just to print it :P
<Cypi>
If you're really using a Stack, then yes, a Stack can't be traversed without popping its elements. (That's what a stack is ^^ )
<vext01>
indeed
<vext01>
Cypi: having said that, Stack has iter :P
<Cypi>
Yes, but you can actually write what you want.
<Cypi>
let rec f s = try let x = pop s in f s; do_something x; push x s with Empty -> ()
<Cypi>
Something like that
<vext01>
hah
<vext01>
didnt think of that
<vext01>
thanks
<Drup>
or just use iter with a reference to do a "to_list"
jsvgoncalves has joined #ocaml
Fullma has joined #ocaml
<wmeyer>
vext01: you could also just use list, and stay pure
<orbitz>
pure as a babies bottom
<wmeyer>
orbitz: lol
<dsheets>
"stay pure; don't mutate until you get to the Real World"?
<malfunct>
i have a simple logging function that goes like this: let logf fmt = fprintf logfile (fmt ^^ "!")
<malfunct>
but i just noticed that "!" doesn't flush the output, if I hit CTRL-C, the log is lost. how to fix this elegantly?
gnuvince has quit [Remote host closed the connection]
ollehar has quit [Ping timeout: 252 seconds]
<Anarchos>
thanks Ptival
<Anarchos>
Ptival what is happening is that thread 1 calls caml_c_thread_register() while thread 2 has already called caml_acquire_runtime_system(). As caml_c_thread_register calls leave_blocking_section(), it fails on the assertion of caml_leave_blocking_section() :(
travisbrady has joined #ocaml
<Anarchos>
Ptival arf : line 1165 a comment about a segfault on caml_c_thread_register :)
tobiasBora has joined #ocaml
<tobiasBora>
Hello,
<tobiasBora>
I'd like to create a debug function which call Printf.printf. I tried to do this :
<wmeyer>
if anybody wants an access, giving straight away without hesistation
jcao219 has joined #ocaml
<tobiasBora>
It seems nice ^^ Sorry, my level isn't high enough to help you !
<jcao219>
I have to learn ocaml probably, hehe
<jcao219>
college might require it
<tobiasBora>
Just, does anyone knows how I could take an undermined number of argument (like Printf.print) to create my debug function ?
<wmeyer>
rks_: while I agree it might be boring :) it's also good play field for things like custom guis, sound libraries, opengl bindings, client server programming, reactive guis (maybe not entirelly theorem proving but ...)
<orbitz>
tobiasBora: kprintf or soemthign
<wmeyer>
def-lkb: if you have time to contribute, i am really open
<wmeyer>
last time I looked (was another 6m or so) was the GUI library on React
<wmeyer>
tobiasBora: Sorry I don't remember how I've done that, but orbitz hint seems to be valid from what I recall
<rks_>
(second that)
<tobiasBora>
orbitz: I don't understand what do you mean... How kprintf could do it ?
<tobiasBora>
you mean look in the code of kprintf ?
<def-lkb>
wmeyer: not before… hmm, october :(. if it's not too late, I may consider working on it during my spare time :)
jsvgoncalves has quit [Ping timeout: 264 seconds]
<orbitz>
tobiasBora: no, i mean kprintf is the function you use to implement your own magic formatting functins
<wmeyer>
def-lkb: it will be never late! most likely this project will be not finished in my life time :)
<vext01>
hm
<vext01>
noob question: let x = try read_line() with End_of_file -> exit 0; "" in ...
redfire has quit [Quit: WeeChat 0.3.8]
<wmeyer>
def-lkb: I'm looking forward october
<vext01>
is clearly incorrect as the compiler whines
<orbitz>
no it's ksprintf
<vext01>
obviously, if I exit i cant satisfy the type contract
<vext01>
what is the correct way?
smerz_ has joined #ocaml
<wmeyer>
so exit should have this signature: val exit : int -> 'a
<wmeyer>
so it should work if you remove ""
jsvgoncalves has joined #ocaml
<vext01>
indeed
<vext01>
somehow i expecte exit to return unit
<wmeyer>
vext01: it's actually very logical :-)
<wmeyer>
nevertheless exit never returns so using polymorphic type is safe and justified
<vext01>
is there a decent description of these somewhere?
<vext01>
the option docs are not in plain enough english for the likes of myself
<wmeyer>
tobiasBora: it looks like two branches of if have different types
<tobiasBora>
wmeyer: but it compile : val print_d : (unit, out_channel, unit) format -> unit = <fun>.
<wmeyer>
the "then" and "else" branches should have the same type
<vext01>
oh wait, does Some and None exist just for variant types which need a corner case?
<wmeyer>
vext01: so option type is built in as list, but don't have a separate module - probably because it would be very lean
<tobiasBora>
*um I gave you the wrong signature : val print_d : (string -> string) -> ('a, unit, string, string) format4 -> 'a = <fun>
<Drup>
vext01: the only thing you need to know about option is the definition of the type : "type 'a option = None | Some of 'a"
<orbitz>
tobiasBora: why do you pass format in one branch and a function in another?
<vext01>
is the typical use case 'type blah = None | Some of int;;'?
<orbitz>
vext01: 'a option already exists
<Drup>
vext01: the type already exist, you just use the constructors.
<wmeyer>
vext01: in essence option type is a bit like nullified type, it can be empty or contain something
<tobiasBora>
orbitz: I don't understand. format will contain "Text with %s and %d" PLUS the variables or only the string ?
<orbitz>
tobiasBora: print_d takes a format parameter, what is that?
<vext01>
ok, i get it
<orbitz>
tobiasBora: anyways, you probably want let print_d = Pritnf.ksprintf (fun s -> if !debug_mode then print_endline s else ())
<vext01>
this made it clear to me: let a = [ Some 10; None];;
<tobiasBora>
orbitz: it's all the question ^^ I saw in the printf function that it need only one parameters and I saw it must be a "format" string. That's why I called it format. But I don't really understand how this function works...
<wmeyer>
rks_: yes, gui libraries are fun, I've tried to use React but currently can't converge to something I'd be 100% happy :)
travisbrady has quit [Quit: travisbrady]
<wmeyer>
I tried to use objects more succesfuly
<Drup>
tobiasBora: the printfs functions are a bit strange : they take a format, which is *not* a string, with this format, they generate a new function that take the good number of arguments. If I recall correctly, the implementation is magic/hacky. :]
<tobiasBora>
orbitz: Oua... Thanks a lot ! If you have a little bit of time, could you explain some point of this function ? Who is "s" in the function ? For exemple, in "print_d "Hello, I'm %d" age; , s is a) "Hello I'm %d", b) "Hello I'm 18" c)... Other
<orbitz>
tobiasBora: b
<orbitz>
tobiasBora: ksprintf takes a function, which takes a string, and it performs the fomratting and calls said function with the result
<orbitz>
and returns whatever said function retunrs
<tobiasBora>
Drup: orbitz : Ok I understand a bit better know... So to sum up, kprintf will take the format string, convert it in a function (by gessing the number of arguments...), call this function on the arguments given to print_d, and after send the result to the function given in second parameter to ksprintf ?
<Drup>
except the fact that ksprintf take first a function then a format, yes.
<rks_>
wmeyer: :)
<Drup>
wmeyer: if you try to do a functional interface to your graphic library, glMLite contain a small attempt to do a functional interface for openGL. It's very experimental. :D
<tobiasBora>
Drup: orbitz : Ok, I've understood the main Idea, after I think it's a bit that the replacement by the new function is a bit more complex. Anyway, thanks a lot for your help !
Neros has quit [Ping timeout: 256 seconds]
<tobiasBora>
Um... I've again a little question : I've made this function to convert the format into string : let string_d = Printf.ksprintf (fun s -> if !debug_mode then s else "");;
<tobiasBora>
Is it possible to use this function to display the string, somethink like let print_d = print string_d;; ?
<tobiasBora>
s/print/print_string
<tobiasBora>
The problem is with the parentheses...
<Drup>
Not without using the same magic that the one involved in printf.
<tobiasBora>
Ok thanks !
ontologiae has joined #ocaml
tobiasBora has quit [Quit: Konversation terminated!]
ontologiae has quit [Ping timeout: 260 seconds]
Arsenik has quit [Remote host closed the connection]