<TSC>
Pretty much any introductory computer science book will cover hash tables
<youknow365>
i never used them
<youknow365>
i know what hashes are but hmm lemme do some reading
Schmurtz has joined #ocaml
_jol_ has joined #ocaml
<pango_>
youknow365: so it's not with exceptions that you have a problem, but with pattern matching
_jol_ has quit ["leaving"]
Schmurtz has quit [Read error: 104 (Connection reset by peer)]
Schmurtz has joined #ocaml
Schmurtz is now known as Schmurtz_
Schmurtz_ is now known as Schmurtz
sponge45 has quit ["zzzzzzzz"]
<pango_>
it's not explained in exception's chapter, because it's used in several constructs (match ... with, let, function, try ... with, do I miss any ?) and explained (briefly !) in data types chapter
smimou has joined #ocaml
Schmurtz has quit ["L'énergie semble manquer : dodo !"]
finelemon has joined #ocaml
love-pingoo has joined #ocaml
finelemo1 has quit [Read error: 113 (No route to host)]
_JusSx_ has joined #ocaml
Schmurtz has joined #ocaml
Schmurtz has quit [Read error: 104 (Connection reset by peer)]
<flux__>
well, I didn't realize at first that try.. with was pattern matching
mnemonic has joined #ocaml
Snark has quit [Read error: 110 (Connection timed out)]
Snark has joined #ocaml
kral has joined #ocaml
<WiSmErHi|>
i must play with vector in a fonctionnal algo ( not imperative forms) , can i use pattern matching or i must use recursive function ?
scriptdevil has joined #ocaml
<scriptdevil>
can anyone help me.. i am a newbie and i tried this
<scriptdevil>
what is the error in the if statement?
<scriptdevil>
zmdkrbou: u there?
<scriptdevil>
anyone?
<scriptdevil>
any help?
<scriptdevil>
youknow365 do u know?
scriptdevil has left #ocaml []
scriptdevil has joined #ocaml
<zmdkrbou>
scriptdevil: what does the compiler say ?
<scriptdevil>
it says syntax error in the line where if is there
<scriptdevil>
does it look ok to u zmdkrbou
<scriptdevil>
??
<zmdkrbou>
there are several "if" ...
<scriptdevil>
the first if
marcelino has joined #ocaml
<zmdkrbou>
mmh Printf.printf (bla) if bli then ...
<zmdkrbou>
you have to write either let () = Printf.printf (bla) in if bli ...
<zmdkrbou>
or Printf.printf (bla) ; if bli ...
<scriptdevil>
yeah
<scriptdevil>
line 12
<pango_>
you need "in" after each local declaration
<scriptdevil>
even functions?
<pango_>
functions are no different
<pango_>
they're values too
<scriptdevil>
how do i demarcate a block of code?
<scriptdevil>
ok
<scriptdevil>
ill try
<zmdkrbou>
the only place where you don't have to use "in" is at toplevel
<pango_>
line 15, 23... At that point, you can drop the useless else ()
<zmdkrbou>
if you define something inside another expression, then you have to use "in"
<scriptdevil>
zmdkrbou: i'll see
_jol_ has joined #ocaml
<pango_>
the parenthesis in your ifs are superfluous... So are the one in printf's (I'm even surprized that it does work, but it does)
<scriptdevil>
pango_: i did not use them originally.. i thought not using paranthesis may be the fault.. it turned out that itr wasnt so
<pango_>
I think you miss ;s after printf's however
<zmdkrbou>
moreover, you don't need printf to print plain strings
<pango_>
zmdkrbou: I'm guilty of overusing printf myself ;)
<zmdkrbou>
rhooo :)
<scriptdevil>
hmm.. am i supposed tro make thr function let rec lineCounter i in =
<scriptdevil>
blah balah
<scriptdevil>
sorry for the typos.. new keyboard
<scriptdevil>
pango_: do i make it let rec Funcname Arguments in = or = in?
<pango_>
construct is let [rec] identifier = expression in expression
<pango_>
so the in goes between definition and use
<scriptdevil>
pango looks like i am never using it separately...
<pango_>
scriptdevil: if functions are never called outside their declaration, they'll never be used... I assumed you just pasted part of your code...
<scriptdevil>
ok..
<pango_>
declaring j and k the way you did was useless too... because inside printBlank and printStar, they're shadowed by the respective function arguments of the same name...
<scriptdevil>
pango_: i guess it is a long way to go for functional programming and me.. i wont give up
<pango_>
I'm not sure what's the best way to write your code... I think you should go bottom up
<pango_>
write the small functions to print spaces and stars, test them, then build next functions from them
<scriptdevil>
pango_: one last thing.. how do i use an argument from a value in an outer funtcion
<pango_>
unless they shadowed by another declaration, they're just available
<pango_>
your inequality tests against "i", for example, are ok
<scriptdevil>
ok..
<scriptdevil>
is indentation a problem?
<scriptdevil>
is indentation like in python
<zmdkrbou>
nope
<scriptdevil>
ok
<zmdkrbou>
but a good indentation is *really* useful :)
<zmdkrbou>
for reading
<scriptdevil>
let rec printBlank j =
<scriptdevil>
Printf.printf( " " )
<scriptdevil>
if (j-1 > i) then
<scriptdevil>
printBlank (j-1)
<scriptdevil>
else
<scriptdevil>
now whats wrong?
<zmdkrbou>
printf( " " ) ;
<pango_>
ocaml doesn't care about indentation, but someone wrote some preprocessor so that indentation matters (for the "hard indentation" addicts ;) )
<zmdkrbou>
since indentation doesn't matter, you're writing "printf (bla) if bli then ..."
<scriptdevil>
ok same error after printf " "... compiler is saying syntax error at if..
kral has quit ["Live fast, die young."]
<scriptdevil>
# let rec printBlank j =
<scriptdevil>
Printf.printf " "
<scriptdevil>
if j-1 > i then
<scriptdevil>
printBlank (j-1)
<scriptdevil>
else
<scriptdevil>
();;
<pango_>
scriptdevil: forgot the ; too
<scriptdevil>
Characters 48-50:
<scriptdevil>
if j-1 > i then
<scriptdevil>
^^
<scriptdevil>
;? where?
marcelino has quit ["Ex-Chat"]
<pango_>
scriptdevil: at the end of print's line
<scriptdevil>
ok..
<scriptdevil>
at last its working
descender has quit [Read error: 54 (Connection reset by peer)]
descender has joined #ocaml
<scriptdevil>
hmmm... how did u folks realise a ; was to come after printf?? any general rule for ;
<zmdkrbou>
yes : "don't use it" :p
<pango_>
; is the separator in sequences
<zmdkrbou>
more seriously, ';' is used to separate two "statements", as in C
<scriptdevil>
ok.... so if i use 2 different if then else conditions one after another, do i put a ; after the first else clause?
<zmdkrbou>
no
<pango_>
since all but the last expression's value is kept, previous statements must return unit, and be used for their side-effects; So ';' is associated with imperative programming
<zmdkrbou>
when you write "a ; b ; c", a and b should have type unit
<zmdkrbou>
and the value for "a ; b ; c" is c
<scriptdevil>
ok...
<scriptdevil>
thats neat
_jol_ has quit ["leaving"]
<pango_>
scriptdevil: problem with your code is that defining a function doesn't evaluate it
<pango_>
scriptdevil: so instead of let i = 0 in let rec lineCounter i = ..., you want something like let rec lineCounter i = ... in lineCounter 2
<pango_>
sorry, let rec lineCounter i = ... in lineCounter 0
datrus has joined #ocaml
<datrus>
anyone knows if there is a print function that takes a value of any type and prints it for debugging?
<flux__>
datrus, check out caml humps
<datrus>
ok
<flux__>
I think there's a library that might approximate that
<flux__>
by using the tag info
<flux__>
realistically that's not an easy task to accomplish in ocaml, because the type information is really not in there during runtime
Smerdyakov has joined #ocaml
<datrus>
the type information must be there during runtime no? otherwhise how would pattern matching work
<pango_>
datrus: it's all done at compile time
<datrus>
but i suppose not everything can be done at compile time. in the case of pattern matching it's probably not even decidable
<flux__>
datrus, something match a with A -> .. | B i -> .. | C -> .. is compiled into something match tag(a) with 0 -> .. | 1 -> .. | 2 -> ..
<flux__>
well, that's actually not the kind of tag I referred to earlier
<pango_>
program is statically checked at compile time, so type is known. No need to check it again at run time
<Smerdyakov>
datrus, pattern matching is statically typed like everything else, and (as it seems you haven't learned yet) patterns fall into a very restricted syntactic class.
<flux__>
given a value, at run time it is impossible to inspect its type, even if you had the whole memory dump of the program
<pango_>
s/checked/typed/ (oops!)
<datrus>
ok
<pango_>
datrus: gcaml can do pattern matching on types, but not ocaml
<flux__>
gcaml is seriously cool, too bad it doesn't appear to be worked on
<pango_>
flux__: it's in official ocaml cvs repository