<zmdkrbou>
this is so heavy ... compared to irc messages
tennin has quit [Read error: 104 (Connection reset by peer)]
<youknow365>
yea :\ its xml though :P
<zmdkrbou>
xml sucks bears
<youknow365>
once i get it ......it should work very good
<youknow365>
i think it can be a good way of organizing
<youknow365>
i mean why would it start splitting up packets if its small ?
<zmdkrbou>
it may do, you can't tell
<zmdkrbou>
so you mustn't rely on this
<youknow365>
so do i have to create a buffer to save all messages in ?
<youknow365>
damn programming languages must be fast ........so much overhead to get one message from point A to point B
<youknow365>
zmdkrbou: but how owuld i know what message it is
<youknow365>
i mean
<pango_>
check the Buffer module, it implements appendable strings, taking care of reallocations
<youknow365>
what if a packet gets sent in between
<youknow365>
and has </steam> also
<youknow365>
it would confuse it or something maybe
<youknow365>
how can i distinguish packets
<pango_>
what you get from tcp is a stream; it guarantees that data is received in the order it was sent
<youknow365>
ooooooo
<youknow365>
so all i would be checking for would be message compelte or not right ?
<pango_>
if sender is writting messages sequentially, they're received sequentially, so yes
<youknow365>
well lets say i recive something from the jabber server using recv and i scan it and its only half a message ?
<youknow365>
theres no </steam>
<pango_>
maybe the network is slow and you will received the rest in 10 minutes, or the server crashed...
<pango_>
lots of things maybe happen
<pango_>
s/maybe/may/
<youknow365>
so what would i do with a incomplete message ?
<pango_>
it's up to you... But I guess that after a while you can assume the connection broke (timeout)
<youknow365>
after how long do you think ?
<pango_>
maybe it's specified in jabber specs ?
<youknow365>
hmmmmm
<pango_>
otherwise you guess is just good as mine... It depends on how fast transmitting a message usually takes, and how fast you want to detect broken connections
<youknow365>
but i couldnt jus sit there and wait for the rest of the message
<youknow365>
it would hang my program
<pango_>
actually, if you're avoiding blocking I/O, your program won't hang
<youknow365>
i seee
<youknow365>
well should i worry baotu that right now or should i jsu worrry about getting sending and recivng to work in parrelly and good at the moment
<pango_>
it will keep answering to GUI events, but networking would look "dead"
<youknow365>
well i would saying waiting any more then 1 second would appear to be a timeout right ?
<pango_>
that looks a bit small
<youknow365>
well it owuld be the jabber server to the client
<youknow365>
if ita taking my jabber serve more then 1 second to contact the client that could be a situation
<pango_>
there's also all the hops between the two, routers, modems, wireless stuff, etc.
<youknow365>
hmm
<youknow365>
well i dunno dude 20 minutes ???
<pango_>
any of those could get a temporary surge of traffic and delay some packets
<youknow365>
shit any isp coudl also have a power outage better make it like 2 hours
<youknow365>
hmm
<pango_>
don't worry, if your application notifies the user that the connection broke 2 hours after it happened, he will probably have gone doing other things ;)
<pango_>
one minute or two sounds about right to me. Maybe just one minute, for something as interactive as IM
<youknow365>
if it takes half a packet
<pango_>
non-interactive can have larger timeouts, computers are patient ;)
<zmdkrbou>
you're crazy youknow365
<youknow365>
to travel 1 minute as small as a message
<youknow365>
zmdkrbou: ?
<zmdkrbou>
for your information, the "ping timeout" in irc protocol is (usually) 90s
<youknow365>
90 ?
<youknow365>
seconds ?
<zmdkrbou>
yes
<youknow365>
would that be good for an im as well ?
<youknow365>
im sure jabber has that all covered
<zmdkrbou>
(irc *is* im ...)
<youknow365>
zmdkrbou: yes i knwo :P
<youknow365>
but like i said im sure jabber already has that covered
<youknow365>
it would just send me a notification saying user "##" has logged out
<pango_>
yes, it's not unusual that timeouts are part of protocols specs
<youknow365>
and jabber as popular as it is im sure has it
<youknow365>
so my only worry is making sure i recive complete messages from my jabber server
<youknow365>
more to this IM client then i would have thought
<youknow365>
jeeeshj
<youknow365>
then i also have to make a good looking GUI
<youknow365>
anyone know a quick tutorial on ocam for simply stuff like syntax looping while wtc and how to read documentaiton for ocaml ?
<youknow365>
i will spend a few hours over looking that stuff
<youknow365>
then implmennt my select
<youknow365>
then the XML
<youknow365>
then making sure i am not reciving incomplete messages
<youknow365>
also i am going ot deverlop on my laptop whihc is windows any objections ?
<Chea_544>
whats the differnce between ordinary functions and recursive functions again ?
<postalchris>
Recursion ;-)
shawn has joined #ocaml
Snark has joined #ocaml
<flux__>
hmm.. is there a way to succinctly express a set of rules to make, that would allow 'make -j clean all' ?
<Chea_544>
so whats the difference ?
<flux__>
let rec what_is_recursion () = what_is_recursion ()
<flux__>
let rec what_is_not_recursion () = ()
<postalchris>
:-D
<postalchris>
Chea: are you looking for a definition of "recursion" or are you asking something specifically about the syntax/semantics of OCaml?
<Chea_544>
i was just wondering what a recursion function was ?
<postalchris>
A recursive function is one that calls itself.
<Chea_544>
why would one do that
<postalchris>
Classic examples are Fibonacci, tree walkers.
<postalchris>
let rec fib n = if n < 2 then 1 else (fib (n-1) + fib (n-2))
<postalchris>
(The above is also a classically bad example!)
<Chea_544>
why would you call a function that you just made ?
<flux__>
a more practical example: filling a closed region in a bitmap with a certain color
<postalchris>
In order to define the function inductively
<postalchris>
You're going to need a better reference than IRC if you really want to "get" this.
<Chea_544>
still confused
<flux__>
you have a function that is provided coordinates, x and y, the old color and the new color
<Chea_544>
so a recursive function is jsut a function you call when you made it right before
<flux__>
the function goes like: if the color of the pixel is the same as the old color change the color of the pixel to the new color and call the function with the coordinates of the neighbouring pixels
<postalchris>
You may want to get a copy of the Aho&Ullman or Cormen, Rivest et al. algorithms texts
<Chea_544>
so same function called right after with new arguemnts ?
<flux__>
chea, the function would be: let rec fill x y oc nc = if pixel x y = oc then begin fill (x - 1) y oc nc; fill (x + 1) y oc nc; fill x (y - 1) oc nc; fill x (y + 1) oc nc; end
<flux__>
writing that in another way would be somewhat more complicated
<flux__>
right, it should also call set_pixel x y nc :)
<flux__>
or otherwise it would fill the memory and crash..
<Chea_544>
so hmmmm
<Chea_544>
so its a function inside of a function ?
slipstream has quit [Read error: 104 (Connection reset by peer)]
<flux__>
no, it's a function that calls itself
<Chea_544>
grrrrr
<Chea_544>
also ocamls # is liek c++ -> right ?
<flux__>
sort of
<Chea_544>
i see
<Chea_544>
sint it just used to you can define sub classes of that one ?
love-pingoo has joined #ocaml
<Chea_544>
how can a recursive function be an alternative to a loop ?
slipstream has joined #ocaml
<pango|n8>
try evaluating let rec loop () = loop () by hand :)
pango|n8 is now known as pango
<Chea_544>
oh man in my last 3 hours of learning i have basically understood everything but this recursive function crap
<pango>
another classical example:
<pango>
# let rec list_length = function [] -> 0 | h :: q -> 1 + list_length q ;;
<pango>
val list_length : 'a list -> int = <fun>
<pango>
# list_length [1;2;3;4] ;;
<pango>
- : int = 4
<pango>
that's a (simple, not optimal) recursive implementation of list length
<Chea_544>
but whats the advantage of using this recursive stuff ?
<mellum>
pango: why wouldn't it be optimal?
<pango>
it works because 1. there's a base case: the length of the empty list is 0 and 2. we reuse the function over a "smaller" argument, so eventually we'll reach the base case and give an end to recursive calls
<pango>
mellum: it's not tail recursive
<mellum>
pango: oh, right.
<mellum>
ocaml should really optimize this... even gcc does :)
<flux__>
but then there'd be code that would work with optimizations enabled, but not with them disabled. I guess it could just always do the optimization..
<pango>
Chea_544: for loops is an imperative construct, it relies on the availability of mutable variables
<pango>
Chea_544: the "closest equivalent" in functional languages is recursion
love-pingoo has quit ["Connection reset by pear"]
<pango>
many problems can be expressed recursively in a simple an natural way... and it really shines when you start working on non-linear datastructures (trees, graphs,...)
<Chea_544>
can i jus skip the recursive function
<Chea_544>
i am going to program ocaml in an imperative way C like
<pango>
I'm not sure you can, but I'm sure you shouldn't ;)
<mellum>
you're going to miss most of its power then.
<mellum>
also, you get ugly syntax :)
<Chea_544>
its still confusing meeeeee
<Chea_544>
is it bad to program in an imperative way ?
<pango>
it's bad not to use the paradigm that best fits the problem at hand
<mellum>
In fact, it has been shown to cause cancer in 78% of lab rats.
<Chea_544>
i dont see why i would use recursive functions is all im saying
smimou has joined #ocaml
<pango>
let's suppose you're working on a binary tree datastructure, and need to compute the size of a tree (number of leaves and nodes); Is there a simpler definition than "the size of a tree with a single leaf is 1, the size of a larger tree is the size of its left sub-tree + size of its right sub-tree + 1 (its root)"
<pango>
and then, you it be a better implementation than just translating that definition into code, if the language allows it ? Or do you prefer managing stacks yourself ?
<pango>
type 'a tree = Leaf | Node of 'a * 'a tree * 'a tree
<pango>
let rec tree_size = function Leaf -> 1 | Node (x, left, right) -> tree_size left + tree_size right + 1
<pango>
you'll probably end up preferring a recursive implementation of tree_size() in C, too
<Chea_544>
While recursion can simplify the solution of a problem, often resulting in shorter, more easily understood source code, it is often less efficient, in terms of both time and space, than iterative solutions. There are some methods to convert recursive algorithm into an iterative algorithm using a loop and branching structure
<postalchris>
Chea: go back to my Fibonacci example and think about the sequence of calls that it generates.
<Chea_544>
oh man too much for my brain i need sleeep
<Chea_544>
its like 4 am
<postalchris>
Also, please don't think you'll figure out in an afternoon on IRC what it took most of us a term of university to understand well.
<Chea_544>
well i have only been trying to grasp it for about the last hour......
<Chea_544>
i half understand it
<pango>
I do not agree on the "it is often less efficient" part, specially when you're using a functional language, that's optimized for that style...
<Chea_544>
hmmmmm
<pango>
lots of recursive functions evaluation is an iterative process, see tail recursion
<Chea_544>
ok so its used to use a function -- inside of the same function to alter the outcome or control the outcome of the main function ?
<pango>
in pure functional paradigm, the point of a function is to return a value, that's all
<pango>
whether a function uses another function, or itself, doesn't matter
<Chea_544>
pango: could you explain recursive function in an ABC example ?
<pango>
url ?
<pango>
or did I not get the question ;)
<pango>
a recursive function is one that uses itself in its definition
<Chea_544>
that makes no sense though lol
<pango>
it does
<Chea_544>
uses itself in the definition
<mellum>
Chea_544: asking people on IRC to stuff knowledge down your throat is not a reasonable way to learn. Just grab any book or tutorial and *try it yourself*.
<pango>
it's not just "recursive function: see 'recursive function'"
<pango>
even if indeed that definition is recursive
<pango>
of course the point is to use definitions that can actually be computed
<pango>
much like one usually tries to avoid infinite loops in real programs
<Chea_544>
ommg either im incedibly stupid or this makes absolutely no sense .......uses itself as a defnition .....thats like declaring a variable a = a
<pango>
not as a definition, but in its definition
<Chea_544>
how would that do any good
<TSC>
...
<Chea_544>
if you sue the function that you are trying to make
<Chea_544>
use
<Chea_544>
it would be using a incomplete function
<TSC>
No
<TSC>
Have you looked at any of the examples?
<TSC>
The one for computing the size of a binary tree?
<Chea_544>
no?
<TSC>
Maybe you should
<Chea_544>
i dont remmebr seeing any binary tree thingy ?
<TSC>
Then you should pay attention
<Chea_544>
hmm
<Chea_544>
everything* makes sense but this
<pango>
and, possibly, how function call actually works, it seems ;)
<Chea_544>
i think i get it now
<pango>
must be the beginning of a recursive mental process :)
<Chea_544>
i thiiiiiiiiiink i get it
<Chea_544>
so a recursive function could be used for like calling itself as many times as it needs to in the function until it recives everything
<Chea_544>
like for pulling an un expected result and an alternative to looping it
<pango>
yes, you must have "base case(s)", where you don't need another recursive call, otherwise evaluation will never complete
<Chea_544>
thats what i was thinking
<Chea_544>
so like somehwere where it can exit
<Chea_544>
or per say call itself finished
<pango>
or at least resume the evaluation of the function one level up
<Chea_544>
so it would be like used for looking into a file system and pulling folders
<pango>
for example
<Chea_544>
so instead of using a loop to get all the folders
<Chea_544>
you could use a recursive function to keep calling for them until there is no more
<pango>
folders are just an example of recursive datastructure, so it's normal that you need recursive functions to handle them
<Chea_544>
well a recursive function could be used for anything where you know theres more of something
<Chea_544>
or for repeated actions
<Chea_544>
where you dont want to use a loop or something
<pango>
yup, I think you got it
<Chea_544>
but how would you let it know when to exit or set a exit strategy out so it ends and doesnt go on forever ?
<Chea_544>
hmmmm recursive functions could be used for lots of things
<pango>
all you need is to always call the function on "smaller" arguments
<pango>
that is, that are "closer" to your base case(s)
<Chea_544>
so could recursive functions replace loops ?
<pango>
break big problems into smaller one(s)
<Chea_544>
pango: so can recursive functions in a way repalce loops
<pango>
in pure functional paradigm you don't have loops
<Chea_544>
ooooo
<Chea_544>
i guess that anwsers that question ;)
<Chea_544>
well jeese thats the hardest concept yet i have had to grasp in a long time
<Chea_544>
kinda breaks all the rules of loops
<pango>
but instead of writing recursive functions all the time, it's best to use high order functions when you can... there's probably another chapter on that topic, however
<Chea_544>
pango: man i respect all that real complicated stuff but im just doing small projects, im trying to keep it simple as possible and yet learn as much as possible at the same time
<Chea_544>
high order functions just sounds complicated
<pango>
not that much
<pango>
it's just that after a while, you notice that a lot of recursive functions "look the same"
<Chea_544>
also when do you use ";" i know when you use ;; but when just one ?
<pango>
mmh can you wait 10 mins ? have to switch places
pango has quit ["brb"]
zmdkrbou has quit [Remote closed the connection]
zmdkrbou has joined #ocaml
love-pingoo has joined #ocaml
pango has joined #ocaml
<TSC>
You should read the tutorials on OCaml
<pango>
back
<Chea_544>
yea
<Chea_544>
TSC: i am
<Chea_544>
its just that recursive stuff didnt make sense till now
<Chea_544>
how do you guys feel about ocaml for web work ?
<pango>
web frameworks are still weak (in features), compared to perl/php/python/ruby/...
<Chea_544>
pango: what you mean mod ocaml ....... good or bad ?
<Chea_544>
php is the RULER of web langs ;)
<piggybox>
ya, and ruby is catching up fast
<Chea_544>
but Ruby is slow
<Chea_544>
very slow
<Chea_544>
so many complaints about it
<piggybox>
yes, pretty slow, but not a too serious issue for web app where caches are widely used
<Chea_544>
yea
<Chea_544>
buuuut
<Chea_544>
i swsaw a few forum post of peopel with alot of traffic ......there site being slower becasue of ruby's speed
<Chea_544>
saw
<pango>
I think that right now the main problem of web frameworks are security issues... Anything, reasonably performant, that will fix the biggest ones, could get a place on the map
<piggybox>
Well, page caches require a lot of effort to design carefully, that's the pain
<pango>
php as a language is utter crap however (and I hate the idea of mixing arrays and hash tables in a single datastructure. They even had a major security flow because of this, why I am not even surprized)
<love-pingoo>
anybody knows a page summing up the long history of php security bugs ?
<pango>
maybe they should have formally proven the code of their basic datastructure ;)
finelemo2 has quit [Read error: 110 (Connection timed out)]
shrdlu has joined #ocaml
<shrdlu>
Hi all. I'm writing a parser with ocamllex/ocamlyacc and I would like to output line/char numbers to the user in case of syntax errors. Anybody knows how to do this?
<postalchris>
I'm really surprised that's not in the manual/FAQ
<shrdlu>
well there's something about the parse_error function which one can customize
<shrdlu>
but I don't see how to proceed from there. The Parsing.Parse_error exception doesn't carry any info, does it?
<zmdkrbou>
t does carry information
<zmdkrbou>
+i
<zmdkrbou>
but the doc is not so clear about that
<zmdkrbou>
shrdlu: you have to look at the doc for modules Lexing and Parsing (in the lib reference)
<shrdlu>
there's an example on how to use the functions from the Parsing module
<shrdlu>
but that's not what I want
<zmdkrbou>
then i suppose doing it yourself is the simplest way
<zmdkrbou>
that's not so much work so it's ok
<shrdlu>
btw, does the lexer first transform the whole input into tokens, which are then passed to the parser
<shrdlu>
or do they somehow interact?
<zmdkrbou>
no they interact
<zmdkrbou>
the lexer reads input on demand
<shrdlu>
ok since otherwise counting wouldn't work
<zmdkrbou>
yes :)
<shrdlu>
ok then I'll try to hack something. thanks anyways:)
Snark has quit [Read error: 110 (Connection timed out)]
Snark has joined #ocaml
<shrdlu>
zmdkrbou: I think I found a nice way to do it:
<shrdlu>
I keep a pointer in the .mll file file which I initialize with some dummy lexbuf
<shrdlu>
an my get_info just returns the value the pointer points to
<shrdlu>
then I call ocamllex, and in the generated .ml file, I add lexdata := lexbuf into the "token" function
<shrdlu>
this way, the lexbuf always stays up to date with every step of the lexer
<zmdkrbou>
aaaargl
<shrdlu>
it's just 3 lines of code altogether
<zmdkrbou>
you should *not* change the generated .ml file
<zmdkrbou>
don't you have a makefile ? don't you have "make clean" which will erase the .ml ?
<shrdlu>
I do
<shrdlu>
of course now I have to do 2 steps
<zmdkrbou>
then you use sed or something in your makefile to do this ?
<shrdlu>
this would be a way to do it
<zmdkrbou>
this is a dirty hack :\
<shrdlu>
c'mon it works :)
<zmdkrbou>
yes
<shrdlu>
however it appears that the lexer does not automatically count the lines
<zmdkrbou>
but it's ugly :)
<zmdkrbou>
then add line counting to your lexer
<shrdlu>
so in the position record, pos_lnum is always 1, unless you increase it "manually"
<shrdlu>
problem is, my input is very dense, so the line number alone won't help the user find his mistake
<zmdkrbou>
getting characters position is not that hard
<shrdlu>
how?
<zmdkrbou>
you can get character index in the whole file easily
<zmdkrbou>
then when you count lines, juste update a "base index"
<zmdkrbou>
global_index - base_index = position in the current line
<shrdlu>
but then don't you have to update the index with every token?
<zmdkrbou>
nope
<zmdkrbou>
just on every newline
tennin has joined #ocaml
<shrdlu>
hm
<shrdlu>
what is global_index?
<zmdkrbou>
the position of the character in the file
<zmdkrbou>
ie. its index if the file was a string
<shrdlu>
but how do get this? I mean if a parsing error occurs, then I land in parse_error, so I call the lexer's get_info. How do I know which character was read last?
tennin has quit [Read error: 60 (Operation timed out)]
tennin has joined #ocaml
smimou has joined #ocaml
shrdlu has quit ["Leaving"]
love-pingoo has quit ["Leaving"]
tennin has quit [Read error: 113 (No route to host)]
<youknow365>
is it better to use loops or just use recursive functions ?
shawn has quit ["This computer has gone to sleep"]
mwc has joined #ocaml
shawn has joined #ocaml
SSelva has joined #ocaml
_jol_ has joined #ocaml
mwc has quit ["Leaving"]
love-pingoo has quit ["Connection reset by pear"]
mwc has joined #ocaml
<youknow365>
what are better performance wise ?
mwc has quit ["leaving"]
mwc has joined #ocaml
mwc has quit [Client Quit]
mwc has joined #ocaml
_jol_ has quit ["leaving"]
kryptt has joined #ocaml
kryptt has left #ocaml []
mwc has quit ["Lost terminal"]
SSelva has left #ocaml []
Snark has quit ["Leaving"]
mnemonic has joined #ocaml
<mnemonic>
hi
Eelis has joined #ocaml
<Eelis>
greetings
<Eelis>
how come the '<' operator works equally for both ints and floats, while the '+' operator doesn't? is there some fundamental difference between the two?
<Eelis>
does it have to do with return types, perhaps?
<Eelis>
(since for '<' it's always bool while for '+' it depends on the operands)
<Eelis>
or rather, "it /would/ depend"
<zmdkrbou>
because + only works on ints and floats
<zmdkrbou>
(in its +. version for floats)
<zmdkrbou>
but <, > and = are related to the "compare" function
<zmdkrbou>
i mean (in)equality is something that has a meaning for a lot of types, + doesn't
<Eelis>
hmm, is the fact that one has to use "+." for floats a conscious decision or is there simply no way to make + work for both ints and floats in ocaml?
<zmdkrbou>
no its a design choice
<Eelis>
ah, i see
<zmdkrbou>
there's no overloading in ocaml
<zmdkrbou>
(except for < > = and ==)
<zmdkrbou>
(because *they* are special operators)
<Eelis>
oh, i see. yes, special treatment for those would explain it
<Eelis>
thanks, it makes sense now :)
<Eelis>
i can't say i like it, but that's another story ;)
<zmdkrbou>
btw, there's no overloading but you can "redefine" operators :)
<zmdkrbou>
(i'm no more happy with +. etc. than you are)
Smerdyakov has quit [Read error: 110 (Connection timed out)]
Smerdyakov has joined #ocaml
<Smerdyakov>
Eelis, the generality of (<) in OCaml is very undesirable, since it's done in such an ad-hoc way.
<Eelis>
yes, that's the impression i got, but i didn't voice it because i didn't want to come off as a whining newbie, considering that i'm still very new to OCaml :)
<smimou>
someday, maybe gcaml will be integrated mainstream...