* how to print (or cast) an integer
@ 2008-08-06 14:08 Ben Aurel
2008-08-06 14:13 ` [Caml-list] " Andrew Gacek
2008-08-06 14:38 ` Ashish Agarwal
0 siblings, 2 replies; 4+ messages in thread
From: Ben Aurel @ 2008-08-06 14:08 UTC (permalink / raw)
To: caml-list
hi
again a noob question
--
1 let x = 1 and y = 2;;
2
3 x + y ;;
--
how can I print the result on line 3? Printf.printf? I can't find a
solution based on the docu
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html
thanks
ben
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] how to print (or cast) an integer
2008-08-06 14:08 how to print (or cast) an integer Ben Aurel
@ 2008-08-06 14:13 ` Andrew Gacek
2008-08-06 14:38 ` Ashish Agarwal
1 sibling, 0 replies; 4+ messages in thread
From: Andrew Gacek @ 2008-08-06 14:13 UTC (permalink / raw)
To: Ben Aurel; +Cc: caml-list
You can do
print_int (x+y) ;;
or
Printf.printf "%d" (x+y) ;;
-Andrew
On Wed, Aug 6, 2008 at 9:08 AM, Ben Aurel <ben.aurel@gmail.com> wrote:
> hi
>
> again a noob question
>
> --
> 1 let x = 1 and y = 2;;
> 2
> 3 x + y ;;
> --
>
> how can I print the result on line 3? Printf.printf? I can't find a
> solution based on the docu
> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html
>
> thanks
> ben
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] how to print (or cast) an integer
2008-08-06 14:08 how to print (or cast) an integer Ben Aurel
2008-08-06 14:13 ` [Caml-list] " Andrew Gacek
@ 2008-08-06 14:38 ` Ashish Agarwal
2008-08-06 18:34 ` David Allsopp
1 sibling, 1 reply; 4+ messages in thread
From: Ashish Agarwal @ 2008-08-06 14:38 UTC (permalink / raw)
To: Ben Aurel; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 827 bytes --]
Also note you do not need "and". That is only required when the variables
being defined are mutually recursive. It would be better style to write:
let x = 1;;
let y = 2;;
On Wed, Aug 6, 2008 at 10:08 AM, Ben Aurel <ben.aurel@gmail.com> wrote:
> hi
>
> again a noob question
>
> --
> 1 let x = 1 and y = 2;;
> 2
> 3 x + y ;;
> --
>
> how can I print the result on line 3? Printf.printf? I can't find a
> solution based on the docu
> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html
>
> thanks
> ben
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
[-- Attachment #2: Type: text/html, Size: 1588 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [Caml-list] how to print (or cast) an integer
2008-08-06 14:38 ` Ashish Agarwal
@ 2008-08-06 18:34 ` David Allsopp
0 siblings, 0 replies; 4+ messages in thread
From: David Allsopp @ 2008-08-06 18:34 UTC (permalink / raw)
To: 'Ashish Agarwal', 'Ben Aurel'; +Cc: caml-list
> Also note you do not need "and". That is only required when the variables
> being defined are mutually recursive. It would be better style to write:
>
> let x = 1;;
> let y = 2;;
The style aspect of your comment is a definite matter of opinion![*]
Given that this is a beginner question, it's probably worth clarifying that
in the context of "let .. and .. ;;" or "let .. and .. in ..;;" the "and" is
a shorthand allowing you to group multiple lets together without introducing
a new environment.
"and" only provides mutually recursive definitions in a "let rec" statement.
David
[*] I personally find it neater to group a series of definitions at the same
level using "let .. and .. in" and only use let again for nested definitions
but that's because I indent code after an "in" but I think that my indenting
scheme is somewhat less common...
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-08-06 18:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-06 14:08 how to print (or cast) an integer Ben Aurel
2008-08-06 14:13 ` [Caml-list] " Andrew Gacek
2008-08-06 14:38 ` Ashish Agarwal
2008-08-06 18:34 ` David Allsopp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox