<Myoma>
x is the parsed thing, and y is everything after it (in this case nil)
<palomer>
Sym ("foo") ?
<palomer>
(is the result) ?
<Myoma>
"Sym ("foo") ?"?
<Myoma>
no
<Myoma>
run ti if you like, it should give the cons tree
<Myoma>
the tokens are (foo(())bar)
<palomer>
that's...mind boggling
<Myoma>
the cons sould be like Cons(Symbol("foo"),...)
<palomer>
the tokenizing is about 10 lines though
<palomer>
so the total is 18 lines
<Myoma>
Like I said earlier, you should use camllex
<palomer>
but we want to minimize dependencies!
<palomer>
and doesn't using camllex involve running an external program?
<Myoma>
yes, the ocaml compiler
<palomer>
I have to run ocamllex too
<Myoma>
oh boo hoo
seafood_ has quit [Connection timed out]
<palomer>
man, that program boggles my mind
<palomer>
did you just pick that off the top of your head?
<Myoma>
well I am glad of that ;0
<Myoma>
:) *
<palomer>
I couldn't imagine that people actually wrote code like that
<palomer>
do you often pass continuations?
<palomer>
doesn't it make the code hard to read?
<Myoma>
I think the continuation passing method is simpler than the one you pasted -- That's just my opinion of course
<palomer>
it IS simpler
<palomer>
but it's written in a way which I'm not used to
<palomer>
I mean, I read about CPS in my textbooks
<palomer>
but I wasn't aware that people actually used it!
seafood__ has quit [Connection timed out]
seafood has quit [Read error: 110 (Connection timed out)]
seafood has joined #ocaml
filp has joined #ocaml
<palomer>
whoa
<palomer>
my version doesn't even work!
<Myoma>
Is it pointless for me to suggest using camllex again? :)
<palomer>
:P
<palomer>
it would come out to more code in the end
<palomer>
I'd use it if I could use it elsewhere
seafood_ has joined #ocaml
ozy` has quit ["Shop for a whopper"]
seafood___ has quit [Read error: 110 (Connection timed out)]
<Myoma>
You shouldn't be worried about "more code" but "correct code"
seafood_ has quit [Read error: 104 (Connection reset by peer)]
seafood_ has joined #ocaml
Jedai has quit [Read error: 110 (Connection timed out)]
pattern has joined #ocaml
seafood_ has quit [Read error: 104 (Connection reset by peer)]
Jedai has joined #ocaml
seafood_ has joined #ocaml
seafood has quit [Read error: 110 (Connection timed out)]
<palomer>
I can't get my head around your code
<palomer>
how could it possibly work?
<Myoma>
I think the key to understand it is use a high level understanding
<Myoma>
when you write a recursive program, you don't consider how the execution works, You write base cases, and then you take as an axiom that the function works when you write the recursive cases. Do you know what I mean?
<palomer>
yeah
<Myoma>
(It's not relevant that this is a recursive function, I am just describing a thought process)
<Myoma>
so we can use a similar understanding here,
<palomer>
that's what I usually do
<Myoma>
| (Sym ss::xs) -> k (Symbol ss) xs
<Myoma>
| (LPar::RPar::xs) -> k Nil xs
<Myoma>
are base cases
<Myoma>
they tell 1) ocaml what the type of 'k' is
<Myoma>
2) us what the semantic meaning of 'k' is
<Myoma>
so k : sexp -> tok list -> 'z
<flux>
btw, it seems to me myoma could easily write a short article (blog entry) about this subject and perhaps help people on their way ;)
<Myoma>
the k continuation takes the parsed object and all the garbage left over from parsing
<palomer>
and combines them?
<Myoma>
k could do anything it wants really
<Myoma>
but now you can look at the subexpression: parse (fun hd ys -> ...) xs
<flux>
I recently wrote a non-tokenizing parser for s-expressions in c++, it was quite a bit longer ;-)
<Myoma>
'hd' is Symbol ss or Nil or some parsed sexp, ys is the rest of the tokens
ulfdoz_ has joined #ocaml
<palomer>
really?
<palomer>
how come?
<Myoma>
flux, hm good idea
ulfdoz has quit [Remote closed the connection]
<palomer>
whoa, it's getting mega late
<palomer>
and im getting sleepy
<palomer>
I'd love to read the article when you wrote it!
* palomer
is off for the night
<Myoma>
:)
Jedai has quit [Read error: 110 (Connection timed out)]
Jedai has joined #ocaml
seafood_ has quit [Read error: 60 (Operation timed out)]
OChameau has joined #ocaml
seafood has joined #ocaml
Asmadeus has joined #ocaml
marmotine has joined #ocaml
maattd has joined #ocaml
Snark_ has joined #ocaml
seafood has quit [Read error: 60 (Operation timed out)]
Asmadeus has quit ["cya !"]
mfp has quit [Read error: 110 (Connection timed out)]
mfp has joined #ocaml
Proteus has joined #ocaml
Asmadeus has joined #ocaml
Ched- has joined #ocaml
hkBst has joined #ocaml
Asmadeus has quit ["cya !"]
struktured_ has quit [Read error: 110 (Connection timed out)]
munga has joined #ocaml
acatout has quit [Read error: 104 (Connection reset by peer)]
acatout has joined #ocaml
Snark_ is now known as Snark
bluestorm has joined #ocaml
bluestorm has quit [Client Quit]
filp has quit ["Bye"]
Jedai has quit [Read error: 110 (Connection timed out)]
Jedai has joined #ocaml
threeve_ has joined #ocaml
filp has joined #ocaml
Proteus has quit [No route to host]
Associat0r has joined #ocaml
Proteus has joined #ocaml
mishok13 has quit [Read error: 60 (Operation timed out)]
Proteus has quit [Read error: 113 (No route to host)]
Asmadeus has joined #ocaml
<Smerdyakov>
Interesting. I got a recruiting e-mail for a quantitative finance operation that mentions Haskell early on the list of good technologies to know.
<Smerdyakov>
One wonders if that's just a trick to snag good programmers.
pango_ has quit [Remote closed the connection]
pango_ has joined #ocaml
Proteus has joined #ocaml
filp has quit ["Bye"]
ecc has joined #ocaml
Proteus has quit [Read error: 113 (No route to host)]
mbishop has quit [Read error: 113 (No route to host)]
bluestorm has joined #ocaml
Linktim has joined #ocaml
Proteus has joined #ocaml
Proteus_ has joined #ocaml
Proteus has quit [Read error: 104 (Connection reset by peer)]
maattd has quit [Remote closed the connection]
Linktim has quit ["Quitte"]
filp has joined #ocaml
Amorphous has quit [Read error: 110 (Connection timed out)]
Amorphous has joined #ocaml
Proteus__ has joined #ocaml
ecc has quit [Read error: 113 (No route to host)]
Proteus has joined #ocaml
Proteus_ has quit [Read error: 113 (No route to host)]
Linktim has joined #ocaml
Asmadeus has quit [Read error: 54 (Connection reset by peer)]
jlouis has joined #ocaml
Proteus__ has quit [Read error: 113 (No route to host)]
OChameau has quit ["Leaving"]
itewsh has joined #ocaml
tvn1981a has joined #ocaml
<tvn1981a>
can I create something like enum type in ocaml ? e.g., [WIN=1, LOSE = 2, TIE = 0] ?
<Myoma>
No
<Myoma>
you write, let win = 1 in ocaml
<Myoma>
or you cal define type conclusion = Win | Lose | Tie
<bluestorm>
with a let int_of_result = function TIE -> 0 | WIN -> 1 | LOSE -> 2
<tvn1981a>
nice - thanks
wlmttobks has quit ["Leaving"]
wlmttobks has joined #ocaml
<tvn1981a>
if I have 2 classes c1 and c2 all inherit from class c0. I can do something like let myclass = if true then new c1 else then new c2 in ... now I would like to intialize the variable myclass ? e.g., let myclass = ref Something ; if true then myClass := new c1 ... <- these syntax aren't right - what are the right ones ?
<flux>
you could use either let myclass = ref None and later reset it to Some (new ..), or perhaps you can do let myclass = ref (new dummy_class) where dummy_class has only dummy methods
mbishop has joined #ocaml
Linktim has quit ["Quitte"]
Proteus_ has joined #ocaml
tomh_-_ has joined #ocaml
<palomer>
Myoma, did you write an article based on that cool program?
<Myoma>
palomer: No, another example of the same thing came to mind though
<palomer>
what is it?
<Myoma>
it sort of a silly example in ocaml, it makes sense in a pure functional setting though
<Myoma>
in ocaml you could just close over some mutable cells, but anyway a tuple was used for returning two values, since it was recursive the tuple is created and destroyed lots of times. looking at it in terms of continuation (of the tuple constructor) you can do away with that
Proteus has quit [Read error: 113 (No route to host)]
itewsh has quit [Read error: 113 (No route to host)]
thelema has quit [Read error: 110 (Connection timed out)]
Proteus__ has joined #ocaml
Proteus has joined #ocaml
Proteus_ has quit [Read error: 113 (No route to host)]
filp has quit ["Bye"]
itewsh has joined #ocaml
Jedai has quit [Connection timed out]
Jedai has joined #ocaml
ygrek has joined #ocaml
Proteus__ has quit [No route to host]
Snark has quit ["Ex-Chat"]
longh has joined #ocaml
smimou has quit [Remote closed the connection]
Proteus has quit [No route to host]
Linktim has joined #ocaml
ary1 has joined #ocaml
Linktim has quit ["Quitte"]
<bluestorm>
tvn1981a: if you're new to OCaml, you should stay away from object oriented programming at first
<bluestorm>
it's non-trivial and might give you bad ocaml habits
<bluestorm>
the natural way is to use functional programming, not the old OOP you know
<tvn1981a>
I have to learn this program which is written in ocaml
<tvn1981a>
it contains some oop
smimou has joined #ocaml
Proteus has joined #ocaml
bluestorm has quit [Remote closed the connection]
ary1 has left #ocaml []
sporkmonger has quit []
marmotine has quit ["mv marmotine Laurie"]
tvn1981a has quit ["ChatZilla 0.9.83 [Firefox 3.0.1/2008070206]"]
jeddhaberstro has joined #ocaml
longh has quit [Read error: 104 (Connection reset by peer)]
ygrek has quit [Remote closed the connection]
threeve_ has quit []
itewsh has quit ["KTHXBYE"]
Jedai has quit [Connection timed out]
Jedai has joined #ocaml
hkBst has quit [Read error: 104 (Connection reset by peer)]
rby has quit [Read error: 54 (Connection reset by peer)]
Jedai has quit [Read error: 60 (Operation timed out)]
Jedai has joined #ocaml
jlouis has quit ["Leaving"]
Proteus_ has joined #ocaml
rby has joined #ocaml
Proteus has quit [Read error: 104 (Connection reset by peer)]
mbishop_ has joined #ocaml
pango_ has quit [Remote closed the connection]
mbishop has quit [Read error: 110 (Connection timed out)]
Proteus_ has quit [Read error: 113 (No route to host)]