dark_light changed the topic of #ocaml to: OCaml 3.09.2 available! Archive of Caml Weekly News: http://sardes.inrialpes.fr/~aschmitt/cwn/ | A free book: http://cristal.inria.fr/~remy/cours/appsem/ | Mailing List: http://caml.inria.fr/bin/wilma/caml-list/ | Cookbook: http://pleac.sourceforge.net/
slipstream has quit [Read error: 104 (Connection reset by peer)]
slipstream has joined #ocaml
mpc has quit []
jcreigh has joined #ocaml
slipstream has quit [Read error: 104 (Connection reset by peer)]
slipstream has joined #ocaml
<pango_> youknow365: that's why you see buffering so often (they're other solutions, that's an easy one)
<pango_> or, if you can't tell when you received a full message, you must be able to resume parsing where you left it at the end of previous packet
slipstream has quit [Connection reset by peer]
slipstream has joined #ocaml
dan2 has joined #ocaml
<youknow365> pango_: you have brought a new problem to the table dammmit
jcreigh has quit ["Cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet."]
<youknow365> damn damn
<youknow365> how could i stop from packets getting mixed up etc
<Grincheux> mixed ?
<youknow365> or making sure i get the remaining message
<Grincheux> you will get it
<youknow365> i dont see why all the message wouldnt be in 1 packet
<youknow365> the max jabber allows is likwe 1.5 KB
<Grincheux> ethernet frame are 1500 bytes
<Grincheux> a little bit more actually
<Grincheux> s/more/less/
<Grincheux> sonet frames on the backbone is 53 bytes
<Grincheux> IP fragments too
<Grincheux> you cannot be sure what will happen
<youknow365> so do i have to worry about that or not ?
<Grincheux> yes
<youknow365> should all the bytes be in one packet ?
<youknow365> message i mean
<Grincheux> fragmentation happens, not always when you send small messages, but it certainly happens
<youknow365> this is im messages
<Grincheux> TCP/IP/Ethernet does not care about the contents
<youknow365> ??
<Grincheux> <youknow365> this is im messages << it does not matter
<youknow365> yea i know
<youknow365> but wouldn't it have ot be over a certain size
<youknow365> to be split up
<Grincheux> it depends what network, routers, machines are between you and the other guy
carrumba has quit [Read error: 110 (Connection timed out)]
Grincheux has left #ocaml []
<youknow365> dammmmit
<youknow365> so what do i have to do here somebody ?? zmdkrbou pango_ ???
<zmdkrbou> you have to check, once you received data, that it's a complete message. if not, you store it until you reiceve enough to complete it.
<youknow365> oh shit dude
<youknow365> that just sounds like trouble
<zmdkrbou> that sounds like i told you wouldn't make it in such a short time
<youknow365> never knew about that man
<zmdkrbou> (not using ocaml, at least)
<youknow365> i thought it had to be a certain number of bytes ot be split up in more then one packet
<youknow365> damn damn
<youknow365> zmdkrbou: whats the best way of doing this for IM ??
<youknow365> storing it where ?
<zmdkrbou> in a string
<zmdkrbou> (how tricky)
<youknow365> how could i knwo if i recived the whole message ?
<zmdkrbou> a message should have something to mark ending
<youknow365> im sure jabber does
<zmdkrbou> what kinds of message is it ?
<youknow365> so use regex ?
<zmdkrbou> look at the jabber doc
<zmdkrbou> yes
<zmdkrbou> (or don't use it if that's a very simple delimiter)
<youknow365> </stream:stream>
<youknow365> zmdkrbou: any need for regex ?
<zmdkrbou> try to guess ...
mpc has joined #ocaml
<youknow365> zmdkrbou: i would say no ????? buut give me your input
shawn has quit [Read error: 110 (Connection timed out)]
<youknow365> since its very simple
shawn has joined #ocaml
<youknow365> usually regexx is for scanning different messages for certain things
<zmdkrbou> you can do without regexp, yes
<youknow365> ok
<zmdkrbou> (your message is not complete until you receive a '>')
<youknow365> huh?
<youknow365> someone could send one of those in a message
<zmdkrbou> you have to escape this ...
<youknow365> </stream:stream>
<youknow365> could that be the delimiter ?
<zmdkrbou> do you know what an escape sequence is ?
<youknow365> i knwo what escaping is yes
<zmdkrbou> so what's the problem ?
<youknow365> escaping is usually used to remove any junk
<zmdkrbou> if you get \> or equivalent, then that's not the end
<zmdkrbou> if you get >
<zmdkrbou> then it's the end
<youknow365> but i am saying i can say t you in an im i am > then you
<youknow365> zmdkrbou: ??
<zmdkrbou> mmh ?
<zmdkrbou> the sentence was not a correct sequence of words
<youknow365> ok ok
<youknow365> </stream
<youknow365> could i just use that as a delimiter ?
<youknow365> or at the very beginning send the number of bytes the message is if its below then it would wait
<zmdkrbou> you have to do it the way jabber forces you to do
<youknow365> ok ??
<zmdkrbou> i think i misread the delimiter
<zmdkrbou> what will a message look like ?
<youknow365> <message to="bob@example.com" >
<youknow365> <subject>Hello!</subject>
<youknow365> <body>Can't wait to see you tomorrow.</body>
<youknow365> </message>
<youknow365> <presence type="unavailable" >
<youknow365> <status>Logged out</status>
<youknow365> </presence>
<youknow365> </stream:stream>
<zmdkrbou> mmmh
<youknow365> <stream:stream xmlns:stream="http://etherx.jabber.org/streams"
<youknow365> xmlns="jabber:client" to="example.org">
<youknow365> ^^ very beginnning
<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 ?
<pango_> http://caml.inria.fr/pub/docs/manual-ocaml/manual003.html#htoc7 but recursive functions are more common
mpc has quit []
pango_ is now known as pango|n8
mpc has joined #ocaml
jcreigh has joined #ocaml
dan2 has left #ocaml []
dvekravy has quit [Remote closed the connection]
dvekravy has joined #ocaml
joshcryer has joined #ocaml
pango|n8 has quit [Remote closed the connection]
pango|n8 has joined #ocaml
bzzbzz has quit ["leaving"]
tennin has joined #ocaml
shawn has quit [Read error: 110 (Connection timed out)]
dvekravy has quit [Remote closed the connection]
shekmalhen has joined #ocaml
jcreigh has quit ["Cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet."]
<youknow365> pango|n8: still reading these tutorials
<youknow365> man everything is so different
<youknow365> even a damn if statement
<Smerdyakov> There are no statements in OCaml. ;)
Smerdyakov has quit ["Leaving"]
<youknow365> whats the difference between ordinary function and recursive function ?
<shekmalhen> heh
<shekmalhen> the recursive function is, internally, optimised for recursive calls. eg.: It won't fill the stack
youknow365 has quit ["Konversation terminated!"]
mpc has quit []
Smerdyakov has joined #ocaml
postalchris has joined #ocaml
tennin has quit ["Download Gaim: http://gaim.sourceforge.net/"]
shekmalhen has quit ["Snakes on Crack!!"]
Chea_544 has joined #ocaml
<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 ?
<Chea_544> lol postalchris your exxageratting for a simple problem
<postalchris> Chea: I'm not trying to exaggerate. Recursion is a very important part of programming and CS
<Chea_544> i understand, but i dont think it takes a book to learn that one thing
<postalchris> flux may get you to the point where you grok the syntax...
<postalchris> the books may teach you a few other useful things as well ;-)
<postalchris> Read this, then worry about the syntax: http://en.wikipedia.org/wiki/Recursion
<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> try implementing that in C, and compare
<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/...
<pango> but improving...
smimou has quit ["bli"]
<piggybox> just seen F#'s new lightweight syntax, pretty cool: http://blogs.msdn.com/dsyme/archive/2006/08/24/715626.aspx
<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
<piggybox> chea: check this http://wiki.rubyonrails.org/rails/pages/Framework+Performance, though the cakephp test might not be configured properly
<piggybox> sry, the symfony php, not cakephp
<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 ?
<love-pingoo> nice bit
finelemon has joined #ocaml
<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> ah ok, so I have to look a the current lexbuf's position
<zmdkrbou> yep
<shrdlu> thanks
<shrdlu> but I can't access the lexbuf from within the .mly file
<zmdkrbou> you can put a "get_info" function in the header of your .mll
<zmdkrbou> then use Yourlexername.get_info to retrieve the lexing buffer data
<shrdlu> ok sounds good
ingeB0RG is now known as ulfdoz
<shrdlu> zmdkrbou: what exactly should get_info return? It seems I can't access the lexbuf from within the .mll's header
<zmdkrbou> mmh yes that's right
<zmdkrbou> in fact :
<zmdkrbou> this seems to be simpler :)
<zmdkrbou> (i don't know if it provides everything you need, but it should i suppose)
<shrdlu> yes I looked at that, but I think those functions can only be called from within a grammar rule
<zmdkrbou> and you need them somewhere else ?
<shrdlu> actually what I want is that whenever a parsing error occurs, the corresponding position in the input is returned
<shrdlu> so I'm not in a grammar rule any more
<shrdlu> or should I introduce for each nonterminal a rule with the special "error" token?
<zmdkrbou> nope
<zmdkrbou> mmm. this is not so well done
<zmdkrbou> you can have global values
<shrdlu> yes I thought about having a global pointer on the lexbuf in the .mll file
<zmdkrbou> personnaly i don't like the way it's done so i count newlines (using a reference) in my lexer, and then i can use it easily
<shrdlu> ok
<zmdkrbou> but i always though i was wrong doing so, and that the Lexing and Parsing modules had what i needed :)
<zmdkrbou> (+t)
<shrdlu> sorry
<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)]
tennin has joined #ocaml
pango has quit ["Leaving"]
pango has joined #ocaml
love-pingoo has joined #ocaml
postalchris has quit ["Trillian (http://www.ceruleanstudios.com"]
tennin has quit ["Download Gaim: http://gaim.sourceforge.net/"]
<Chea_544> hola everone zmdkrbou pango etc
Chea_544 has quit []
Stormogulen has joined #ocaml
Stormogulen has left #ocaml []
youknow365 has joined #ocaml
<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...
smimou has quit ["bli"]
mnemonic has quit ["leaving"]