cjeris changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/
david_koontz has quit ["This computer has gone to sleep"]
david_koontz has joined #ocaml
david_koontz has quit [Client Quit]
jlouis_ has joined #ocaml
jlouis has quit [Operation timed out]
hs` has joined #ocaml
<hs`> hi... need some help! please dont tell me to rtfm :)
<hs`> here's the deal: i'm writing some ocaml + opengl program, and i need to store several "points" from the mouse.. but since these points are saved inside a callback function, i need to have a global list to store them
<hs`> now i'm trying to add values to that list inside the callback function, but i cant... what would be the syntax for that? I must alter the variable... the let..in works only inside the block...
<hs`> in fact these 5 line example shows the same thing:
<hs`> let x = [];;
<hs`> let _ =
<hs`> Printf.printf "lenght: %d\n" (List.length x) ;
<hs`> x = 1 :: x ;
<hs`> Printf.printf "lenght: %d\n" (List.length x)
<hs`>
<malc_> hs`: let list = ref [] let add_stuff elem = list := elem :: list;;
<malc_> erm..
<malc_> list := elem :: !list;;
<hs`> uhum, this is working... so in these cases i must use a "real" variable...
<hs`> what is the ! operator ?
araujo has joined #ocaml
<araujo> hello
<hs`> hello
<hs`> any brazilian here?
<araujo> how is the gtk2 support on ocaml?
<hs`> i came accross a nice tutorial listed on reddit today, btw...
<mbishop> lablgtk2 is great
<araujo> thanks
<hs`> sure
<mbishop> I submitted that, btw :P
<araujo> it only supports 2.6?
Smerdyakov has quit ["Leaving"]
hs` has quit ["good nite ocamlers"]
Naked has joined #ocaml
Hadaka has quit [Read error: 111 (Connection refused)]
Naked is now known as Hadaka
pango has quit [Remote closed the connection]
pango has joined #ocaml
Naked has joined #ocaml
Hadaka has quit [Read error: 113 (No route to host)]
pango has quit [Remote closed the connection]
ikaros has quit [Read error: 113 (No route to host)]
pango has joined #ocaml
Naked_ has joined #ocaml
Naked_ is now known as Hadaka
ikaros has joined #ocaml
Naked has quit [Read error: 111 (Connection refused)]
david_koontz has joined #ocaml
G_ has joined #ocaml
Mr_Awesome has quit ["...and the Awesome level drops"]
G has quit [Connection timed out]
G_ is now known as G
<flux> something off-topic, but this is a fun way to implement tic-tac-toe: http://koti.mbnet.fi/pllk/muut/rnolla.html#0
bluestorm_ has joined #ocaml
benny has joined #ocaml
benny_ has quit [Read error: 60 (Operation timed out)]
love-pingoo has joined #ocaml
screwt8 has quit [Remote closed the connection]
sourcerror has quit [No route to host]
screwt8 has joined #ocaml
screwt8 has quit [Remote closed the connection]
screwt8 has joined #ocaml
Submarine has quit [Remote closed the connection]
smimou has joined #ocaml
love-pingoo has quit ["Connection reset by pear"]
jlouis_ has quit [Remote closed the connection]
TaXules has joined #ocaml
love-pingoo has joined #ocaml
david_koontz has quit ["This computer has gone to sleep"]
joshcryer has quit [Client Quit]
malc_ has quit ["leaving"]
Submarine has joined #ocaml
pedro_soc has joined #ocaml
franka_ has joined #ocaml
<franka_> Hello, all.
franka_ has quit []
<mrvn_> hi
<mrvn_> and he's gone.
mrvn_ is now known as mrvn
svenl has quit [Remote closed the connection]
Types_and_Kinds has joined #ocaml
ramky has joined #ocaml
vorago has quit [Read error: 110 (Connection timed out)]
vorago has joined #ocaml
ramki has quit [Read error: 110 (Connection timed out)]
svenl has joined #ocaml
<svenl> E/win move 8
smimram has joined #ocaml
smim_ has joined #ocaml
smimou has quit [Read error: 110 (Connection timed out)]
smim_ is now known as smimou
smimram has quit [Read error: 110 (Connection timed out)]
mikeX has joined #ocaml
lmbdwr has left #ocaml []
<pedro_soc> hi, anyone can explain me curried function.
<pedro_soc> let add_one = (+) 1;;
<pedro_soc> add_one 10
<pedro_soc> - : int = 11- : int = 11
<flux> I'm not sure how much I can explain it. it's the same as let add_one x = (+) 1 x
<flux> and a + b is the same as (+) a b
<pedro_soc> umm something like in lisp ??
<pedro_soc> do you know a illustrative example ?
<flux> I don't think lisp has currying, but it does use the same notation 'function arg1 arg2 .. argn'
<mrvn> Currying means that you can apply arguments to a function one at a time
<flux> any operator in ocaml can be converted into a function with (operator)
<mrvn> # let sum a b c = a + b + c;;
<mrvn> val sum : int -> int -> int -> int = <fun>
<mrvn> # let inc_sum = sum 1;;
<mrvn> val inc_sum : int -> int -> int = <fun>
<mrvn> Every time you apply one argument you get a new function back with one argument less.
OatTop has joined #ocaml
<mrvn> "Simply put, currying is the transformation of an input into a new function, the new function requiring another input of course. For example f(x) = gx(y), where gx(y) = x + y. Therefore you can say that f(x)(y) = x + y, which means that instead of using a 2 dimensional cartesian input, ie f(x,y), you are using a 1 dimensional input and giving the output another input which will finally produce the result sought" to use wikipedia
<pedro_soc> ok i think i understand. if the input of the funtion its not complete, we have a new function with one less parameter. No?
<mrvn> yes.
<mrvn> Unlike # let add (a, b) = a + b;;
<mrvn> val add : int * int -> int = <fun>
<mrvn> # let inc = add 1;;
<mrvn> This expression has type int but is here used with type int * int
<mrvn> That would be without currying.
<pedro_soc> ok, will be this currying?
<pedro_soc> let sum a b = a+b;;
<pedro_soc> let inc = sum 1;;
<pedro_soc> inc 55;;
<mrvn> To demonstrate that ocaml does real currying you have to use something like this # let add = function a -> Printf.printf "add got a = %d\n" a; function b -> Printf.printf "add got b = %d\n" b; a+b;;
<mrvn> val add : int -> int -> int = <fun>
<mrvn> # let inc = add 1;;
<mrvn> add got a = 1
<mrvn> val inc : int -> int = <fun>
<mrvn> # inc 55;;
<mrvn> add got b = 55
<mrvn> - : int = 56
<mrvn> Every function in ocaml is curried. You have to actively use tuples to not do that.
<mrvn> 'let add a b = a+b' is just syntactic suggar for 'let add = function a -> function b -> a+b'
svenl has quit [Remote closed the connection]
<pedro_soc> aha, i get it.
OatTop has left #ocaml []
<pedro_soc> thanks for the explanation.
<flux> hmph, linux epoll_ctl cannot be used with for example /dev/zero or regular files
svenl has joined #ocaml
<flux> apparently linux doesn't support the idea of reading a file in a non-blocking fashion
<flux> so, what, fork a process to feed it to a pipe?-)
<flux> (not really critical for me, I don't handle files that much, but annoying)
<svenl> flux: Unix. val set_nonblock : file_descr -> unit
<flux> yes, but apparently select always returns true, and epoll doesn't even support regular files
<svenl> flux: you create the file_descr, and then call set_nonblock.
<svenl> flux i use it for sockets though; and it works fine.
<flux> yes, sockets are a different beast
<flux> maybe asynchronous IO is what I'm looking for
<svenl> epoll is not ssupported by the unix module though.
<flux> nope, but it is by Libevent
<svenl> ah
<flux> which btw isn't quite stable, the next release will probably be
<svenl> well, if you do the, non-block, you will be able to do reads on the,; and if there is nothing to read, they return -EAGAIN.
<flux> I wonder if that's actually true. maybe I should test it out.
<mrvn> flux: I have some bindings for libaio.
<svenl> hi mrvn
<flux> mrvn, I was just thinking if there were :)
<mrvn> flux: For a normal FD what would mean the FD is ready for read or write?
<flux> mrvn, have a link for the .mli?
<flux> mrvn, yes.
<flux> mrvn, hm, so how do you know IO is ready?
<mrvn> And http://paste.debian.net/26019 to test it
G_ has joined #ocaml
<mrvn> flux: That is the "some" part.
<flux> :)
<mrvn> extern int io_getevents(io_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct timespec *timeout); will tell you.
<flux> well, my app is very network-io-bound so this stuff isn't very relevant. but nice to know it's there.
<flux> it'd be nice if one were able to select or epoll on those events
<flux> there is no such thing?-o
<mrvn> you could read/write to sockets with libaio I guess.
<mrvn> What happens when you select on a real file? Doesn't it always return directly?
<flux> according to the mailing lists, yes
<mrvn> You could create a pipe and pass your aio events through there from another thread.
<flux> yes, I thought of that (ref backlog ;)), but my disk-IO-needs are minimal now
<mrvn> Alternatively there is mmap, msync and madvice
<flux> yeah, but you can't select on memory, so isn't that even more troublesome?
<flux> or unless you mean another thread would maintain some counters and report them back to me via a pipe or something
<flux> that would work, but be tricky
<mrvn> yes
<flux> I would just like the unix 'everything is a file' to really work with everything: mutexes, semaphores, processes dying, disk io arrived, etc
<flux> freebsd had something like that?
<flux> it's darn troublesome to simultanously wait for IO and a pthread condition
<mrvn> But disk IO doesn't block as such. It just takes time.
<flux> I call that blocking
<flux> while I'm at it (ranting ;-)), a portably readable uptime-counter would also be nice
<flux> I wonder how many pieces of software break when the system time is adjusted
<mrvn> There is no buffer that the disk will fill so it is ready for read.
<flux> mrvn, there is readahead buffers, no?
<flux> mrvn, and the write buffers may be full
<flux> or atleast the os doesn't want to make more such buffers
Types_and_Kinds has quit []
G has quit [Connection timed out]
<mrvn> flux: it would be nice but unix afaik never worked that way.
<flux> right. but it's one phrase can has been used to describe the unix ideology.
<flux> I think Plan9 gets it right, but I haven't used it
pango has quit [Remote closed the connection]
pango has joined #ocaml
ikaros has quit [Read error: 110 (Connection timed out)]
ikaros has joined #ocaml
ikaros has quit [Client Quit]
sourcerror has joined #ocaml
beschmi has joined #ocaml
Smerdyakov has joined #ocaml
<love-pingoo> is it possible to produce two tokens at once using ocamllex
<love-pingoo> ?
<flux> hmm.. what do you mean?
<flux> or rather: what are you attempting to do..
<mrvn> no. But you can have a token buffer inside and store the token for the next call.
<love-pingoo> I have the following regexps in my lexer: "and", var (that is [a-z]+) but also var ' '+ '('
<love-pingoo> problem is that "and (" gets parsed by the third regexp
<love-pingoo> a quick fix would be to add "and" ' '+ '('
<love-pingoo> and produce AND and LPAR instead of my compound VARLPAR
<Smerdyakov> That's a very unusual choice of division between lexing and parsing.
<Smerdyakov> The standard approach would have regexps for and, var, and open-paren.
<Smerdyakov> The parser would sort out the rest.
<love-pingoo> I know, my compound VARLPAR is a way to have a generally whitespace insensitive language without ; for sequence
<love-pingoo> it helps me tell x \n (1,2) from x(1,2)
<Smerdyakov> Why do you want to tell the difference between those?
<love-pingoo> because one is x ; (1,2) while the other is x(1,2)
<flux> love-pingoo, why don't you interpret \n as ';' ?
<love-pingoo> except that I don't have a semicolon
<love-pingoo> I'll write a regexp that matches any var but "and" and "or"... that's painful
<love-pingoo> flux: cause then I'd have to handle all the cases when \n is not really a ; in the grammar
love-pingoo has quit ["Leaving"]
pango has quit [Remote closed the connection]
pango has joined #ocaml
tree has quit [Nick collision from services.]
tree has joined #ocaml
tree has quit [Nick collision from services.]
david_koontz has joined #ocaml
tree_ has joined #ocaml
Submarine has quit [Remote closed the connection]
joshcryer has joined #ocaml
jlouis has joined #ocaml
postalchris has joined #ocaml
shawn has quit [Read error: 110 (Connection timed out)]
Submarine has joined #ocaml
david_koontz has quit ["This computer has gone to sleep"]
er_ocaml has joined #ocaml
<er_ocaml> if i call the following: "Unix.unlink "foo";mkfifo "foo" 0o666
<er_ocaml> are the two guaranteed to execute in order?
<er_ocaml> i'm seeing a weird bug that would get explained by the above
malc_ has joined #ocaml
<jlouis> er_ocaml, yes. The unlink before the mkfifo
bluestorm_ has quit ["Konversation terminated!"]
joshcryer has quit [Read error: 104 (Connection reset by peer)]
slipstream has joined #ocaml
joshcryer has joined #ocaml
slipstream-- has quit [Read error: 60 (Operation timed out)]
OatTop has joined #ocaml
OatTop has left #ocaml []
er_ocaml has quit []
G has joined #ocaml
er_ocaml has joined #ocaml
joshcryer has quit [Read error: 104 (Connection reset by peer)]
tspier2 has joined #ocaml
<tspier2> Is there a way to add a snippit of code to create a space between two letters or so? You add a new line with \n, but is there anything similar just for a space?
<pango> space char itself ?
<tspier2> Will that work?
<tspier2> I thought whitespace was ignored.
<pango> why not ?
<tspier2> ^ Up there
<pango> and I thought \n was n... it all depends on context
<pango> spaces are significant in strings
<tspier2> Hm
<tspier2> Good point.
<pango> (ah, not even; \n is not allowed outside strings # let \n = 3 ;; => Illegal character (\\) )
<tspier2> pango, I needed to know that for a little script I am writing that will help me generate morphological information for a language pair without having to write out all the code myself for each morphological component.
<tspier2> Yes, I really am *that* lazy.
<tspier2> Why do something one hundred times when you only need to do it once? :P
G_ has quit [Connection timed out]
kig has quit [Read error: 110 (Connection timed out)]
TaXules has quit [Read error: 104 (Connection reset by peer)]
er_ocaml has quit []
er_ocaml has joined #ocaml
er_ocaml has quit [Client Quit]
joshcryer has joined #ocaml
<tspier2> pango, do you know why this isn't working? http://pastebin.be/813
<tspier2> I can get OCaml to print out the code nicely in XML, but I need to setup user input now, so that there is actually something *to* output. ;P
<malc_> syntax issues notwithstanding a is an int yet is printed as a string
<tspier2> Hm?
<pango> malc_: or it's a string, compared to an int...
<malc_> #
<malc_> let infinitiveVerb = int_of_string (read_line ()) in
<malc_> # a = infinitiveVerb
<malc_> infinitiveVerb is an int, by extension a is an int too
<malc_> therefore print_string a; is nonsense
<pango> tspier2: but a is bound to "" (or tried to...) above
<pango> s/tspier2/malc_/
<pango> tspier2: there's several bugs here
<tspier2> I really just need to figure out how to get the user's input, and then print it out on the screen.
<malc_> i don't know what to make out of the syntax of the example, nevertheless latter a = shadows the former
<tspier2> If I can figure out how to do that, then I'll be in good shape, because I have the rest of it ready.
<pango> tspier2: first, let identifier = expr is only valid at top level, for global declarations
<pango> tspier2: inside functions, you can only use let bindings, and the syntax is let identifier = expr1 in expr2 (notice the 'in')
<tspier2> Hm
<pango> a = infinitiveVerb is a boolean expression; what's more, a is a string, infinitiveVerb an int, so you can't compare them (or, alternatively, a must be an int too)
<pango> I guess you meant an assignment, but that's not possible because a is not a variable
<tspier2> Hm
<pango> if you really want the equivalent of variables, have a look at references; But that may not be required here
Mr_Awesome has joined #ocaml
smimou has quit ["bli"]
<mrvn> And have a look at the examples for parsing input.
<mrvn> If you want XML as input you should write a robust parser for it.
Types_and_Kinds has joined #ocaml
Types_and_Kinds is now known as Sparkles
er_ocaml has joined #ocaml
Sparkles has quit []
er_ocaml has quit []
G_ has joined #ocaml
malc_ has quit [Read error: 110 (Connection timed out)]