dylan changed the topic of #ocaml to: OCaml 3.09.1 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/
<pango> you can, but not just "List.tl - List.hd" as you said
<pango> but you can also avoid using it implicitely, by using ocaml's deconstruction... the syntax is nicer :)
<tspier2> Oh, how would I use it properly though?
<pango> I'll give an example: computing the length of a list
<tspier2> Okay
<pango> # let rec length l =
<pango> match l with
<pango> | [] -> 0
<pango> | h :: q -> 1 + (length q) ;;
<pango> match is used to "compare" l with different values
<pango> first, we check if it's empty. If it is, the result is easy: the length of an empty list is 0
<tspier2> How can q be the length of q plus one?
<pango> you're not reading it correctly
<pango> otherwise, if it's not empty, it's build out of a head an a queue. And then, the length of the list is the length of the queue plus one
<pango> since the queue is shorter than l, sooner or later it will be an empty list, and we will be able to compute the length of the whole list
<tspier2> Oh
<pango> the length function is defined using itself, that's a recursive function
<pango> # length [1; 2; 3; 4; 5] ;;
<pango> - : int = 5
<pango> ok, now let's suppose we want to get the minimum value of a list, using a recursive function...
<pango> we need two things 1. a basic case whose answer is immediate 2. a way to compute the minimum of a list, using h and the minimum of the list q
<pango> a basic case would be a list with a single element (the minimum of the empty list doesn't really make sense)
<tspier2> Hmm
<pango> then if we know h and the minimum of q, we just have to compare the two to get the minimum of the whole list, okay ?
<pango> # let rec min l =
<pango> match l with
<pango> | [] -> failwith "min"
<pango> | [e] -> e
<pango> | h :: q -> let minq = min q in
<pango> if minq < h then minq else h ;;
<tspier2> Is there an "or" statement?
<tspier2> Like &&?
<pango> ||
<tspier2> Okay, thanks.
mecolin has joined #ocaml
mecolin has left #ocaml []
<tspier2> Hey, just a question for you pango...
<pango> yes ?
<tspier2> I'm trying to implement this whole list thing with the if/else/Printf.printf/print_endline statements, so I can learn how to do that one hard problem, so I am working on a prime number one. Can you tell me if it looks fine so far?
<tspier2> let even_array[(2; 4; 6; 8)]
<tspier2> let odd_array[(3; 5; 7; 9)]
<tspier2> let rec eval_num x =
<tspier2> if x / even_array.(0) <> 1 then Printf.printf "%d" ^ " is not a prime number." x
<tspier2> I just started it a minute ago.
<pango> array values are enclosed with [| |] not [( )]
<mikeX> tspier2: if you choose to use printf, there's no need for ^
<pango> let even_array = [| 2; 4; 6; 8 |] ...
<mikeX> Printf.printf "%d is not a prime number." x
<tspier2> Okay
<tspier2> Does it look fine so far though?
<tspier2> Just yes or no
<tspier2> No hints or tips yet...I wanna see if I can do it myself.
<pango> x / k = 1 means x is in k .. 2*k-1 range ... so x / k <> 1 means it's outside that range... I'm not sure what that means in your example
<tspier2> Well, a prime number is a number that cannot be divided by anything except for one, so if x / k <> 1, then it isn't a prime number, because it can be divided by anything else.
<pango> again / is the result of the euclidian division, if you want to test multiplicity the rest may be more useful
<pango> (modulus)
<pango> # 3 / 2 ;;
<pango> - : int = 1
<pango> p is the euclidian division of x by y, if x = py + r, 0 <= r < p
<tspier2> Okay, I'm finished, but I didn't add in the modulus stuff yet.
<tspier2> Would you mind checking it if I give you a link?
<pango> sure
<pango> go ahead
<pango> you can't use local definitions locally... so either get even_array and odd_array out of eval_num definition, or use let ... in ... constructs instead of let
<pango> same with let x, must be let x = ... in
<pango> read_line () returns a string, so there's probably an int_of_string missing
<tspier2> I should have read_int (), shouldn't I?
<pango> syntax of || (and &&) is cond1 || cond2 ... so no need to repeat if's
<pango> mmmh yet read_int should work too
<pango> s/yet/yes/
<tspier2> Alright, let me repost it.
<pango> let read_int () = int_of_string(read_line()) (in pervasives.ml, no less)
<tspier2> Gah
<tspier2> I didn't put that, and I just posted it.
<pango> it's in pervasives.ml, no need to define it
<tspier2> Okay
<tspier2> Check that
<pango> Pervasives is the module that's opened implicitly in all other ocaml modules
<tspier2> How does it look now?
<pango> I'm not too sure of your primaly tests, but at least the syntax is almost correct (';' missing at the end of line 7)
<pango> and 8 too
<tspier2> Before or after the x?
<tspier2> Maybe you could test it then?
<pango> end of line
<pango> mmmh and don't forget the = in the let statements (2 first lines)
<tspier2> Okay
<tspier2> Can you test it for me?
<pango> testing... one more missing ; at the end of line 5...
<pango> and () after let eval_num
<pango> let rec even
<tspier2> Gott...ich bin dummer als ein Stein.
<pango> mmmh had to modify slightly the end... not sure the exact reason so late ;)
<pango> $ ./dump-656
<pango> Enter a Number:
<pango> 5
<pango> 5 is not a prime number.5 is a prime number.Enter a Number:
<pango> lots of numbers are both prime and not prime, I think there's still bugs (but in logic that time ;) )
<tspier2> Gah
<tspier2> I'm stupid.
<pango> x is prime <=> for any k / 2 <= k < x, x mod k <> 0
<pango> and it's not difficult to optimize it to
<pango> x is prime <=> for any k / 2 <= k <= sqrt x, x mod k <> 0 (maybe with some conditions on x)
<tspier2> Oh
<tspier2> Sorry for the late response...trying to help my Dad with a hdd problem.
<tspier2> Hmm
<pango> or if you want to avoid using sqrt, but run a bit slower: http://www.pastebin.be/659/
<pango> mmh my explanation above wasn't too readable, because I used '/' to mean 'like', and not some division :/
<pango> x is prime <=> for any k when 2 <= k <= sqrt x, x mod k <> 0
<pango> one can expand (q = x) || (q > x / q) || (x mod q <> 0) && aux (q+1) using if ... then ... else
<pango> if q =x then true else if q > x / q then true else if x mod q = 0 then false else aux (q+1)
<pango> I won't win any primality test efficiency contest, but it works
easy4 has quit [Read error: 110 (Connection timed out)]
<pango> mmh stem and leaf plot are easier than I thought
<tspier2> Lol
<tspier2> Post it?
easy4 has joined #ocaml
<pango> I'm still writing the code, but I use a hash table for stems
<pango> in the meanwhile, http://www.pastebin.be/660/
<pango> I used some functions of the standard library, so I'm somewhat cheating there too ;)
<tspier2> Okay
<pango> http://www.pastebin.be/661/ (hashtable, again. And output not sorted)
cricket_ has joined #ocaml
<cricket_> any1 alive?
<dylan> bird flu, bird flu!
<cricket_> how do i check if a character = the quote character?
<cricket_> i tried #"""
<cricket_> but obviously thats wrong
<cricket_> i guess there is an escape sequence for quote?
<dylan> '"'
<pango> '\'' ?
HatchBack176 has joined #ocaml
<pango> # Char.code '\'' ;;
<pango> - : int = 39
<cricket_> figured it
<cricket_> thnx
<cricket_> #"\""
<dylan> # stuff looks like SML, not ocaml.
<pango> sorted output => http://www.pastebin.be/662/
<tspier2> Done with it?
<pango> that's how I would have wrote it for my own use
<pango> it should be possible to rewrite it to use only lists
<pango> using an association list instead of a hash table of list references :)
<tspier2> Heh, you used my example as a comment. ;)
<pango> true :)
<pango> and that's what the program outputs
<tspier2> If you change the numbers, it will output diff. though, right?
<tspier2> In the list
<pango> sure, it's not hardcoded ;)
<tspier2> pango, you're my hero. ^_^
<tspier2> So if you put 100 in the list, it will output "10 | 0", right?
<pango> # #use "stem.ml" ;;
<pango> # print_stems (classify [100]) ;;
<pango> 10 | 0
<pango> - : unit = ()
<tspier2> Awesome
khaladan has quit [Read error: 110 (Connection timed out)]
* tspier2 sneaks up behind pango, and steals his knowledge of OCaml for a day. ;)
<pango> one can avoid using references by using Hashtbl.replace... http://www.pastebin.be/663/ not a huge difference in code
cricket__ has joined #ocaml
<cricket__> hey, whats a good way to check if a character is alpha numeric in SML?
<easy4> cricket_: Char.isAlphaNum
<Smerdyakov> Definitely wrong channel for that question.
<Smerdyakov> cricket_, you don't seem ever to have asked a question in #sml, so I don't know why you go on acting like there is no one there who will answer.
slipstream-- has joined #ocaml
cricket_ has quit ["BitchX-1.1-final -- just do it."]
cricket__ has quit ["BitchX-1.1-final -- just do it."]
<tspier2> Smerdyakov: is that username Russian, Polish, or Ukranian?
<Smerdyakov> tspier2, yes, and you have now revealed yourself as a philistine. :P
<tspier2> Huh?
<tspier2> I don't know what that is...but I live in the United States.
<Smerdyakov> Wow. A philistine who doesn't know the word is doubly so. ;)
<Smerdyakov> A philistine is a person who is not familiar with the exciting world of Art, and you are revealed as one because my nick comes from one of the greatest novels ever!
<tspier2> Ah, I'm not really one of those people that takes pride in his/her country. I'm one of those people that plan to leave the country once they graduate High School or College.
<tspier2> Which novel?
<Smerdyakov> The Brothers Karamazov
<mikeX> haven't read that one yet
* Smerdyakov ATTACKS mikeX.
<tspier2> Doestevsky?
<tspier2> Sorry for the spelling
<Smerdyakov> tspier2, yes.
* mikeX should finish crime and punishment first
<tspier2> I read Crime and Punishment.
<mikeX> :P
<tspier2> Good book, btw
<mikeX> where do you plan to go to tspier2 ?
<tspier2> Either Germany or Austria
<tspier2> I study German at school, and I am over 80% German and Austrian.
<mikeX> oh I see
<tspier2> Yep
<Smerdyakov> I hope you don't disagree with the statement that American culture has many awesome elements.
<tspier2> I agree with that, however, I think American culture has more elements of ignorant than those of awesome-ness.
<mikeX> heh
<Smerdyakov> I don't have any plans to live outside the USA.
<tspier2> Smerdyakov, what state?
<Smerdyakov> tspier2, oh, I go where the opportunity is.
<tspier2> What state presently?
<Smerdyakov> California
<tspier2> Lol...I'm all the way to the other side.
<tspier2> Pennsylvania
<tspier2> mikeX, do you live in the U.S.?
<Smerdyakov> I've lived in PA for most of my life. I moved to CA in 2003.
<tspier2> What city in PA?
<Smerdyakov> Allentown for most, and 3 years in Pittsburgh.
<tspier2> Whoa
<joshcryer> There was a guy in here, whip I think his nick was, asking about OCaml compiler documentation, do you guys know of any papers that discuss what makes it so efficient/good?
<tspier2> I live about 20 minutes from Allentown.
<tspier2> I live in Fleetwood.
<dylan> tspier2: You must be Pennsylvania dutch! ;)
<Smerdyakov> joshcryer, it's NOT efficient/good! :D
<joshcryer> Smerdyakov, shut up, the Shootout is infallible!
<Smerdyakov> joshcryer, for that you want MLton, whose web site has some links to academic papers on it.
<dylan> MLton needs to support amd64. :'(
<joshcryer> Smerdyakov, hmm, cool, I'll check it out. I'm really curious about new compiler innovations (despite that I won't understand most of it probably).
<Smerdyakov> joshcryer, tiny single-file benchmarks don't provide much opportunity for optimizing compilers to shine.
slipstream has quit [Read error: 110 (Connection timed out)]
<mikeX> tspier2: no
<mikeX> i live in greece
<tspier2> Whoa
* dylan hums Zorba the Greek.
<mikeX> hahah
<dylan> Smerdyakov: is there any plans for mlton to target amd64?
<tspier2> Just wondering...has anyone here used MLGame? It is a game library for OCaml...sort-of like Allegro for C.
<Smerdyakov> dylan, I don't know.
<dylan> Smerdyakov: Darn.
<dylan> it seems debian/amd64 doesn't have any SML implementations in apt.
<dylan> hmm, except in sid.
<joshcryer> pango, doh!
dark_light has joined #ocaml
<tspier2> Night
tspier2 has quit ["Leaving"]
mikeX has quit ["zzz"]
bzzbzz has joined #ocaml
ramkrsna has joined #ocaml
Banana_ has joined #ocaml
mattam_ has joined #ocaml
mattam has quit [Read error: 104 (Connection reset by peer)]
Banana has quit [Read error: 110 (Connection timed out)]
Smerdyakov has quit ["Leaving"]
love-pingoo has joined #ocaml
dark_light has quit [Remote closed the connection]
Skal has joined #ocaml
<flux__> I found a great reason for the existence of 'let rec'-expression ("Why aren't all functions recursive?").. it helps you track down stack overflows, by spotting the potentially recursive functions ;)
khaladan has joined #ocaml
love-pingoo has quit ["Connection reset by by pear"]
pango is now known as pangoafk
HatchBack176 has quit [Read error: 110 (Connection timed out)]
pauldia has joined #ocaml
pangoafk is now known as pango
joshcryer has quit [Read error: 104 (Connection reset by peer)]
m3ga has joined #ocaml
GCarrier is now known as PierreTramo
love-pingoo has joined #ocaml
VB has joined #ocaml
Yorick has joined #ocaml
<Hadaka> hey, have there been efforts to minimize the size of the bytecode runner and/or bytecode in ocaml?
<Yorick> Hadaka: Not to my knowledge. Are you thinking about using ocaml in an embedded system?
<Hadaka> Yorick: well, kinda
<Hadaka> Yorick: I would probably be doing that minimizing if this thing would become a reality
<Yorick> But you are memory-constrained then?
<Yorick> (I agree this sort of thing is useful)
<Hadaka> Yorick: somewhat, also
<Yorick> I doubt it's easy to shrink the bytecode much (at least not without making it slower), but I could be wrong.
<Yorick> More likely you would be interested in building a smaller runtime, making some parts optional.
<Hadaka> Yorick: I'm not *that* memory constrained - I can store bytecode in a compressed form and just blow it up on loading
<Yorick> Writing a console game? :)
<Hadaka> Yorick: but building a smaller runtime would indeed be important - and also to build a runtime that depends as little on POSIX as possible
joshcryer has joined #ocaml
<Hadaka> Yorick: nah, something to run on phones, wince and the like
<Yorick> I believe Lua is worth looking at, even if just to see what techniques it uses to allow small runtimes.
<Yorick> oh, phones. Damn, then I shouldn't have helped you :)
<Hadaka> Yorick: you think I might be in competition, or? :)
<Yorick> No, I just think it's not a worthwhile cause.
<Hadaka> Yorick: oh, but this is worthwhile.
<Yorick> Games, however, now that is a legitimate use of human creativity and time.
<Hadaka> :)
<Yorick> The world has way too many phones. I'm telling you, civilisation is the other way.
<Hadaka> Hmmh, I should probably incorporate ocaml parts into BatMUD...
m3ga has quit ["disappearing into the sunset"]
ramkrsna has quit [Read error: 110 (Connection timed out)]
ramkrsna has joined #ocaml
<love-pingoo> speaking embedded, I'd love to seea a skillful hacker port OCaml to Palms !
ramkrsna has quit [Read error: 110 (Connection timed out)]
ramkrsna has joined #ocaml
love-pingoo has quit ["Leaving"]
love-pingoo has joined #ocaml
Skal has quit [Remote closed the connection]
PierreTramo has quit [Read error: 113 (No route to host)]
VB has quit ["Kopete 0.11 : http://kopete.kde.org"]
illya23b has joined #ocaml
Smerdyakov has joined #ocaml
slipstream has joined #ocaml
slipstream-- has quit [Connection timed out]
pauldia has quit ["Leaving"]
Yorick has left #ocaml []
love-pingoo has quit ["Leaving"]
slipstream has quit [Read error: 104 (Connection reset by peer)]
slipstream has joined #ocaml
khaladan has quit [Read error: 110 (Connection timed out)]
_fab has joined #ocaml
Skal has joined #ocaml
Schmurtz has joined #ocaml
easy4 has quit []
khaladan has joined #ocaml
easy4 has joined #ocaml
ppsmimou has quit ["Leaving"]
PierreTramo has joined #ocaml
khaladan_ has joined #ocaml
smimou has joined #ocaml
khaladan has quit [Connection timed out]
pango is now known as pangoafk
easy4 has quit []
pangoafk is now known as pango
Snark has joined #ocaml
easy4 has joined #ocaml
tspier2 has joined #ocaml
<tspier2> pango!
<tspier2> How are you?
love-pingoo has joined #ocaml
slipstream-- has joined #ocaml
easy4 has quit [Remote closed the connection]
easy4 has joined #ocaml
easy4 has quit [Remote closed the connection]
easy4 has joined #ocaml
shawn has quit ["This computer has gone to sleep"]
slipstream has quit [Connection timed out]
easy4 has quit [Remote closed the connection]
easy4 has joined #ocaml
Skal has quit [Remote closed the connection]
easy4 has quit [Remote closed the connection]
easy4 has joined #ocaml
slipstream has joined #ocaml
weel has joined #ocaml
easy4 has quit [Remote closed the connection]
easy4 has joined #ocaml
<weel> i have a question about tuareg-mode. i'm working on existing code that has multi-line comments with a star on every line, but that has the (* and the *) on separate lines. when I hit M-q in tuareg-mode, these comments are condensed so that the (* and *) no longer have their own lines. does anyone recall having dealt with this before?
Schmurtz has quit [Read error: 113 (No route to host)]
Snark has quit ["Leaving"]
slipstream-- has quit [Read error: 110 (Connection timed out)]
descender has quit ["XML is like violence, if it doesn't solve the problem, just use more."]
easy4 has quit []
shawn has joined #ocaml
descender has joined #ocaml
slipstream-- has joined #ocaml
Skal has joined #ocaml
slipstream has quit [Read error: 110 (Connection timed out)]
dark_light has joined #ocaml
smimou has quit ["bli"]
love-pingoo has quit ["Connection reset by by pear"]