<Nutssh>
Oh, doing that iss no problem. But I'd like to parse cocnventional regexps, in the perl syntax.
<Nutssh>
But thanks for the link. Its a good alternative syntax.
<Riastradh>
Why do you want to parse POSIX regexps?
<Nutssh>
Because that is the most frequently used syntax.
<ayrnieu>
Please don't actually use POSIX regexps.
<Nutssh>
Its also very dense, which is another plus.
<Riastradh>
Why are you using OCaml instead of C if you like that logic?
<Nutssh>
Because I'm doiing, or will be doing, transformations on the AST, and Ocaml is a much better applications language than C. Especially for securiity conscious software.
<Nutssh>
ayrnieu: What do you mean exactly by that?
<Riastradh>
Density is not necessarily an advantage.
<ayrnieu>
nutssh - eh, I mean that I wish that you'd not actually use POSIX regexps -- because they have many deficiencies to them, compared to Perl's system; because they use \ as a significant character which makes for much ugliness outside of special syntax.
<Nutssh>
Nor is verbosity.
<Riastradh>
Verbosity has the advantage of readability.
<Riastradh>
Or at least in this case, anyways.
<Nutssh>
ayrnieu: Oh. Ok. I'm actually planning on using the flex/bison.
<Nutssh>
Riastradh: Not when most of the tokens are parenthesis. 'ab[cdef]*g(hi|jk)' would be most of a line in the scsh sexp syntax or ocamllex.
<ayrnieu>
nutssh - and you don't have a POSIX regexp, there.
<ayrnieu>
nutssh - you really want "abc\\[cdef\\]*g\\(hi\\|jk\\)"
<Nutssh>
Ok.. It would work with an editor that does parentheis matching.
<ayrnieu>
eh, or a human.
<Nutssh>
ayrnieu: Um. No. But in flex, it would be pretty much exactly as I gave it.
<ayrnieu>
nutssh - as abc\[cdef\]*g\(hi\|jk\) ? Sure.
<ayrnieu>
nutssh - so you don't ever plan on actually expressing such regular expressions in other programs to pass to this parser?
<Nutssh>
ayrnieu: No, Thats definitely broken. On the other hand, the perl scheme has problems, '\' isn't a generic escape, \X doesn't mean a literal 'X' if X='d'.
<Riastradh>
SREs have no weird escape devices.
<ayrnieu>
nutssh - to what do you refre as definitely broken?
<ayrnieu>
also, refer.
<Nutssh>
ayrnieu: I can have more than one external syntax. I mean the use \ to indicate every command character like \( \) etc.
<ayrnieu>
nutssh - the POSIX regexp syntax, yes.
<Nutssh>
I expect to use the flex syntax. The exact variant flex, perl, posix, etcc doesn't matter. How do parse.
_JusSx_ has quit ["BitchX: a new fragrance for men, by Calvin Klein"]
d2004xx_ has joined #ocaml
<Nutssh>
Any ideas? I can't lex larger than one character because '12{12}', the first 12 is two tokens, the second 12 is one. I'm using streams, but explicitly left-factoring the grammar.
d2004xx__ has joined #ocaml
d2004xx_ has quit [Read error: 104 (Connection reset by peer)]
d2004xx has quit [Read error: 104 (Connection reset by peer)]
d2004xx__ is now known as d2004xx
whiskas has quit ["Leaving"]
d2004xx has quit ["Client Exiting"]
d2004xx has joined #ocaml
Nutssh has quit ["Client exiting"]
Smerdyakov has quit [Nick collision from services.]
Smerdyakov has joined #ocaml
blueshoe has quit [Read error: 104 (Connection reset by peer)]
teratorn has joined #ocaml
whiskas has joined #ocaml
<whiskas>
Hello
<whiskas>
I'm trying to construct a function that takes two arguments, a string and a int, and prints the string as many times as the int parameter say; I have tried this approach:
<whiskas>
let rec repeated s n = if n > 0 then print_string n; repeated s (n - 1);;
<whiskas>
But it just hangs when I run it, any ideas?
<whiskas>
(And yes, I'm so newbie to O'Caml)
wazze has quit ["If we don't believe in freedom of expression for people we despise, we don't believe in it at all -- Noam Chomsky"]
lus|wazze has quit ["If we don't believe in freedom of expression for people we despise, we don't believe in it at all -- Noam Chomsky"]
blueshoe has joined #ocaml
<whiskas>
Hey
<teratorn>
odd
<whiskas>
What?
<whiskas>
And by the way, I've tried defining a factorial function, like this
<whiskas>
let rec factorial n = if n > 0 then n * factorial (n - 1) else 1;;
<whiskas>
But for every argument different than 1, it throws Stack overflow during evaluation (looping recursion?). at me
<whiskas>
What the heck am I doing wrong?
<whiskas>
Anyone?
<teratorn>
uhh, well you have "print_string n" for one
<whiskas>
Nevermind that, just a typo
<whiskas>
And what about the factorial function?
<teratorn>
figured
<teratorn>
i don't know what is wrong with it
<teratorn>
but you can use pattern matching instead
<whiskas>
Lemme try
<whiskas>
Hmm, how can I match something that is greater than something else?
<teratorn>
# let rec factorial = function
<teratorn>
0 -> 1
<teratorn>
| n -> n * factorial (n - 1);;
<whiskas>
Ok, that works; still, not as expected, it should give an error with the argument is negative
<whiskas>
And I don't know what's wrong with the if stuff
<whiskas>
Shouldn't it work that way?
<teratorn>
it works for me
<whiskas>
Ok, it seems there's something wrong with my system
<whiskas>
Which is weird, btw
Nutssh has joined #ocaml
<vect>
whiskas try "then (print_string s; repeat s (n-1))"
<whiskas>
Lemme see (the factorial still doesn't work with ifs)
<Nutssh>
Hi.
<vect>
hi
<whiskas>
vect: Ok, this one works
<whiskas>
Hey Nutssh
<Riastradh>
whiskas:
<Riastradh>
let rec factorial = function
<Riastradh>
n when n > 0 -> n * factorial (n - 1)
<Riastradh>
| _ -> 1
<whiskas>
That should clearly work
<whiskas>
Still, I don't uderstand what I'm doing wrong if the other form
<whiskas>
Aah, I've got it
<whiskas>
I just needed parens around x - 1
<ayrnieu>
whiskas - what did you get?
<Nutssh>
Hi whiskas
<ayrnieu>
er, yes, function application binds more strongly than any operator.
<whiskas>
Somebody should have told that to me :-)
vect is now known as gl
<whiskas>
Hmm, how would one define a nested function?
<ayrnieu>
let x a = let y b = b+b in y a + y a;;
<whiskas>
Thank you
<whiskas>
Hmm
<whiskas>
let range a b = let range2 x y accum = if x > y then accum else range2 (x + 1) y (x :: accum) in range2 a b [];;
<whiskas>
Doesn't work
<Etaoin>
range2 needs to be recursive
<Etaoin>
... let rec range2 ...
<whiskas>
Yeah, I just figured it out ;-)
<Etaoin>
wonderful
<whiskas>
This takes quite some time to complete: range 1 1000000000;;
<whiskas>
And it's eating my RAM
<Etaoin>
not really surprising is it?
<whiskas>
Hehe, no
<Etaoin>
bah
<Etaoin>
(wrong window)
ayrnieu has quit [brunner.freenode.net irc.freenode.net]
shawn has quit [brunner.freenode.net irc.freenode.net]
srv has quit [brunner.freenode.net irc.freenode.net]
mw has quit [brunner.freenode.net irc.freenode.net]
yella has quit [brunner.freenode.net irc.freenode.net]
cmeme has quit [brunner.freenode.net irc.freenode.net]
Riastradh has quit [brunner.freenode.net irc.freenode.net]
blueshoe has quit [brunner.freenode.net irc.freenode.net]
Smerdyakov has quit [brunner.freenode.net irc.freenode.net]
Etaoin has quit [brunner.freenode.net irc.freenode.net]
mattam has quit [brunner.freenode.net irc.freenode.net]
ejt has quit [brunner.freenode.net irc.freenode.net]
teratorn has quit [brunner.freenode.net irc.freenode.net]
smkl has quit [brunner.freenode.net irc.freenode.net]
blueshoe has joined #ocaml
teratorn has joined #ocaml
Smerdyakov has joined #ocaml
Etaoin has joined #ocaml
mattam has joined #ocaml
ayrnieu has joined #ocaml
shawn has joined #ocaml
mw has joined #ocaml
Riastradh has joined #ocaml
yella has joined #ocaml
srv has joined #ocaml
ejt has joined #ocaml
cmeme has joined #ocaml
smkl has joined #ocaml
srv has quit [brunner.freenode.net irc.freenode.net]
shawn has quit [brunner.freenode.net irc.freenode.net]
mw has quit [brunner.freenode.net irc.freenode.net]
yella has quit [brunner.freenode.net irc.freenode.net]
ayrnieu has quit [brunner.freenode.net irc.freenode.net]
cmeme has quit [brunner.freenode.net irc.freenode.net]
Riastradh has quit [brunner.freenode.net irc.freenode.net]
ejt has quit [brunner.freenode.net irc.freenode.net]
Etaoin has quit [brunner.freenode.net irc.freenode.net]
mattam has quit [brunner.freenode.net irc.freenode.net]
blueshoe has quit [brunner.freenode.net irc.freenode.net]
Smerdyakov has quit [brunner.freenode.net irc.freenode.net]
teratorn has quit [brunner.freenode.net irc.freenode.net]
smkl has quit [brunner.freenode.net irc.freenode.net]
blueshoe has joined #ocaml
teratorn has joined #ocaml
Smerdyakov has joined #ocaml
Etaoin has joined #ocaml
mattam has joined #ocaml
ayrnieu has joined #ocaml
shawn has joined #ocaml
mw has joined #ocaml
Riastradh has joined #ocaml
yella has joined #ocaml
srv has joined #ocaml
ejt has joined #ocaml
cmeme has joined #ocaml
smkl has joined #ocaml
srv has quit [brunner.freenode.net irc.freenode.net]
shawn has quit [brunner.freenode.net irc.freenode.net]
mw has quit [brunner.freenode.net irc.freenode.net]
yella has quit [brunner.freenode.net irc.freenode.net]
ayrnieu has quit [brunner.freenode.net irc.freenode.net]
cmeme has quit [brunner.freenode.net irc.freenode.net]
Riastradh has quit [brunner.freenode.net irc.freenode.net]
ejt has quit [brunner.freenode.net irc.freenode.net]
Etaoin has quit [brunner.freenode.net irc.freenode.net]
mattam has quit [brunner.freenode.net irc.freenode.net]
blueshoe has quit [brunner.freenode.net irc.freenode.net]
Smerdyakov has quit [brunner.freenode.net irc.freenode.net]
teratorn has quit [brunner.freenode.net irc.freenode.net]
smkl has quit [brunner.freenode.net irc.freenode.net]
blueshoe has joined #ocaml
teratorn has joined #ocaml
Smerdyakov has joined #ocaml
Etaoin has joined #ocaml
mattam has joined #ocaml
ayrnieu has joined #ocaml
shawn has joined #ocaml
mw has joined #ocaml
Riastradh has joined #ocaml
yella has joined #ocaml
srv has joined #ocaml
ejt has joined #ocaml
cmeme has joined #ocaml
smkl has joined #ocaml
blueshoe has quit [Read error: 104 (Connection reset by peer)]
Nutssh has quit ["Client exiting"]
<whiskas>
Hmm, anyone still awake?
<ayrnieu>
Yes.
<whiskas>
I'm trying to make my own List.map function
<ayrnieu>
OK.
<whiskas>
Could I show you the approach I've taken in order to get some hints? (btw, this doesn't compile yet)
Nutssh has joined #ocaml
<ayrnieu>
Go ahead.
<whiskas>
let my_map alist f = let my_map2 lst f2 result =
<whiskas>
match lst with [] -> result | [x] -> (f2 x) :: result | head :: tail -> (f2 head) :: (my_map2 tail f2 result)
<whiskas>
in my_map2 alist f [];;
<whiskas>
That would be it.
<Riastradh>
Way too complicated.
<whiskas>
Hmm. How come?
<Riastradh>
It can be made simpler.
<whiskas>
Ahh, lemme see...
<whiskas>
Hmm, I can't think of any way without using an "accumulator"
<ayrnieu>
let map f l = match l with [] -> [] | (h::t) -> ...
<Riastradh>
The stack is often a great accumulator.
<whiskas>
Yeah, that's what just came to my mind :-P
<Riastradh>
List.map f [a; b; c; d] <=> [f a; f b; f c; f d]
<Riastradh>
Rewrite that example using :: instead of the square bracket notation and you might get a good idea.
<whiskas>
What about this?
<whiskas>
let rec my_map l f = match l with [] -> [] | head :: tail -> (f head) :: (my_map tail f);;
<Riastradh>
That works, although typically the list and function arguments are reverse, and you can safely remove all parentheses used therein.
<whiskas>
Anything but that?
<Riastradh>
s/reverse/in the other order/1
<whiskas>
Yeah, I got that part
<Riastradh>
Other than those two changes, that's precisely how I'd write it.
<whiskas>
Heh, I'm pretty good then, it only took me one night of reading :-P
<whiskas>
Anyways, can this be turned into some form of tail-recursion?
<Smerdyakov>
Everything can be made tail recursive.
<Riastradh>
Yes, but whether or not it's a good idea is another question.
<whiskas>
How come?
<whiskas>
I thought that tail-recursion is a good thing.
<Riastradh>
Either way, you're going to be using an intermediate data structure, either the stack or a list that you build up in reverse.
<Smerdyakov>
Most functions become more complicated when made tail recursive.
<Smerdyakov>
More complicated is bad.
<whiskas>
Aha.
<whiskas>
Say, after scanning the manual, I saw no reference to network programming libs. Is there such a thing for O'Caml?
<whiskas>
And what about the I/O system, in general?
<Nutssh>
Tail recursion is important though if you're going to be analyzing somethign of arbitrary size.
<Smerdyakov>
Nutssh, which is fine in certain compilation strategies.
<Smerdyakov>
Nutssh, but these silly OS's today tend to give fixed size stacks. :(
<Riastradh>
Nutssh, if you do make it tail recursive, you have to allocate an extra cons cell for each item in the list.
<Riastradh>
_And_ you have to add the overhead of reversing that intermediate structure you consed up.
<whiskas>
That the heck does cons mean?
<Nutssh>
Yes, but it has to be kept in mind.. (cons, roughly means 'allocate' or 'to allocate')
<Riastradh>
It's short for 'construct,' generally in the context of lists -- (::) is pronounced 'cons' --.
<Nutssh>
(cons is from lisp, a cons is a pair.)
<ayrnieu>
whiskas - you typically want the function argument first for useful currying
<Nutssh>
Riastradh: True, but the overhead of the stack is almost sure to be greater than that of the list. Deallocation doesn't hit the GC< but at the same time, there's more of it so the caching effects will bite you.
<ayrnieu>
let my_map f l = ...
<ayrnieu>
let add_ones l = my_map (function x => x + 1);;
<Nutssh>
(Sorry, greater than that of making a list then reversing it.)
<whiskas>
ayrnieu: Thanks.
<whiskas>
Hmm, could anyone give me some hints on writing a list reversing function?
<ayrnieu>
let rev l = match l with [] -> [] | (h::t) -> ... =)
<whiskas>
What does ... do/mean?
<ayrnieu>
exercise for the reader.
<whiskas>
:-))
<ayrnieu>
Actually, you wouldn't use that pattern.
<ayrnieu>
but do you have any more specific questions on list reversal?
<whiskas>
Umm, what do you mean?
<Nutssh>
I've just done a test.. Interesting. The tail recursive version followed by an explicit reverse is about 5 times slower than the stack-based one, but it can reverse a 10 million element list. (The stack-based one stack_overflows)
<Nutssh>
OH wait. Nevermind. THe stack-based one overflows.
<Smerdyakov>
I think you already said that.
<Nutssh>
No, it overflows on the 1000,000 element one too. I didn't notice the first time.
<Nutssh>
Performance on 500k elements, stack=2.7s tail=1.6. On 50k stack=.8 tail=1.2. On 100, stack=1.9 tail=1.8
<whiskas>
I made a function that reverses a list :-P
<Nutssh>
Heh. Good. :)
<whiskas>
By the way, how would you do it?
<whiskas>
(Ya know, I've been doing O'Caml for like... 6 hours now?)
<Nutssh>
I posted the URL to a program where I compared the tail recursive and stack-based versions of map in performance. See there.
<whiskas>
Hmm
<whiskas>
I don't get that "function" and _ part
<whiskas>
I know that _ matches everything, but what does function mean?
<whiskas>
Nah, I don't get it
<Nutssh>
function FOO === fun x -> match x with FOO
<whiskas>
OK
<whiskas>
Hmm...
blueshoe has quit [Read error: 104 (Connection reset by peer)]
<Maddas>
Interesting
<Maddas>
I didn't know tali recursion would have such a performance impact
* Maddas
rewrites some things and makes them simpler again
<Maddas>
Nutssh: how did you time, simply with the `time' command or is there any built-in way?
* Maddas
curses time zones
* Maddas
also curses the vim caml mode while he's at it
blueshoe has joined #ocaml
<Maddas>
Hi, blueshoe!
<blueshoe>
hey
gim_ has joined #ocaml
<Nutssh>
the time command.
<Nutssh>
Maddas: Hmms? Were you expecting faster or slower?
<Maddas>
Nutssh: I hoped faster, I didn't expect much though.
<Maddas>
I overlooked that it has an additional List.rev, though
<Nutssh>
It isn't much. Its actually sorta funny. It varies by 20% faster to 10% slower to 20% faster as the list length changes.
<Nutssh>
Yeah, gotta reverse the list to preserve the semantics of map.
<Maddas>
Hm. Heh.
<Maddas>
Yeah, I didn't look at the particular example
<Maddas>
Isn't there any (efficient) thing that does the :: just the opposite way?
<ayrnieu>
Maddas - eh, think about that.
<Maddas>
ayrnieu: I'm not too good at thinking. :-)
<Maddas>
Let me try, though.
<Maddas>
ayrnieu: Heh, does the answer involve List.append? :)
<ayrnieu>
Maddas - no, you should focus on the relative efficiency of :: and something that does :: 'just the opposite way'
<Maddas>
ayrnieu: Oh. I have no idea about that
<Maddas>
Is appending to a list more costly than adding to the front of it?
<ayrnieu>
Maddas - one of these has O(1) complexity and one of these has O(N) complexity.
<Maddas>
ayrnieu: Oh. That answers my question :-)
<Maddas>
I have no idea how lists are stored/handled internally
<Maddas>
But if it is something like linked lists, I see
<ayrnieu>
Maddas - yes, linked lists.
<Maddas>
ayrnieu: Ok. Then, my question was stupid. I apologise :)
<ayrnieu>
no worries. You surely have had exposure to languages like Python with their 'lists' that they call 'arrays' that they implement as other than linked lists.
<Maddas>
Heh, in fact, no, I just didn't apply enough thinking.
<Maddas>
But if one gave the last element a special status internally and always stored it in an easy-to-access way.. Oh well, I'm sure that wouldn't work out for many reasons :)
<ayrnieu>
indeed. You can define such a structure easily enough, if you really want to.
<Maddas>
ayrnieu: heh. Actually, I think the O'Caml developers know better than me, so I'll trust them that it wouldn't be very useful in the end =)
<Maddas>
s/them/them in/
<Nutssh>
If it was doubly-linked, no problem. You could reverse it in constant time too.
<Maddas>
...doubly linked?
<Maddas>
Oh, having a link to the last element, also across bounds?
<Maddas>
s/last/previous/
<ayrnieu>
Maddas - yes.
<Maddas>
Cool
<ayrnieu>
you can play with such implementations in O'Caml just fine, of course =) You can even get a nice syntax for them through camlp4
<Nutssh>
In this case, a link to the two adjacent nodes. If you look at node Y and you're next to it at node X, node Y has two adjacencies, X and Z. THe one that isn't the node you're on is the next one.
<Nutssh>
How does camlp4 work? THe docs I saw were inscrutible.
maihem has joined #ocaml
buggs|afk has joined #ocaml
Nutssh has quit ["Client exiting"]
buggs has quit [Read error: 110 (Connection timed out)]
gim has quit [Read error: 104 (Connection reset by peer)]
Defcon7 has quit [Read error: 113 (No route to host)]
Defcon7 has joined #ocaml
whiskas has quit ["Leaving"]
gim has joined #ocaml
blueshoe has quit [Read error: 104 (Connection reset by peer)]
mattam_ has joined #ocaml
mattam has quit [Read error: 110 (Connection timed out)]
maihem has quit ["Client exiting"]
mattam_ is now known as mattam
whiskas has joined #ocaml
<whiskas>
It's me again :-)
<Maddas>
He's back! Run while you can!
<whiskas>
Told ya.
<Maddas>
Hi
<Nomme>
hi
wazze has joined #ocaml
blueshoe has joined #ocaml
whiskas has quit [Read error: 104 (Connection reset by peer)]
whiskas has joined #ocaml
blueshoe has quit [Read error: 104 (Connection reset by peer)]
daemon has joined #ocaml
whiskas has quit [Read error: 60 (Operation timed out)]
daemon is now known as whiskas
Nutssh has joined #ocaml
karryall has quit ["."]
housetier has joined #ocaml
blueshoe has joined #ocaml
Melchior has joined #ocaml
<Melchior>
Hello, does anyone know to get the system date with Caml ? (sys__time doesn't fit my purpose)
<Smerdyakov>
Hm. I can't find anything with a quick look at the standard library docs.
Chimp_ has joined #ocaml
<gim_>
with Unix you can
<Melchior>
nor do I !
<gim_>
Unix.gettimeofday
<gim_>
or smthg like that
<Melchior>
right : unix__time
<Melchior>
(Caml Light)
* Smerdyakov
wonders why anyone would want to use Caml Light anymore. :)
<Maddas>
gmtime returns a struct which lets you get the date if you pass it a float (as returned by Unix.time)
* Melchior
uses Caml Light because his teachers ask him to...
<Melchior>
thks everybody !
<Nutssh>
How old is caml light?
<Smerdyakov>
The second most recent release was made in 1997, according to the web page. :)
<Smerdyakov>
And it's .01 version numbers away from the current one, which was in Jan 2003.
<Melchior>
but we french students have to use this wonderful Caml Light...
<Melchior>
it's only good for educational purpose
Melchior has quit []
Chimp_ has quit ["leaving"]
<Nutssh>
Heh. Thanks.
Nomme has quit ["Leaving"]
housetier has quit ["Verlassend"]
Nutssh has left #ocaml []
blueshoe has quit [Read error: 54 (Connection reset by peer)]
jdmarshall has joined #ocaml
blueshoe has joined #ocaml
gim_ has quit [Remote closed the connection]
mimosa has joined #ocaml
mimosa has quit ["J'ai fini"]
jdmarshall has quit [Connection timed out]
blueshoe has quit [Read error: 104 (Connection reset by peer)]