cymonts has quit [Read error: 113 (No route to host)]
bobov has joined #ocaml
giedi has quit ["unused process"]
gl has joined #ocaml
gene9 has joined #ocaml
gene9 has quit [Client Quit]
bobov has quit [Read error: 104 (Connection reset by peer)]
mrvn has joined #ocaml
gl has quit [Read error: 104 (Connection reset by peer)]
gl has joined #ocaml
mrvn has left #ocaml []
cymonts has joined #ocaml
yangsx has joined #ocaml
yangsx has quit ["Client Exiting"]
cymonts has quit [Read error: 60 (Operation timed out)]
Dalroth has joined #ocaml
JX has joined #ocaml
Dalroth has quit [Remote closed the connection]
<JX>
hello all...
Dalroth has joined #ocaml
<mr_bubbs>
hello
<JX>
I'm quite confused... I'm starting writting some small programs with ocaml... I would like to have qome quick help (if possible)
<JX>
I would like to "construct a variable" in function of a variable... for exemple I want to create a string which contains "hello" if x arg is greater than 10 and "hi" if less...
<mr_bubbs>
a few ways to do that, indeed
<mr_bubbs>
just a sec.. gotta check the oven :)
<JX>
:)
<mr_bubbs>
let f a =
<mr_bubbs>
if a > 10 then
<mr_bubbs>
"yep"
<mr_bubbs>
else "nop" ;;
<mr_bubbs>
print_endline (f 11) ;;
<mr_bubbs>
prints yep and a newline
exarkun has joined #ocaml
<JX>
mr_bubbs: ok thanks! So if I want it to be "embedded into a function"?
<mr_bubbs>
JX: 'tis the idea of functional programming
<JX>
ok
<exarkun>
/4/1
<mr_bubbs>
you could assign it to a variable if you wanted
<JX>
yes thats what I would like to do
<JX>
mr_bubbs: ok thanks I will try with this :)
<mr_bubbs>
here's one crude function using ref
<mr_bubbs>
let f a =
<mr_bubbs>
let str = ref "" in
<mr_bubbs>
if a > 10 then
<mr_bubbs>
str := "greater"
<mr_bubbs>
else
<mr_bubbs>
begin
<mr_bubbs>
str := "lesser"
<mr_bubbs>
end;
<mr_bubbs>
print_endline ("result: " ^ !str) ;;
<mr_bubbs>
f 11 ;;
<mr_bubbs>
prints ``result: greater''
<mr_bubbs>
you can use String too
<JX>
if you want the size of str? (sorry I'm completely newbie)