<love-pingoo>
jeremy_c: you must be reading it wrong
<love-pingoo>
- : ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a = <fun>
<love-pingoo>
'b array -> 'a, that is to say 'a array -> 'b..
<jeremy_c>
love-pingoo: hm. ok. I am still learning these signatures.
<love-pingoo>
Array.fold_left (fun i f -> i+.(float f)) 0. [|1;2;3|] should be 6.
<love-pingoo>
- : float = 6.
<LUCAS>
love-pingoo: thanks :) I think the new version will be available soon in repositories ;)
<love-pingoo>
those debian folks are reactive
gmh33 has left #ocaml []
<LUCAS>
love-pingoo: yep, by night!
<LUCAS>
good night all!
<love-pingoo>
it's 11am here ;)
<LUCAS>
it's 3 am in italy!
<LUCAS>
(he lives now in italy, I suppose)
<LUCAS>
have a nice day :-)
* LUCAS
go sleep
* LUCAS
goes
* LUCAS
etc.
b00t has joined #ocaml
chessguy has joined #ocaml
pingu has joined #ocaml
<Fly_101>
pango: is there an exception for a successful connection ?
<love-pingoo>
Fly_101: no, it just returns happily
joshcryer has joined #ocaml
<Fly_101>
love-pingoo: does a successful connection return anything ?
<love-pingoo>
Unix.connect doesn't return anything on success
<Fly_101>
ahhh
<love-pingoo>
when the C connect() returns 0, Unix.connect returns (). when the C returns an error code, the caml function turns it into an exception and raises it.
<Fly_101>
thanks for clearing that up :P
<Fly_101>
love-pingoo: for recieving messages the recv # ........that number is how many bytes are being sent Or the max bytes allowed to be sent
pango_ has joined #ocaml
<Fly_101>
pango_: you up ?
pango has quit [Remote closed the connection]
jcreigh has joined #ocaml
<TSC>
jeremy_c: isn't your "'a user" type just "'a option" ?
<TSC>
(From your paste of a few hours ago)
<jeremy_c>
TSC: I don't know. I'm still new :-/
<TSC>
I think it is
<jeremy_c>
TSC: I'm not sure how it would work out
<TSC>
You'd leave out that first type definition
<TSC>
And have (in the record) "original: user_rec option"
<jeremy_c>
TSC: well, all-be... that worked exactly the same.
<jeremy_c>
I forgot all about option. Its been a while since I have delt with ocaml and when I did, I only got thru the basics.
<love-pingoo>
Fly_101: read the doc for Unix.read, that's the same type and meaning (man Unix or see the ref)
<Fly_101>
love-pingoo: yea that number besides recv is the max bytes
<Fly_101>
im having a desgin flaw i think
<Fly_101>
:\
<love-pingoo>
for the Unix module, reading the doc of the equivalent C functions is actually the best thing to do
<love-pingoo>
for the design ... good luck :)
<Fly_101>
ok well how often should i call the select to check for new messages ?
<love-pingoo>
what are you building ?
<Fly_101>
Im client
<Fly_101>
and using Select to check for new messages on the file descriptor
<love-pingoo>
one way to do is to build everything around select
<love-pingoo>
you select, get something, do something, reselect, and so on
<Fly_101>
i think i know how to od it
<Fly_101>
the select is only used for checkiing file descriptors
<love-pingoo>
for a client, you may as well go for blocking receptions and so on
<Fly_101>
and since i am using GTK ........the tookit has a function where you can have a main loop - the GUI and a 2nd ary loops the Select so if its nt running any gui events it would be running the select
<love-pingoo>
yeah, and no threads to worry about, sounds good
<Fly_101>
that was my main concern .......i dont want multiple threads or anything to over done for a simple im
<Fly_101>
do you know how often irc checks for new messages ?
<Fly_101>
ever 1 ms or 5 ms ?
<love-pingoo>
I wonder how many people build IM for practicing.. has it grown more popular than games/editors/languages ?
<Fly_101>
its turning out to be a good learning experince
<Fly_101>
but im actually going to use this
<Smerdyakov>
Whenever I see someone talk about writing down an IM program, I write down his name, so I can explode his head later on.
<love-pingoo>
Fly_101: I'd say the real question is how long can you wait for the event before the user notices the UI freeze
<Fly_101>
love-pingoo: im just curious what irc protocol uses
<Fly_101>
i would think it would be single threaded
<love-pingoo>
I don't see why it should be specified, and why you need to know.
<Fly_101>
so it owuld use a poll so a select of some nature
<Fly_101>
human curiocity
<love-pingoo>
k
<love-pingoo>
I think gtk will call your select block often enough.. otherwise, threading it later should be ok
<love-pingoo>
Smerdyakov: what are valid projects for you, except proof checkers/assistants ?
<Fly_101>
love-pingoo: i would think most irc and im clients use select
<Smerdyakov>
A valid project serves some useful purpose not already served by existing projects.
<Smerdyakov>
(A necessary but not sufficient condition)
<love-pingoo>
Fly_101: sure, but the timeout they give to select doesn't say how often they check for events
<Fly_101>
love-pingoo: like i said for GTK theres a function where it will always handle GUI events first then it will handle whatever function you specify if there are no gui events going on
<love-pingoo>
so let GTK handle gui events (shouldn't take long) and then let him call your select, which will block for a little while waiting for events, but not too long so GTK can manage his stuff again
<Fly_101>
love-pingoo: your making it seem like a long time lol ........we are talking Miliseconds nothing even noticeable to the human eye
<love-pingoo>
Fly_101: anyway, I think you can also directly give your filedescr to gtk together with an handler to call in case of an event
<Fly_101>
my irc client is prolly polling for messages every 1-5 seconds times how many channles i have open
<Fly_101>
miliseconds
jcreigh has quit ["Cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet."]
<love-pingoo>
Fly_101: where would this 1-5msec come from ? the time gtk spends in handling gui, select()'s timeout ?
bohanlon has quit [Read error: 104 (Connection reset by peer)]
<Fly_101>
gtk would call the select every 1-5 ms
<love-pingoo>
I thought it would call your function whenever it's idle
<Fly_101>
ok ok
<Fly_101>
the way the gtk function works
<Fly_101>
is whenever there no GUI event to handle it will call a function you specify ever "n" seconds
<love-pingoo>
oh, you mean that it won't call it twice with less than n msecs delay between ?
<Fly_101>
love-pingoo: could you rephrase?
<love-pingoo>
I don't think you need this restriction, and there is probably a way to get rid of it
<Fly_101>
love-pingoo: i dont think we understand each other :P
<love-pingoo>
Fly_101: you mean that as long as there are no events, gtk would keep calling your function, but never with less than N ms between two calls ?
<Fly_101>
ok this gtk function will call Select as in my case ever n second i specify
<Fly_101>
you can do that
<Fly_101>
or set it so there is no delay between calls
<love-pingoo>
I'd go for no delay
<Fly_101>
yea ......can do easily
<Fly_101>
but i dont think 1 ms is really a delay ;)
<love-pingoo>
it doesn't matter if you give a non-zero timeout to select
<love-pingoo>
Fly_101: best is better than better, 0ms better than 1ms lag ;)
<love-pingoo>
although it probably won't make any noticeable difference, I agree
<Fly_101>
i was thinkign of poeple with like a 300 mhz computer :P
* love-pingoo
should work, gets distracted to happily ;)
<Fly_101>
im editing my gtk also .........tkaing out what i am not using
<Fly_101>
i am going to statically include it with my windows release
<Fly_101>
i tink i can get my gtk down to 1-1.5 MB
Smerdyakov has quit ["Leaving"]
shawn__ has quit ["This computer has gone to sleep"]
<Fly_101>
ok so if this thing checks the file descriptor every 1 ms .....or w/e how od i check to see if there is any information with an IF ?
chessguy has joined #ocaml
verendus has left #ocaml []
<Fly_101>
also doesnt ocaml opt build itself against the Libc library ?
<love-pingoo>
man Unix, man select ;)
jewel has joined #ocaml
<Fly_101>
love-pingoo: im saying i assume the select will check the file descriptor and return either if information is there or info is *not* there
<Fly_101>
but then i would need to have something to do a pattern match or an if statement to see id what the select returns is that it contains info
<love-pingoo>
it returns lists, in which it puts the fd which have received new events
<love-pingoo>
as the (man Unix) shows
<Fly_101>
<< man's unix
<Fly_101>
grrrrrr i dont have a manual entry for select here
b00t has quit [Remote closed the connection]
<Fly_101>
ok i was right i would use a IF
<Fly_101>
love-pingoo: is there any difference between poll or select ?
<love-pingoo>
never used poll
<love-pingoo>
and I don't see it in OCaml's Unix doc
<Fly_101>
could you link me to that ?
<Fly_101>
i cant find it
_velco has joined #ocaml
<Fly_101>
nevermind im stupid
Carillon has joined #ocaml
<jeremy_c>
In a module, I define a type of a record. Can I not access that record outside the module?
<Fly_101>
val select : file_descr list ->
<Fly_101>
file_descr list ->
<Fly_101>
file_descr list ->
<Fly_101>
float -> file_descr list * file_descr list * file_descr list
<Fly_101>
i see that ..........i guess thats what i should use
Carillon_ has quit [Read error: 60 (Operation timed out)]
Carillon is now known as Carillon_
<love-pingoo>
jeremy_c: yeah, but unless you open the first module the names of the field should be prefixed by it: record.Module.field
<jeremy_c>
love-pingoo: hm. I wonder if I shouldn't have just used classes.
<love-pingoo>
I often wondered about that too, or the other way around.. ;)
<jeremy_c>
bear in mind I'm a newbie, but that's just some generic stuff I've been working on. By trade, I do database apps.
shawn__ has joined #ocaml
shawn has joined #ocaml
<Fly_101>
love-pingoo: how do i declare my File Descriptor ?
<Fly_101>
let sock_send sock str =
<Fly_101>
let len = String.length str in
<Fly_101>
send sock str 0 len []
<Fly_101>
is that my file descriptor?
<Fly_101>
no wait Unix.file_descr is the file descriptor
<Fly_101>
but how do i hook it to my socket so it knows to look there
<love-pingoo>
a socket _is_ a file descriptor
<love-pingoo>
I said I had work to do, please find a doc and read it more carefully before asking here.. I might give up otherwise.
<Fly_101>
<< goes and reads about select more in depth ly
chessguy2 has joined #ocaml
chessguy has quit [Nick collision from services.]
chessguy2 is now known as chessguy
<Fly_101>
im just a little confused on which is the file descriptor the sock_send or let client_sock = socket PF_INET SOCK_STREAM 0 in hmmmm
<Fly_101>
stupid question of course the client sock would be the file descriptor
smimou has joined #ocaml
chessguy has quit [" HydraIRC -> http://www.hydrairc.com <- 100,000+ downloads can't be wrong"]
<Fly_101>
so the ;; is basically there to end a block of functions ?
<Fly_101>
or "a" function so it doesnt carry on
<love-pingoo>
it's not needed outside the toplevel, if you start all your expressions with a let .. = ..
<pango_>
jeremy_c: #load is a toplevel interpreter directive, when compiling one usually just links against the libs used
<pango_>
jeremy_c: you should use meaningful identifiers (what's "a", "b" ? and the "change" function used create a record from scratch, that's misleading)
<jeremy_c>
those are functions responding to a List.fold_left ... not sure what a meaningful name would be. first second ?
<jeremy_c>
about the load. I am dealing just with top level at this point. I'm just mocking this stuff up to learn/refresh my knowledge (or lack of) of ocaml
<jeremy_c>
pango_: any more comments on the code would be great, that's how I learn best.
<pango_>
do you need to create that field_name_value_pair if it will only be used in fold_left ?
<pango_>
an anonymous function may be enough
<jeremy_c>
pango_: the paste just now, is a version I wrote using classes instead of functions/record types.
<pango_>
never used ocaml OO
<Fly_101>
love-pingoo: yea but fully understaning that takes away alot of confusion
<pango_>
beware of !=, it's physical inequality, I'm not sure that's what you meant
<jeremy_c>
pango_: yeah, I think that was sloppy. In my rewrite using classes, I didn't make an anonymous function, but I made a supporting function inside the main "for_update" function to do the same thing.
<jeremy_c>
pango_: prob pretty easy for you to see I don't come from a functional background, eh?
<pango_>
you can write String.get last_name 0 as last_name.[0]
<pango_>
(saves typing, it's the same thing)
<jeremy_c>
pango_: cool. that's good to know.
<pango_>
in fold_left high order functions, I personally always name the accumulator 'acc'
<jeremy_c>
pango_: good call.
<pango_>
it's like using 'i' for loops, it's not enforced by the language, but it's conventional, and help rereading code
<pango_>
in do_pair, you have code duplication between the two if branches
<jeremy_c>
pango_: thanks, fixed.
<pango_>
when constructing strings using a lot of concatenations, it can be useful (and faster) to use the Buffer module; but you can check that later
<Fly_101>
http://phpfi.com/152154 << when i run this it still runs the function .......I am not even calling it
<jeremy_c>
pango_: other than what you suggested, what do you think of the code? It is obviously missing database access and finder methods, but you get the idea.
<love-pingoo>
Fly_101: let something = .. doesn't define a function, a function has an argument, at least unit: let something () = ...
<jeremy_c>
pango_: on quite a few of my tables, I have to do auditing in regards to who changed what and when. Down to the field level. Better idea?
<jeremy_c>
pango_: you are right though, fn = field name, ov = old value, nv = new value.
<Fly_101>
love-pingoo: stupid mistake
<Fly_101>
its this small crap that keeps golding me back
<pango_>
jeremy_c: well, keeping a separate log of changes, as you do, looks enough for that; no need to remember previous value in each record
<jeremy_c>
pango_: that's how I tell what has changed when I go to user#save
<Fly_101>
love-pingoo: will using () and having it return as a unit hurt me in any way ?
<love-pingoo>
no
<Fly_101>
ok just checking
<love-pingoo>
it's what you put when there are only side effects, that's normal
<jeremy_c>
pango_: when you update an attribute, the change is recorded. Upon save, a log will be created from that changes class then the values in the changes array will be reset to nothing, no changes.
_fab has joined #ocaml
<jeremy_c>
pango_: that functionality is not yet represented in the code though.
<jeremy_c>
pango_: the logging of attribute changes is, not the change log recording/reseting on save
<pango_>
I see the point, but I also avoid database code ;)
<jeremy_c>
pango_: database work is about all I do.
<pango_>
you'd use databases when data can't fit in memory, or when concurrent accesses are needed
<pango_>
in both cases keeping data in memory with such code is not possible or interesting
<jeremy_c>
pango_: like 3 million claim records with over 75 million service lines?
<love-pingoo>
even with smaller data, it's useful to have a persistent structured storage
<pango_>
anyway I think it should be up to the database to take care of caching, it feels wierd to have to write all this code just to duplicate its job
<jeremy_c>
pango_: the db backend is postgresql. I have played with pg access in ocaml, but have not put it into my example/learning code yet. Just trying to get the interface down.
<jeremy_c>
pango_: what do you mean caching?
<pango_>
managing disk <-> memory exchanges to keep data being worked on at hand
<pango_>
skip over unnecessary updates, etc.
<pango_>
you're just trying to do the job of the database in your own code... well, probably adding bugs in your application along the way...
<jeremy_c>
pango_: hm. I'm not sure I follow.
<jeremy_c>
pango_: let u = user_find_by_id 10 ; puts u#full_name ; u#set_code "john" ; u#save ;;
<pango_>
sure, but no need to keep records data in the application if it can be retrieved from database backend
<jeremy_c>
how would you code that and make it actually usable if your dealing only by SQL queries, results, tuples?
<jeremy_c>
pango_: what do you mean records data?
<pango_>
mmmh no you're right it's not saved
<pango_>
it's just that I'm terrified by the amount of code needed for something that simple
<jeremy_c>
hm, I thought it was a small amount of code for such a nice abstraction, change log recording, etc...
<jeremy_c>
I'd love to know how to accomplish the same task w/less code.
smimou has quit ["bli"]
<jeremy_c>
I like the flow of the OO version much better.
<jeremy_c>
that's my newest, w/changes you suggested. Also, note. That the entire base_user class will be generated based on db schema, not coded by hand. That will go for all my models.
<jeremy_c>
Then I can inherit from base_user in my user class and provide additional, non-standard functionality, such as full_name, blinded_name, work_queue, etc...
<Fly_101>
http://phpfi.com/152167 << someone wanna give me a little helping hand with this select i think im kinda off :(
<pango_>
jeremy_c: if anything, change != with <> in add_maybe
<pango_>
!= is physically equality
<pango_>
# "hello" != "hello" ;;
<pango_>
- : bool = true
<jeremy_c>
ah, forgot about that.
<pango_>
s/equality/inequality/
* jeremy_c
going to sleep, 3:18am here.
<jeremy_c>
pango_: thanks for your input this morning. I do appriciate it.
<pango_>
np
<Fly_101>
pango_: what is up with thi select......i have seriously spent like 2 hours on it .......its very simple i understand but love-pingoo said your file descriptor is your socket ........so it would be client_sock in my case ......but i dont understand what i am suppose to expect or what its going to return
<Fly_101>
i have looed over 10 examples most of them are very advanced C examples and focus more on using select ofr like accpeting incoming connection ......which is not what i am doing here
<pango_>
for now, I must get ready for work ;)
<Fly_101>
no problem :)
jeremy_c has quit [Client Quit]
velco has joined #ocaml
jewel has quit [Read error: 110 (Connection timed out)]
<Fly_101>
only if :(
pango_ has quit ["brb"]
pango has joined #ocaml
Wild_Cat has joined #ocaml
bebui has joined #ocaml
<pango>
Fly_101: well, Unix.select description seems clear... it takes 3 lists of file_descr, a timeout, and returns 3 other lists of file_descr
<pango>
if you're just going to monitor one socket for incoming data, you won't need to care about write and exceptional lists, and the read list will just have a single element...
<Fly_101>
pango: i am also going to be writing to sockets as well ........do i need to check to write as well or no ?
<Fly_101>
like if theres messages coming in and getitng sent at the same time on the same socket will that mess anything up ?
<pango>
select tells you if reads or writes would block
<pango>
for writes, I think that means whether outgoing socket buffer is full
<Fly_101>
what happens if i tried to write and it was being read at the same time ?
<Fly_101>
i dont think it would be full .........that would be the only thing being sent .....ims
<pango>
tcp sockets are bidirectional, it just works
<Fly_101>
so its like 2 path ways in one socket
<pango>
that's why I think it's not necessary
<Fly_101>
stuff coming in and stuff being written at the same time wont hurt it ?
<pango>
what if it did ? :)
<Fly_101>
lol
<Fly_101>
you cant do me that way :( lol this is my first tcp / ocaml projhect .......its a hard road this first project
<Fly_101>
once i get this recieivng / polling messages down then all i got to do is GUI and hook it all up
<pango>
btw, I won't help you with GUI part, I'm neither an OO, nor a GUI guy
<pango>
(well, actually I already wrote OO code a long time ago, but not in ocaml)
love-pingoo has quit ["taio"]
<Fly_101>
pango: doing GUI in Glade
<Fly_101>
so its just a matter of calling the widget
<Fly_101>
i have looked through quite a bit of docs
jewel has joined #ocaml
<Fly_101>
pango: also with gui stuff its nothing really new ........what i am doing now is having to learn new stuff ......
<Fly_101>
pango: i still dont exactly know what my file descriptor is :)
<pango>
ocaml's OO is... peculiar ;)
<pango>
in Unix "everything is a file" : files, directories, devices, network sockets...
<pango>
and to use a file, you use "descriptors" : when you open a "file", you get a descriptor back, that is used for further operations (reading, writing, seeking, closing, you name it)
<Fly_101>
interesting
<pango>
think of it as an opaque ticket (on Unix it's just an int)
<Fly_101>
i seee
<Fly_101>
so
<Fly_101>
client_sock = socket PF_INET SOCK_STREAM 0 in
<pango>
so yes, type of return is a Unix.file_descr
<Fly_101>
so i just use select with that then right
<Fly_101>
pango: like select client_sock [then arguments here or something ]
<pango>
Unix.select takes Unix.file_descr lists
<Fly_101>
could you expalin just a little more ......this is not really a very well documtned function ........well atleast for me
<pango>
explanation on what ocaml's lists
<pango>
?
<Fly_101>
the select :P
<Fly_101>
i mean
<pango>
again ?
<Fly_101>
i understand what select is and does but i just cant get the code for it wrriten out .....i just ned it to check the file descript which in this case is client_sock
<pango>
I think the description in Unix module is short and clear...
<Fly_101>
it is
<pango>
at least much shorter and clearer than select() manpage (even if probably less accurate)
<Fly_101>
vut reading val sock_send : Unix.file_descr -> string -> int = <fun> << that kind of stuff confuses me sometimes
<Fly_101>
not that one but the one for Unix.Select
<pango>
as usual, interpreter displays the type, then the value of what has been evaluated
<pango>
in that case, Unix.file_descr -> string -> int is the type, and <fun> is the value
<Fly_101>
whats the <fun>
<Fly_101>
ahhhh
<Fly_101>
i mean yea that makes snese
<pango>
function values are abstract in ocaml, so you can't display it
<Fly_101>
but the one for Select is a little more complicated
<pango>
functions of type Unix.file_descr -> string -> int take an Unix.file_descr and a string, and return an int
<pango>
actually the notation is ambiguous on purpose
<Fly_101>
yes i understand
<Fly_101>
val select : file_descr list ->
<Fly_101>
file_descr list ->
<Fly_101>
file_descr list ->
<Fly_101>
float -> file_descr list * file_descr list * file_descr list
<pango>
if you don't give a function all its arguments, it gives you another, "partially applied" function
<Fly_101>
^^ that one confuses me
<pango>
that you can use later by giving it the other missing arguments
<Fly_101>
i would just like to see a example of this Select in action .....i have never saw what i am to expect
<pango>
for example, since you'll be mainly writing to the same socket most of the time, you could write send_server_socket = socket_send client_sock
<Fly_101>
i understand how to write
<pango>
since you only gave sock_send the file_descr, that will give you a function that takes a string and return an int
<Fly_101>
i understand
<pango>
that's the point of the Unix.file_descr -> string -> int notation, it can also be read as Unix.file_descr -> (string -> int)
<Fly_101>
but can you show me an example of Select in action .......with the file descriptor being my socket (client_sock)
<pango>
that is, a function that takes a descriptor, and returns a function that takes a string and returns an int
<pango>
you'll probably use something like Unix.select [client_sock] [] [] 0.05
<Fly_101>
[] [] 0.05 ?
<Fly_101>
is .05 the timeout ?
<pango>
yes, in seconds
<Fly_101>
all its going to do is check it once right ?
<pango>
don't know if the timeout is ok, or even necessary
<Fly_101>
why would you want a timeout
<Fly_101>
i want it to check for any thing there and tell me thats it :P
<pango>
Fly_101: well, if the "gtk idle callback" is called as long as the GUI is idle, using no timeout will mean your application will be all the time busy (=> 100% cpu usage)
<Fly_101>
i cant see any reason for a timeout really
<Fly_101>
well the timeout will be set with GTK not the select
<pango>
you know better than I there, I haven't looked at the API
<flux__>
you can use negative timeout to disable timeouting
<pango>
yes, but then the GUI will get stuck until a network event arrives
<flux__>
(why they didn't use float option is beyond me)
<flux__>
well, you want to select on gui and network connections too
<Fly_101>
i am saying GTK has its main loop ........those events are 1st then you can set a 2nd function to call if there are no gui events happeneing and you can set a timeout there
<pango>
negative timeout is also the convention of poll()
<pango>
so they borrowed from both APIs ;)
<Fly_101>
there should be no timeout with Select for this
<flux__>
but yes, gtk provides its own select-loop, there's no need to write one's own
<flux__>
you can register descriptors to it
<Fly_101>
wait wait
<Fly_101>
so i dont use the Unix.Select ?
<pango>
flux__: but I agree it's not very clean (not to mention the use of floats in the first place ;) )
<Fly_101>
im not trying to loop the Unix.Select at the moment -- all i want ot do is call the function Unix.Select and have it return and tell me if there is any information waiting for me
<flux__>
pango, well, floats are somewhat convenient in this case, imo
<pango>
it's Unix.select, not Unix.Select, capitals are reserved for constructors and module names ;)
<Fly_101>
heheheh
<flux__>
I use floats for time almost always, unless precision is a requirement
<Fly_101>
i just need to see an example on how to use this Select .........C examples are usually very complex and dont display it to well
<pango>
feels weird, even if I suppose it has the benefit of portability...
<Fly_101>
let result = select client_sock [] [] << this doesnt exactly work
<Fly_101>
wait is Select a Loop ?
<Fly_101>
will it just sit there and wait for something to be read ?
<pango>
what's wrong with select description in Unix module ?
<Fly_101>
i domt know it must be me
<Fly_101>
because i get the concept of it i just cant make it happen ........it a very simple perice of code like 2 lines
<Fly_101>
Wait until some input/output operations become possible on some channels
<Fly_101>
so this means it just sits there and waits
<flux__>
fly_101, you missed the last argument anyway
<Fly_101>
well wait ........does select just sit there and wait until something comes avaliabkle to be read ?
<Fly_101>
or does it just check and return yes or no ?
<pango>
depends on timeout argument, both are possible
<pango>
if your application is purely socket-driven, you make it wait forever on select
<pango>
if it has other background activities, you bound the wait (possibly to 0, returning immediately no matter what)
<Fly_101>
thats what i need it to do
<Fly_101>
i need it to return right away
<Fly_101>
and let me know if there is info or not and if there is call a recv
<Fly_101>
then display the info
<pango>
then timeout = 0
<pango>
0. exactly, since it's a float
<Fly_101>
so if i put a number there it owuld wait that length pf seconds for info then return right ?
<Fly_101>
im just wondering
<Fly_101>
of*
<pango>
it will return as soon as a socket is ready, or the timeout expires, whichever come first
<Fly_101>
ok well i need 0 casue i want my gui to stay active
<Fly_101>
and what form will the result be ?
<Fly_101>
i mean how can i display the result either yes or no if data was there or not
<pango>
select return the file_descr list * file_descr list * file_descr list of descriptors that are ready
<Fly_101>
i think there syntax highlighting is off
<pango>
you're missing a double quote, what about trying to compile your code ?
<Fly_101>
the select is messed up right ??
<Fly_101>
pango: ^^
<pango>
at least 3 errors
<Fly_101>
could you fix my select thats all i want
<pango>
two of arguments types... the last one is that client_sock is not defined at that place
<Fly_101>
every way i try i cant get it
<Fly_101>
client_sock is my socket - the file descriptor
<pango>
yes, but it's defined locally in the function above; in this function it doesn't exist
<pango>
ocaml uses lexical scoping
<Fly_101>
oooooo
<Fly_101>
so its not used outside or cant be used outside of that function ?
<pango>
unless you return it in some way, it's not visible outside the function it's defined in
<Fly_101>
well could you show me there how i am suppose to do the Select
<pango>
(and will sooner or later be reclaimed by the garbage collector, since it can't be used anymore
<Fly_101>
is there any way i can define it so i cna use it wherever ?
<pango>
ok, let ready_for_read, _, _ = Unix.select [client_sock] [] [] 0. in ...
<Fly_101>
how can i define my client_sock so i can use it from whatever function
<Fly_101>
just by using let right ?
<pango>
you could use a global definition... probably using a reference on an option type, since it won't have any meaningful value until it's opened... a bit ugly, but well...
<Fly_101>
i just did let client_sock = socket PF_INET SOCK_STREAM 0 in
<Fly_101>
well let client_sock = socket PF_INET SOCK_STREAM 0
<pango>
mmh thinking of it, that should work
<pango>
since socket creation and connection are separate things, you're right
<pango>
ready_for_read will be a Unix.file_descr list
<pango>
not a string
<pango>
and even if Printf's formats aren't really strings, they require double quotes
<pango>
I think you should really try compiling your code... compiler will point out 95% of your problems
<Fly_101>
yea i am everytime ;)
<Fly_101>
i am using Camelia
<Fly_101>
i think is a real nice IDE
<Fly_101>
saves alot of time
jewel has quit [Read error: 104 (Connection reset by peer)]
<pango>
then it should tell you what's wrong, like all those type inconsistencies
<Fly_101>
pango: well how can i print out a list ......i have looked in a few places i see how to create and modify but how do i print them out ? also why is this returing in a list ?
<pango>
it's returning the list of the descriptors that are ready for read
<Fly_101>
isnt it just letting me know if it has data to be able to be read
<pango>
it won't change of type just because you're using it with a single descriptor...
<Fly_101>
so in my case client_sock right ?
<Fly_101>
i seeee
<Fly_101>
so if data is there it will just return [client_sock] ?
<pango>
either a list containing it, or an empty list if it's not ready
<Fly_101>
ahhh i seee
<Fly_101>
how can i print it out to check ?
<Fly_101>
what do you use to print out list
<pango>
file_descr is an abstract type, so it cannot be printed
<Fly_101>
wtf
<pango>
you could display list length, or just whether it's empty or not
<Fly_101>
if it contained more htne one file descriptos which it will not in my case how would someone to a pattern match ?
<pango>
theorically, lists are a recursive variant type with two constructors, [] and ::
<pango>
(I say theorically, because in ocaml those are builtin)
<Fly_101>
ok so what method can i use to check to see if any data is there
<Fly_101>
an IF ?
<pango>
so when doing pattern matching on lists, you have two cases, either [], or a non-empty list that matches with head :: tail
Snark has joined #ocaml
<pango>
if ready_for_read = [] then ...
<Fly_101>
but lets say i had 5 sockets which gave me 5 file descriptos and 3 of them had info on them .......if it cant print it out how could you see what ones have info and what ones do not ?
<pango>
select would return a list with those 3 descriptors
<Fly_101>
but how could you see them ?
<Fly_101>
i thought you cant print out list ?
<pango>
what would you want to "see" exactly ?
<Fly_101>
which file descriptos it sent back lol
<pango>
they're "descriptors", something abstract you can't just "see"; you can use them, though (read, write, etc.)
<pango>
much like the function type; you can't display the definition of a function, yet you can call it
<Fly_101>
i seee
<Fly_101>
so you would have to do a pattern mattch and compare all your decriptors you have vs the ones it sent back ??
<Fly_101>
pango: ^^
<pango>
why compare both, to determine which ones are not ready ?
<Fly_101>
pango: also if it returns [] does that mean there is info or is not info ?
jewel has joined #ocaml
<pango>
select returns the list of the descriptors you can safely use without blocking
<pango>
no more, no less
<Fly_101>
i understnad :P
<Fly_101>
but if it returns [] does that mean there is info or does that mean there is no info ??
<pango>
for reads, not blocking means some data available, or end of stream
<Fly_101>
let check_im () =
<Fly_101>
let ready_for_read, _, _ = Unix.select [client_sock] [] [] 0. in
<Fly_101>
if ready_for_read = [] then prerr_endline "no info"
<Fly_101>
else prerr_endline "there is info"
<Fly_101>
;;
<pango>
and if the "list of data that can safely be used without blocking" is empty, that means that no stream has either data, or has reached its end
<Fly_101>
when i do that it says there is info
<pango>
Since you'll have at most a single element, you can use List.hd to get it out of the list
<Fly_101>
so i can pull things out of the list then ?
<pango>
it looks more like Lisp code than ocaml code, where one usually prefer using pattern matching, but it should work
<Fly_101>
it does work ........witrhout error
<Fly_101>
but its saying there is info
<pango>
pattern matching does datatypes deconstruction; in fact for some datatypes there's no other solution
<Fly_101>
i think i have them switched up becasue its saying there is info
<pango>
no, no, that looks fine
<pango>
maybe server sends some sort of "banner" or "greeting" when you connect ?
<Fly_101>
no the server is not turned on ;)
<Fly_101>
it throws the exception ECONNREFUSED
<pango>
that's why it necessary to understand the precise description of select
<Fly_101>
huh?
<pango>
it tells you what descriptors won't block if used
<pango>
telling you that the descriptor is not working doesn't block, so select returns it
<Fly_101>
pango: im not following
<Fly_101>
i thought select sends back the descrpts of the ones that have info waiting
<pango>
that's why I said the description of select in Unix module is shorter, even if probably less accurate
<pango>
the manpage more accurately describes the behavior of select()
<Fly_101>
so what does select really send back .....descriptos with info or descriptos without info ?
<pango>
descriptors that won't block when used; that includes descriptors that have info available for read
<Fly_101>
well this thing is saying i have data avaliable to be read but im not even connected
<pango>
no, it tells you that using read or recv on that descriptor will immediately return
<Fly_101>
this is not making sense :D my thing is not connected ........but its saying there is info ..........my connection gets refused
<Fly_101>
pango: ^^
<pango>
in some places, like in Unix module description, it's said that select tells you which descriptors are ready for read or for write
<LUCAS>
pango: I was wrong about pcre version :(
<pango>
it's a simplification, so that people understand, but it's approximative
<Fly_101>
how cna it be either when theres no connection lol
<pango>
the exact select behavior, is that it tells you want descriptors can be used without blocking. That includes returning immediately from failure, or just because of end of stream, etc.
<pango>
s/want/what/
<Fly_101>
if i make no connection ......and run the read_for etc etc it will come back and say there is info
<pango>
if you can't understand what I wrote, read it again ;)
<pango>
typing it 4 times was enough
<Fly_101>
lol
<Fly_101>
ok sooooo
<Fly_101>
the descriptor returns IF anything can be read or written right ?
<pango>
reread again
<Fly_101>
lol i get it ........all im saying is all i want to know is when something can be read ........or else it will return postive everytime
<pango>
then you either have to avoid using select on descriptors you know aren't ready, or must handle errors at read time
<Fly_101>
is there any way i can just make it return when things can be read ?
<pango>
no
<Fly_101>
so dude it returns postive everytime :)
<Fly_101>
great
<pango>
not if the socket could be opened, and has no data waiting
<pango>
because trying to read from it in that case would block
<Fly_101>
i have no data waiting but its saying i have data
<pango>
actually it's your prerr_endline that says that, for what select says, reread above
<pango>
select just says "read would block" or "read wouldn't block"
<pango>
or, if you prefer that wording "read would wait" or "read would return immediately"
<Fly_101>
so i have my preee_endline switched up the ?
<Fly_101>
now that solves the mystery i had on why it was saying something could be read
d-bug has joined #ocaml
<Fly_101>
pango: oh man my stuff is starting to like all work now
<Fly_101>
sending reciving ....... the slect works as it should now
<Fly_101>
goooood got to main base all taken care of
Carillon_ has joined #ocaml
<Fly_101>
pango: quick question how cna i make a ocaml app sleep for 10 seconds ?
<pango>
use Unix.sleep, or select with empty lists
<pango>
select has the advantage of better resolution than 1s
m3ga has quit ["disappearing into the sunset"]
<Fly_101>
pango: with sleep ?
<Fly_101>
is the number afterwards a second a milisecond
<Fly_101>
or a nano second ?
<pango>
sleep unit is second
<Fly_101>
what if i need less then a second ?
<Fly_101>
pango: like miliseoncds or something ?
<pango>
they're syscalls with better accuracy, but they're not very portable - that's why select() is often (ab)used for this
<Fly_101>
hmmm i seeeeee
<Fly_101>
well i odnt need it do i ?
<Fly_101>
i know some people have their apps sleep a little bit to aquire better cpu performance ?
<Fly_101>
all i am using is windows and linux
<Fly_101>
pango: ^^
<pango>
depends how gtk idle callback works
<pango>
whether it looks as fast as possible, or adds delays itself
<Fly_101>
im saying for an im client do i need to sleep it ?
<Fly_101>
pango: but i need to have it check for new ims at all times
<Fly_101>
i cant have iit sleep
<Fly_101>
pango: is polling bad ? this guy is saying its bad and a lazy way ........saying its like asking are we there yet are we there yet etc etc
<pango>
it's better when polling can be avoided
<Fly_101>
pango: welll what are my other options lol ???
<pango>
but that means all events must be detected, and waited for in a single place
<Fly_101>
pango: dont most im clients and irc clients use polling to check for new messages
<pango>
so that requires special provisions in GUI framework... Don't know what Gtk provides
<Fly_101>
pango: lol yesterday everyone was telling me to use poll now everyone is saying its bad
<pango>
poll, or poll() ?
<pango>
poll() is a syscall similar to select()
<Fly_101>
ok i mean select
<Fly_101>
is select bad for what i am doing with it ?
<Fly_101>
checking the file descriptor ever n ms for new data ?
<Fly_101>
grrrrrrrrr
<Fly_101>
so now is select() bad for what i am trying to do ?
Wild_Cat has quit ["Leaving"]
Wild_Cat has joined #ocaml
<Fly_101>
pango: now i dont know what to do man
<pango>
unless Gtk provides a better mean to handle network sockets, you can only use select or non-blocking sockets
<Fly_101>
pango: i dont think Gtk does
<flux__>
fly_101, elegant programs should only exit select when they know they have something to do
<flux__>
fly_101, but I suppose, if you're in the learning process, some other approaches may be made ;
<flux__>
;)
<Fly_101>
pango: just these people were making it seem like oh no polling omg
<pango>
then there's no alternative than some kind of polling
<pango>
(or threads)
<Fly_101>
flux__: well i will have select called like ever 5 ms
<Fly_101>
pango: i didnt want threads those would be just as bad
<Fly_101>
or just as good for this simple thing
<pango>
that's your choice, I'm just listing the alternatives
<Fly_101>
flux__: i will have GTK run my select function every 5 ms .........of course GUI events and things of that such come first if any are made
<Fly_101>
pango: i just dont want cpu to be like 100 %
<pango>
to use no cpu until something happens, you application must be able to wait for both GUI events and network events using a single instruction
<pango>
so if it's possible, it must be provided by the GUI API
<pango>
if not => polling
Wild_Cat has quit [Remote closed the connection]
<Fly_101>
pango: how owuld something wait for a network event ??/
<TSC>
select ?
<Fly_101>
thats impossible .......it would need to be running solo on its own thread or to be polled
<pango>
select, poll, epoll, kqueue, fibres,...
<Fly_101>
and which one of those are compatible with Ocaml ?
<Fly_101>
pango: ^^
<pango>
no, the application calls a blocking syscall, so that when a network packet arrives, as the same times the data is written in the incoming buffer of the socket, the application is woken up. No polling required.
<Fly_101>
what does that ?
<Fly_101>
can i do that in Ocaml ?
<pango>
some operation systems kernels
<Fly_101>
what is esque ?
<pango>
in its standard library, ocaml provides a wrapper for the select() syscall. Others are possible, if you write the wrappers yourself (and if the operating system support the syscall, of course)
<Fly_101>
lol
<Fly_101>
man hmmmmmm
<Fly_101>
will a simple poll work for a simple im client ?
<Fly_101>
or will it throw the computer off make it 100 percent cpu and crash it
<pango>
even using 100% cpu should not crash it if it's correctly cooled off
<Fly_101>
ok you know what i mean
<Fly_101>
i dont evne want my app to use 1 percent
<Fly_101>
it will just poll 1 file decr ever 5 ms
<pango>
but leaving some cpu for other apps is considered wise
<pango>
and yes, some amount of polling should ok, specially when you have no other choice
<Fly_101>
so is 1 poll every 5 ms fine ?
<Fly_101>
pango: ^^
<pango>
5ms timeout means the polling code will be roughly used 200 times per second
<pango>
may not be good on IBM PC 4.77MHz, but probably barely noticeable those days
<pango>
onless you run a few hundred of instance of your client on a single box
<Fly_101>
is 5 ms to much ?
<Fly_101>
200 times a second seems like alot
<pango>
I think that only experience will tell
<Fly_101>
lol
<Fly_101>
i am new so any info is good
<Fly_101>
do you know what irc uses ?
<pango>
remember that while your client will wait for 5ms, the interface will stop responding to GUI events
<Fly_101>
pango: whats that suppose to mean
<pango>
so, while it may look overkill for IM messages, you can't use overly large delays either, or the interface will look unresponsive
<Fly_101>
at 5 ms the GUI wont work is that what you mean ?
<Fly_101>
oooo i seeeee
<Fly_101>
so 90 ms would be to long to wait in between ?
<pango>
90ms may be near the max limit
<pango>
I'm not sure what's the acceptable delay for GUIs, but at 1/10s, delays start to be noticeable by humans
<Fly_101>
what would you suggest ?
<pango>
to try
datrus has joined #ocaml
<Fly_101>
im saying what do you think is a good delay ?
<Fly_101>
10 ms ?
Wild_Cat has joined #ocaml
<Fly_101>
higher or lower ?
<pango>
as is my guess would be better than yours... I don't know
<Fly_101>
i seeee
<datrus>
anyone knows if there is an ocaml module that implements fastcgi? i would like to use it from a web server written in ocaml
<pango>
maybe 42ms, if you like Douglas Adams
<Fly_101>
Douglas Adams ?
<Fly_101>
datrus: cant you compile your app and just use it that way ?
Wild_Cat` has joined #ocaml
Wild_Cat` has quit [Client Quit]
Wild_Cat has quit [Remote closed the connection]
Wild_Cat has joined #ocaml
<Fly_101>
datrus: fast cgi is for scripting languages with speed problems ..........ocaml is like 40 times faster then php and 60 times faster then Ruby
<datrus>
Fly_101: the web application is in ruby, the web server in ocaml
<Fly_101>
ooooooo lol
<datrus>
so i need fastcgi for the web server
<Fly_101>
oooooooo
<Fly_101>
why not just make the web application in Ocaml :P
<Fly_101>
pango: who is douglas adams ?
Wild_Cat has quit [Remote closed the connection]
<Fly_101>
datrus: i looked over Mod_Ocaml it looked pretty cool
<datrus>
yes but i don't use apache
<Fly_101>
what do you use ?
<datrus>
the reason is that i want the webserver config to be database driven
<datrus>
i just want to use a custom ocaml web server
<Fly_101>
i dont know what to tell ya :P
<datrus>
using the ocaml http module probably
<Fly_101>
datrus: i like apache so yea ;)
<datrus>
but apparently some things you can't do with apache...
<Fly_101>
datrus: apache yhas proven itself to be fast reliable and stable for many years :P
<Fly_101>
like what ?
<datrus>
for example:
<datrus>
handle hundreds of vhosts
<datrus>
that can be added removed dynamically
<datrus>
and use a chrooted fastcgi process
<datrus>
for each vhost
<datrus>
for security
<Fly_101>
im sure you can do that
<datrus>
apparently i can't do that using apache
<Fly_101>
its open source ;)
<datrus>
there is mod_vhost_dbi
<datrus>
but it doesn't handle the fastcgi stuff
<Fly_101>
datrus: your talking about buidling a web server
<datrus>
mod_vhost_alias neither
<Fly_101>
i would thnk it owuld be easier to make a mod to apache then to build a whole web server
<datrus>
i'm talking about the limitation of apache and why i therefore have to use a custom ocaml srver
<datrus>
ok perhaps you're right
<Fly_101>
do you know ocaml ?
<datrus>
thing is i never wrote an apache module
<datrus>
i know ocaml a little bit
<datrus>
the reason i wanted ocaml was for speed
<Fly_101>
have you wrote anything in it ?
<datrus>
yes bdd stuff
<Fly_101>
bdd>?
<datrus>
stuff involving temporal logic and model checking
<Fly_101>
i seeee
<Fly_101>
wellll
Wild_Cat has joined #ocaml
<datrus>
i also looked at lighttpd
<datrus>
to see if can handle the vhost stuff
<datrus>
but no
<Fly_101>
i know i am re inventing the wheel as well ......im making an im client ........but i looked for a week on sf.net and freshmeat for a jabber client that would work for me .......i tired a few tryd to edit but i came to the conclusion that i had to make one
<Fly_101>
typos *
<Fly_101>
but making a web server that is reliable and good secutiy is something i would think that requires alot of info on it
<Fly_101>
i would make a mod for apache ;)
<Fly_101>
i have heard its very easy to make mods with it
<Fly_101>
almost all scripting langs have their own mod for it
<datrus>
yes you're probably right
<datrus>
anyway this is the wrong channel then
Wild_Cat has left #ocaml []
Wild_Cat has joined #ocaml
jewel has quit [Read error: 110 (Connection timed out)]
jeremy_c has joined #ocaml
jeremy_c has quit [Remote closed the connection]
jeremy_c has joined #ocaml
jeremy_c_ has joined #ocaml
jeremy_c has quit [Read error: 60 (Operation timed out)]
jeremy_c has joined #ocaml
_velco has quit [Read error: 110 (Connection timed out)]
jeremy_c_ has quit [Read error: 110 (Connection timed out)]
Smerdyakov has joined #ocaml
Boojum has joined #ocaml
Snark has quit [Read error: 110 (Connection timed out)]
slipstream has joined #ocaml
slipstream-- has quit [Read error: 110 (Connection timed out)]
<jeremy_c>
Can I send a class type as a parameter?
<jeremy_c>
let dummy cls flds = let c = new cls in cls#fill_from_fields flds
Carillon_ has quit [Connection timed out]
Carillon is now known as Carillon_
<jeremy_c>
class johndoe end ;; ... dummy johndoe ["hello" ; "goodbye";] ;;
SyntaxNinja has joined #ocaml
<SyntaxNinja>
I work for a company who hires functional programmers; I want to post a job description to an ocaml mailing list, but I don't really know which, and if that's even appropriate, can anyone give me advice here?
<LUCAS>
which mailing list?
<LUCAS>
that at caml.inria.fr
<LUCAS>
it's appropriate enough ;)
<SyntaxNinja>
so this address would be appropriate? caml-list@inria.fr
<LUCAS>
caml-list@yquem.inria.fr (maybe they are aliases)
<SyntaxNinja>
OK I guess i have to be subscribed, but we'll see if it just rejects the post or what. I don't really want to subscribe just to post the one email. but it makes sense to configure the mailing list like that.
smimou has joined #ocaml
postalchris has quit [Read error: 110 (Connection timed out)]
<SyntaxNinja>
wow, I got a reply, but the archives don't show it. I guess it was posted. hmm