[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Help on Caml

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 1

File: caml_logo_mid.jpg (8KB, 301x156px) Image search: [Google]
caml_logo_mid.jpg
8KB, 301x156px
Got this code :
let abs x =
if x<0 then begin let y=x*(-1);print_int y;end;
else print_int x;;

It gives me syntax error on the "end", what am I doing wrong ?
>>
Stop using begin and end. IIRC parentheses work too.
>>
>>61140968
I am very new in coding, what are thoses parentheses ?
Btw I would appreciate to have a mentor, who will be able to tell me where the error is, so I dont have ton ask on a forum each time
>>
>>61140871
been a while if I've programmed in caml, but you probably want to do something like this
let abs x =
let y = if x < 0 then -x else x in
print_int y


or even this
let abs x =
print_int (if x < 0 then -x else x)
>>
Ok, something else, why EACH TIME I put 2 let in my code, it goes wrong ?
let cpt x y =
(let z=x);
while !z<>y do
print_int (!z);
z:=z+1;
done;;

I'm trying to print all numbers from x to y, but if I want to incr x, I need to put it in a variable (tell me if there is a way for directly edit x, but I dont think so, its just an int, no ?). So I put a "let z=x;" so now I can edit z, which is just like x but as variable. Now the code dont works anymore, it show a syntax error on "done;;". And this happen each time I put 2 let in the same code, why ?
>>
Edited code but still the same problem :
let cpt x y =
let z=ref x;
while !z<>y do
print_int (!z);
z:=z+1;
done;;
>>
>>61143327
For local constants, you must use
let z = x in while ...
.
Thread posts: 7
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.