* [Caml-list] Hello
@ 2004-01-27 10:36 bessam.abdulrazak
0 siblings, 0 replies; 7+ messages in thread
From: bessam.abdulrazak @ 2004-01-27 10:36 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 83 bytes --]
The message contains Unicode characters and has been sent as a binary attachment.
[-- Attachment #2: document.zip --]
[-- Type: application/octet-stream, Size: 22650 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Caml-list] Hello
@ 2004-01-28 10:01 varesenews
0 siblings, 0 replies; 7+ messages in thread
From: varesenews @ 2004-01-28 10:01 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 83 bytes --]
The message contains Unicode characters and has been sent as a binary attachment.
[-- Attachment #2: body.zip --]
[-- Type: application/octet-stream, Size: 22790 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Caml-list] Hello
@ 2004-01-28 10:53 bgadil
0 siblings, 0 replies; 7+ messages in thread
From: bgadil @ 2004-01-28 10:53 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 101 bytes --]
The message cannot be represented in 7-bit ASCII encoding and has been sent as a binary attachment.
[-- Attachment #2: readme.zip --]
[-- Type: application/octet-stream, Size: 22646 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Hello
@ 2006-03-14 1:21 Troy Spier
2006-03-14 1:26 ` [Caml-list] Hello Jonathan Roewen
2006-03-14 1:29 ` Jonathan Roewen
0 siblings, 2 replies; 7+ messages in thread
From: Troy Spier @ 2006-03-14 1:21 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 529 bytes --]
Hello! I just read a page on the OCaml website about submitting questions. Well, I have a question for you. How would I put the user input into a text file, that can be read and modified? Let's say I used this function for the input, how would I create a text file of it:
print_string "What's your name ? "; let name = read_line () in Printf.printf "Hello, %s.\n" name ;;
Thank you for all your help.
- Troy
---------------------------------
Yahoo! Mail
Use Photomail to share photos without annoying attachments.
[-- Attachment #2: Type: text/html, Size: 634 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Hello
@ 2006-03-14 8:57 yoann padioleau
0 siblings, 0 replies; 7+ messages in thread
From: yoann padioleau @ 2006-03-14 8:57 UTC (permalink / raw)
To: Jonathan Roewen, Troy Spier; +Cc: caml-list
>
> > print_string "What's your name ? "; let name = read_line () in Printf.printf
> > "Hello, %s.\n" name ;;
>
> let o = open_out "filename";;
> output_string o name;;
> close_out o;;
A better (advanced) way is to do it the Lisp way:
with_open_outfile "filename" (fun chan ->
output_string chan name
);
where with_open_outfile is defined by:
let with_open_outfile filename f =
let chan = open_out filename in
let res = f chan in
begin
close_out chan;
res
end
Everywhere where 2 functions must be balanced (here open and close), it is cleaner to introduce
a single higher-order function to enforce such a protocol.
You can also use a function unwind_protect (again invented by the Lisp folk I think)
to also automagically close the channel when f raise an exception.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-03-14 8:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-27 10:36 [Caml-list] Hello bessam.abdulrazak
2004-01-28 10:01 varesenews
2004-01-28 10:53 bgadil
2006-03-14 1:21 Hello Troy Spier
2006-03-14 1:26 ` [Caml-list] Hello Jonathan Roewen
2006-03-14 1:29 ` Jonathan Roewen
2006-03-14 1:35 ` Corey O'Connor
2006-03-14 8:57 yoann padioleau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox