caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Remi Vanicat <remi.vanicat@laposte.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] stream conversion
Date: Tue, 09 Dec 2003 13:08:13 +0100	[thread overview]
Message-ID: <87brqi8a8i.dlv@wanadoo.fr> (raw)
In-Reply-To: <2111F26F-2A1D-11D8-8637-000393CB0F1E@spy.net> (Dustin Sallings's message of "Mon, 8 Dec 2003 23:56:00 -0800")

Dustin Sallings <dustin@spy.net> writes:

> 	I have a need to convert a ``string stream'' to a ``char
> stream.''  It's a little unclear to me how I'd accomplish this.  This
> is the best I've been able to come up with so far, but I have to
> imagine there's a prettier solution:
>
> let stream_convert source =
>      let chunk = ref (Stream.of_string (Stream.next source)) in
>      Stream.from (fun x ->
>          try
>              Stream.empty !chunk;
>              try
>                  Stream.empty source;
>                  None
>              with Stream.Failure ->
>                  chunk := (Stream.of_string (Stream.next source));
>                  Some (Stream.next !chunk)
>          with Stream.Failure ->
>              Some (Stream.next !chunk)
>      )
> ;;
>
> 	Any suggestions?

why do you use Stream.empty ? it would be more natural to use only
Stream.next. As in :
let stream_convert source =
  let chunk = ref (Stream.of_string (Stream.next source)) in
  Stream.from (fun x ->
    try 
      Some (Stream.next !chunk)
    with
      Stream.Failure ->
       (* code needed when the chunk is empty *)
    )


By the way, your code make the assumption that no string in the source
stream are empty (look at what would happen in such case).


-- 
Rémi Vanicat

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2003-12-09 12:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-09  7:56 Dustin Sallings
2003-12-09 12:08 ` Remi Vanicat [this message]
2003-12-09 16:58   ` Jean-Baptiste Rouquier
2003-12-09 17:25     ` brogoff
2003-12-09 17:40       ` Jean-Baptiste Rouquier
2003-12-09 18:30       ` Tim Freeman
2003-12-16 22:42         ` Damien Doligez
2003-12-09 19:13     ` Dustin Sallings
2003-12-09 19:15   ` Dustin Sallings
2003-12-10  1:09 ` Nicolas Cannasse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87brqi8a8i.dlv@wanadoo.fr \
    --to=remi.vanicat@laposte.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).