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/
_fab has quit []
joshcryer has quit [Connection timed out]
joshcryer has joined #ocaml
dark_light has joined #ocaml
khaladan_ has joined #ocaml
mrsolo has quit [Read error: 104 (Connection reset by peer)]
khaladan has quit [Connection timed out]
int80_h has joined #ocaml
<int80_h> hi people :)
<zmdkrbou> yo
descender has quit ["XML is like violence, if it doesn't solve the problem, just use more."]
* dylan mutters "I will do homework, not add list comprehensions to my toy language"
<int80_h> hmm
int80_h has quit ["[BX] Reserve your copy of BitchX-1.0c18 for the Nintendo Gameboy today!"]
slipstream has quit [Read error: 110 (Connection timed out)]
khaladan_ has quit [Read error: 104 (Connection reset by peer)]
slipstream has joined #ocaml
dark_light has quit [Read error: 110 (Connection timed out)]
mikeX has left #ocaml []
Submarine has quit [Connection timed out]
easy4 has joined #ocaml
dark_light has joined #ocaml
dark_light has quit [Connection timed out]
dark_light has joined #ocaml
easy4 has quit [Remote closed the connection]
easy4 has joined #ocaml
Smerdyakov has quit ["Leaving"]
dark_light has quit [Read error: 110 (Connection timed out)]
easy4 has quit [Read error: 110 (Connection timed out)]
dark_light has joined #ocaml
TaXules_ has quit [Read error: 104 (Connection reset by peer)]
TaXules has joined #ocaml
dark_light has quit [Remote closed the connection]
TaXules_ has joined #ocaml
TaXules has quit [Remote closed the connection]
_fab has joined #ocaml
pango is now known as pangoafk
joshcryer has quit [Read error: 104 (Connection reset by peer)]
GCarrier has joined #ocaml
<GCarrier> hi!
<GCarrier> is there a function to check is a character is "downcase", like [a-z] but not [A-Z] please?
<flux__> I don't know, but if you don't care about locales, match 'a' with 'a'..'z' -> true | _ -> false would work
<GCarrier> yep
<GCarrier> thx ;)
m3ga has joined #ocaml
joshcryer has joined #ocaml
GCarrier has quit ["Ex-Chat"]
love-pingoo has joined #ocaml
ppsmimou has quit [niven.freenode.net irc.freenode.net]
ppsmimou has joined #ocaml
Snark has joined #ocaml
m3ga has quit ["disappearing into the sunset"]
pangoafk is now known as pango
TaXules_ is now known as TaXules
Skal has joined #ocaml
descender has joined #ocaml
cmeme has quit [Connection timed out]
cmeme has joined #ocaml
pango is now known as pangoafk
Schmurtz has joined #ocaml
GCarrier has joined #ocaml
Skal has quit [Remote closed the connection]
Schmurtz has quit [Read error: 110 (Connection timed out)]
GCarrier has quit ["Ex-Chat"]
ulfdoz has quit [niven.freenode.net irc.freenode.net]
ulfdoz has joined #ocaml
love-pingoo has quit ["Leaving"]
VB has joined #ocaml
Skal has joined #ocaml
pauldia has joined #ocaml
VB has left #ocaml []
ski has quit [Read error: 110 (Connection timed out)]
ski has joined #ocaml
Smerdyakov has joined #ocaml
GCarrier has joined #ocaml
love-pingoo has joined #ocaml
bluestorm has joined #ocaml
ski has quit [Read error: 110 (Connection timed out)]
GCarrier has quit [Remote closed the connection]
GCarrier has joined #ocaml
<GCarrier> #xorg
<GCarrier> sorry
bluestorm has quit [Remote closed the connection]
ski has joined #ocaml
bluestorm has joined #ocaml
ramkrsna has quit [Connection timed out]
smimou has joined #ocaml
mikeX has joined #ocaml
ski has quit ["later"]
pangoafk is now known as pangoafkafk
pangoafkafk is now known as pangoafk
bluestorm has quit [Read error: 113 (No route to host)]
pangoafk is now known as pango
GCarrier has quit [Read error: 113 (No route to host)]
GCarrier has joined #ocaml
tspier2 has joined #ocaml
<tspier2> Hello
<tspier2> Is everyone busy?
<mikeX> tspier2: just ask
<tspier2> Okay, well I'm gonna try compiling a program I was writing today, and if it doesn't work, I'm gonna try to debug it. If it still doesn't work, would you mind if I gave you a link and asked for help, mikeX?
<mikeX> well there's no need to ask me personally, you can paste the link, so anyone can help you
<tspier2> It might look really bad, because I did just start OCaml about a week ago.
<pango> functions are defined with "let", not "let func"
<pango> "try" is a reserved word
<tspier2> Ah
<mikeX> and there already exists a function named incr, which incements int refecerences
<mikeX> let i = ref 0 in incr i;;
<mikeX> now i is ref 1
<mikeX> (so you might want to choose a more appropriate name)
<tspier2> So if I change "let func" to "let", change "try" to "eval", and change "incr" to "bump_one", do you think it will work?
<mikeX> well you can leave incr as is, but it will hide the previous declaration
<pango> ocaml doesn't allow defining functions the way you tried with "try" (with 3 separate definitions); You need to provide a single definition, handling pattern matching yourself
<tspier2> Will the program evaluate the numbers 0-500, divide each of them with 3, 4, and 5, and then print out the respective message, and loop if the number hasn't reached 500 yet?
<pango> as is, there's still a long way to go
<tspier2> Ah
<tspier2> Should I just dump it, and start new?
<pango> / returns the result of integer division, to check divisibility you must check that modulus (rest) is 0
<tspier2> Oh
<pango> let divisible n k = (n mod k = 0) (or something like that)
<tspier2> So...let divisible n 3 = (n mod 3 = 0)
<tspier2> That would work?
<pango> that would create a function 'divisible', that would check if its first argument is a multiple of 3 if its second argument is 3, or raise a match failure otherwise (= including if the second argument is not 3)
<tspier2> Gah
<pango> you can define a function called, say, divisible3 to check for multiples of 3 (let divisible3 n = (n mod 3 = 0)), but what's wrong with the function I provided ?
<tspier2> Uh
<pango> I don't think ocaml compiler can make n mod 3 much faster than n mod k
<tspier2> So I should just use (let divisible3 n = (n mod 3 = 0)), because it would define the function as divisible 3, and perform the value of n divided by three to see what is left, and to check if it is zero...right?
<pango> no, 'divisible' already does that, and returns a boolean value
<pango> # let divisible n k = (n mod k = 0) ;;
<pango> val divisible : int -> int -> bool = <fun>
<mikeX> tspier2: are you using the toplevel interpreter?
<mikeX> it's ideal for trying things out step by step
<tspier2> Oh, how would I install/use it on Windows? Normally I use Linux for it...
<mikeX> the mingw binary has it as far as I know
<tspier2> Oh
<tspier2> Do you think I can have this done by tomorrow?
<mikeX> what exactly?
<tspier2> I want to make it calculate which numbers between 1 and 500 can be divided by 3, 4, and 5 to get integer values, and not floats. Then later on, I want to add a small function to output it, which I know how to do that.
<pango> there's still some problems with your code; Main one remaining is that you use n as if it was mutable
<pango> but it is not; if you don't use references, you can redefine n, but not modify it
<pango> another lesser problem is that print_endline expects a string; So you either have to write print_endline ((string_of_int n) ^ " is not divisible by 3, 4, or 5.") or Printf.printf "%d is not divisible by 3, 4, or 5.\n" n
<tspier2> Oh
<tspier2> Let me try writing it again...
<pango> btw, there's no "floats" involved. / is "euclidian division", its result is an integer, always
<pango> # 7 / 3 ;;
<pango> - : int = 2
<tspier2> http://pastebin.be/645/ <- Is that a little better?
<pango> you call loop_function before defining it, ocaml does not allow that
<pango> that could be fixed by simultaneous recursive definitions (let rec a ... = ... and b ... = ...)
<tspier2> I just moved loop_function up before number_evaluation.
<tspier2> What else should I change?
<pango> but loop_function uses number_evaluation, so you still have the problem, just somewhere else ;)
<mikeX> i'm not sure if that's what you want to do really
<tspier2> Hmm
<pango> tspier2: "in" at the end of line 1 makes number_of_series a local definition of bump_one; so number_of_series is not defined in the remaining of your program
<tspier2> It looks like it checks if the number can be divided by 3, 4, and 5, and if it is greater than or smaller than zero, it prints the message saying it isn't. Likewise for if it does, but why do you have (n-1), when it should be increasing by one. Example...it should go from 1 to 2, not 2 to 1.
<pango> tspier2: mikeX is checking numbers in reverse order, starting from 500 and back to 1
<tspier2> Oh
<tspier2> So what he put would work?
<pango> tspier2: his program looks correct
<pango> testing numbers in increasing order shouldn't be much more complicated
<tspier2> So I should get rid of "in" from the first line, and insert his code into number_evaluation?
<tspier2> Then it would work?
<pango> ;; should only be used when you're back to "toplevel" (if at all; it can be totally avoided in compiled programs). For example, you shouldn't have ;; at the end of line 8 (before 'else') because current function definition is not finished yet at that point
<mikeX> the program works, I just wasn't sure if that's what you wanted exactly
<tspier2> Oh
<mikeX> tspier2: in http://pastebin.be/647 you have a syntax error at line 7
<mikeX> you need to put ; there
<tspier2> Oh
<tspier2> Hopefully one day I will know as much about OCaml as you guys do...
<tspier2> mikeX, other than that, does it work?
<mikeX> you also have to put lines 9-11 into parentheses or begin .. end
<mikeX> assuming you want them to be executed if number_of_series < 500
<mikeX> otherwise only bump_one number_of_series is executed
<pango> the biggest problem remaining is still that number_of_series handling
<pango> as is, bump_one computes next number, returns it, but it's not used (which should lead to a warning)
<mikeX> yes, it should be let number_of_series = ref 0
<mikeX> tspier2: what are you using to learn ocaml ?
<mikeX> reading actually
<tspier2> ocaml-tutorial.org and the OReilly book
<mikeX> oh, nice :), do you have experience with other programming languages?
<tspier2> Not functional
<tspier2> Mainly Imperative
<tspier2> A little interpreted
<tspier2> And a little scripting
<mikeX> there is an online tutorial for c/c++ and java programmers
<mikeX> which might be a bit easier to read at first
<tspier2> Okay, I will have to look for that.
<tspier2> But other than those last corrections, would it work?
<mikeX> well if you change number_of_series to ref 0, you have to use slightly different syntax for some operations
<tspier2> How so?
<mikeX> fist of all, bump_on is not needed, you can use incr
<tspier2> Should I just keep bump_one to be on the safe side for now at least?
<mikeX> you have to change it to bump_one n = n := !n + 1
<mikeX> or bump_one n = incr n
<pango> I think going for references would be a lost occasion to understand how to write that program in a more functional way
<mikeX> which effectively makes it redundant
<tspier2> Oh
<pango> but well, you can write it both ways and compare
<mikeX> yeap
<tspier2> Alright, I changed it to "incr n"
<mikeX> you also have to become familiar with ;
<tspier2> I know...I'm bad at that.
<tspier2> So if I were to compile that program now, it would work?
<mikeX> gotta go now, bbl
<tspier2> Okay, Bye.
<tspier2> Thanks for the help
<tspier2> pango?
<pango> tspier2: could you apply all changes and paste the current state of your program ? :)
<tspier2> Yep
<pango> ok, the problem is now that number_of_series is a reference, so you need to write !number_of_references to get the integer value it references
<pango> !number_of_series > 500, etc.
<tspier2> Okay, just changed it.
<pango> lines from 13 onward are mikeX's program, so you pasted 2 programs btw
<tspier2> Yeah
<pango> you didn't close parenthesis opened at the end of line 8
<tspier2> I did at 12.
illya23b has quit [Read error: 110 (Connection timed out)]
<pango> mmh well, you did, but at the wrong place :)
<pango> it should be before 'in'
<tspier2> Oh
<pango> function definition stops at that 'in'
<tspier2> Question...could I put this in place of Printf.printf "%4d blah..." and print_endline "Finished" to have it create the files and output the text...let o = open_out "Divisible.txt";;
<tspier2> output_string o n && " is divisible by 3, 4, and 5.\n";;
<tspier2> close_out o;;
<tspier2> Likewise for the not divisible one
<pango> && is a boolean operator
<pango> you can use ^ to catenate strings you want to output
<tspier2> So, I would use ^ in place of the &&, and it would output them?
<pango> or use Printf.fprintf to send formatted output to an open channel
<pango> tspier2: and parenthesis around the (string ^ string), because of priorities
<pango> not to mention replace n with (string_of_int n)... there's *no* implicit conversions in ocaml
<tspier2> Alright, I think I have it now: http://www.pastebin.be/651/
<pango> (testing with compiler) there's still several errors
<pango> first line 2, there's nothing called n, it's number_of_series (or alternatively, use n as function parameter)
<pango> you didn't close parenthesis at the right place, line 10
<pango> if the recursive call line 11 is not conditional, your program will loop forever
<mikeX> you should also open the output channel once, and pass the channel as a parameter to the num_eval function tspier2
<pango> on that same line 11, you're still using ;; in the middle of a function definition
<tspier2> Ahhh
<mikeX> otherwise you have 2 problems:
<mikeX> 1) the file gets overwritten (you can change open_out with something else to avoid that)
<pango> and finally, you're calling number_evaluation, that doesn't exist anymore; only loop_function has been kept
<mikeX> 2) the program is not efficient
<mikeX> or rather, not as efficient
<tspier2> mikeX, how do I make it so it will continue writing in the same file then?
<pango> tspier2: mmh a bug you just added: incr works on references, not ints; So you must pass number_of_series to bump_one, not !number_of_series
<tspier2> Gah. I am so confused. I change the right thing, but change something else with it.
AI_coder has quit [Client Quit]
<pango> you cannot increment zero, but you can increment a 'variable' that contains zero
<pango> does that make sense with this wording ?
<tspier2> Yes
<tspier2> So what should I change?
<pango> bump_one number_of_series... drop the !
<tspier2> Okay
<tspier2> What else?
<pango> mmmh did you move the closing parenthesis ?
<tspier2> So it should be bump_one number_of_series);
<tspier2> ?
<pango> no, just before the 'in'
love-pingoo has quit ["Connection reset by by pear"]
<pango> you could have used begin and end instead of parenthesis if you prefer Pascal look ;)
<tspier2> Okay, so num_eval () ); in
<tspier2> Yeah, I do prefer Pascal.
<tspier2> I used it a lot when I did imp. programming, but I will go all functional for this.
<pango> ok, paste again ?
<mikeX> tspier2: http://pastebin.be/653/
<mikeX> that's my program with file output
<mikeX> i open the files outside of the num_eval function, and pass the channels as arguments
<pango> tspier2: drop everything after line 12, you don't need this other program; Just call loop_function at lines 10 and 11 and you should be done
<tspier2> I want it to be outputted though.
<pango> mikeX: your tests don't seem to match your messages
<mikeX> hmm, let's see, I didn't really check :P
<pango> n mod 3 <> 0 && n mod 4 <> 0 && n mod 5 <> 0 is same as n is not divisible by either 3, 4 or 5
<mikeX> oh yes, I forgot to change that part
<tspier2> So I should paste mikeX's code where num_eval starts?
<pango> tspier2: I think you should first try to get it working without files
<mikeX> indeed
Snark has quit ["Leaving"]
<tspier2> Argh
<dylan> "But everyone wants a computation to wind a piece of monad around"
<tspier2> Gah, I might just call quits for the night. I don't know enough, and I am not only fooling myself thinking I could ever learn OCaml.
<pango> you should take your time, and read tutorials with an interpreter at hand to try things
<mikeX> tspier2: you can install this on windows if you want
<dylan> tspier2: If you immediately know the candle light is fire, then the meal was cooked a long time ago. :)
<tspier2> Why is OCaml so difficult?
<tspier2> People say that it is easy, but I feel like killing myself.
<pango> because you have to unlearn a lot
<tspier2> Maybe I should've just stuck with imperative?
<pango> depends whether you want to learn different ways of thinking about programming or not
<mikeX> tspier2: I found it quite difficult at first
<tspier2> I'm not getting anywhere though, and if I can't do that stupid program, then I can't get extra credit in math, unless I actually write it all out.
<mikeX> I don't think becoming familiar with a different programming paradigm under pressure is a good idea
<mikeX> it's a good thing to have a motivation (a project to work on in ocaml), but not time pressure
<tspier2> I've been looking over those books for two weeks now, and I'm not getting anywhere.
<pango> I think they're two kinds of difficulties there, concepts and syntax
<pango> ocaml syntax can be confusing sometimes, but it 'just' takes time to get used to it
<mikeX> i agree with pango
<mikeX> and I'm relatively new to ocaml, so the experience is still fresh in my mind
<pango> concepts is something different, sometimes hard to 'get' out of a book; did you get any introduction to functional programming ?
<pango> I mean, did they teach something about that paradigm ?
easy4 has joined #ocaml
<tspier2> No
<tspier2> Maybe I'd learn better if I didn't have so much stress, but there is no getting around it.
<pango> so, and no offense intended, I'm not too surprized that you find it difficult. It's not "just a different syntax"
<tspier2> pango: do you think I could learn enough tonight to be able to create that application myself?
<pango> hard to tell... it seems that syntax is slowly getting in... I'm not so sure about fp, maybe that's what you should look at more deeply now
<tspier2> fp?
<tspier2> Oh
<pango> functional programming
<tspier2> functional programming
<pango> right
<tspier2> Why doesn't this work? http://www.pastebin.be/654/
<tspier2> Ah, I found one problem.
<tspier2> I forgot to put n behind the two messages printed.
<pango> Printf.printf mimics C's printf, if you used that
<pango> printf "format" var1 var2 ...
<pango> with format containing jokers where vars value need to be inserted (%d for ints, %s for strings,...)
<tspier2> Well, besides the problem I just pointed out, why won't it work?
<pango> as written, num_eval expects two arguments, n and unit
<pango> and recursive calls only pass unit as argument
<tspier2> I don't know what to change on it.
<pango> (I don't know if I'm good enough to teach someone the basics of functional programming, but let's try...)
pauldia has quit [Read error: 110 (Connection timed out)]
<pango> what would you think if you saw the expression number_of_series = number_of_series - 1 in a mathematic problem ?
<tspier2> I'd think that you are changing the value of number_of_series by using the first value of it minus the one.
<pango> you would probably interpret it as "it has no solutions", because there's no such thing as affectations in maths
<pango> since there would be a different number_of_series *before* and *after* that expression
<pango> adding some notion of time makes things much more complex... "Do we refer to the value before, or value after", etc.
<pango> To keep things simple, you want immutable values
<pango> even if that means creating lots of different variables. For example, number_of_series(t+1) = number_of_series(t) - 1
<pango> (does that look familiar ?)
<tspier2> No, because I don't know where t came from.
<pango> any integer value that will be used to "call" each different value number_of_series can get
Skal has quit [Remote closed the connection]
<pango> I could have used i, if t makes you thing too much about a real value
<tspier2> What is the value of i, t, or whatever it is?
<pango> I'm not sure how it's called in english... (series ?)
<pango> u(0) = 3 and u(i) = 2 * u(i-1) ... etc
<tspier2> Wow, I am so lost.
<tspier2> Should I just read the oreilly book?
<pango> I'm talking plain mathematics so far
<pango> sorry if I don't know the correct english terms, it does help
<tspier2> Yes, but I am only 15, so I can only have Algebra I, and we haven't done that stuff.
<tspier2> How about this...
<tspier2> If I give you an example, can we work through it together?
<pango> I think it's called sequences (http://en.wikipedia.org/wiki/Sequence)
<tspier2> Forget about the whole divisible thing for now, let me give you a new example, so I can see if I understand properly...
<tspier2> Let's say I want the user to enter any values they want. Let's say they gave me, 10, 12, 15, 27, and 59. How would I be able to parse those numbers, so the output would look like this...
<pango> it's better if it doesn't involve inputting or outputting strings, because i/os are basically imperative constructs
<tspier2> 1 | 0 2 5
<tspier2> 2 | 7
<tspier2> 5 | 9
<pango> plain computations may prove easier
<pango> (not to mention I don't understand your example ;) )
<tspier2> You've never done stem and leaf plots?
<pango> again, it's possible that english terms are confusing me
<tspier2> 1 | 0 2 5 = 10, 12, 15
<tspier2> 2 | 7 = 27
<tspier2> 5 | 9 = 59
<pango> ok
smimou has quit ["bli"]
<pango> are input number sorted ? in 10-99 range ?
<pango> (I don't really see how such complex example will ease undertanding)
<tspier2> That is a complex one?
<pango> well, it's definitely more complex than previous one, that was already a problem
<tspier2> Oh
<tspier2> Let me think of an easier one...
<tspier2> You know what Range, Median, Mode, and Mean are, right?
<pango> of a set of "numbers", I suppose
<tspier2> Range is the highest number minus the lowest number. Median is the middle number when they are lined up from smallest to highest. Mode is the number that occurs the most. Mean is the average.
<tspier2> Would this one be easier or harder?
<pango> definitely easier, if you've seen ocaml lists
<tspier2> Do you think this one would be too easy for me, or a good start?
<mikeX> douleuei pango ?
<mikeX> oops, wrong channel
<pango> tspier2: you learned how to use lists in ocaml ?
<mikeX> just split a bunch of windows in irssi and it's confusing me a little bit
<tspier2> ["blah"; "blah"; "blah"]?
<pango> tspier2: yes
<tspier2> Then if you have int and string, it is a tuple?
<pango> lists and tuples are totally different beasts
<tspier2> I know, I'm just saying.
<tspier2> Lol
<tspier2> pango, I don't know where you live, but if I am taking up too much time, or you have to sleep, just tell me.
<pango> well, it's 00:51 here, but I'm not sleepy yet ;)
<mikeX> : )
<mikeX> (again wrong window, dammit)
<pango> lol
<tspier2> Heh
<pango> lists can only contain values of the same type
<tspier2> pango, say we have the list, ["1"; "2"; "3"; "4"; "5"], say I wanted to get the range, would I put List.tl - List.hd?
<pango> no, because the two don't have the same type
<tspier2> Oh, I get it. I can't have quotes, because that makes them strings?
<pango> lists are either empty [], or constructed from a head of type 'a and a queue of type 'a list (= list of values of type 'a)
<tspier2> I should just have [1, 2, 3, 4, 5]?
<tspier2> Gah
<tspier2> I mean ; instead of ,
<pango> so head and queue don't have the same type
<pango> for example [1; 2; 3; 4; 5] = 1 :: [2; 3; 4; 5]
<pango> head is 1, of type int, queue is [2; 3; 4; 5], of type int list
_fab has quit [Read error: 113 (No route to host)]
<pango> [2; 3; 4; 5] = 2 :: [3; 4; 5]
<pango> and so forth, til
<pango> [5] = 5 :: []
khaladan has joined #ocaml
<tspier2> Why can't I use List.tl and List.hd?