Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Christophe TROESTLER <debian00@tiscali.be>
To: "O'Caml Mailing List" <caml-list@inria.fr>
Subject: [Caml-list] Scanf and objects
Date: Wed, 21 May 2003 18:48:12 +0200 (CEST)	[thread overview]
Message-ID: <20030521.184812.24056832.debian00@tiscali.be> (raw)

Hi,

I am trying to understand how Scanf works and have some questions.
The comment preceding the definition of [kscanf ib ef fmt f] says

   If the entire scanning succeeds [...] the tokens are applied to [f].

But are they not applied before?  Consider

        Objective Caml version 3.06+33 (2003-05-19)

  let f i = print_string "Hello"; print_newline(); fun j k  -> i+j+k in
  let buf = Scanf.Scanning.from_string "3 4 x" in
    Scanf.bscanf buf "%i %i %i" f;;  
  Hello
  Exception:
  Scanf.Scan_failure "scanf: bad input at char number 5: int_of_string".

The scanning has not succeeded, however the side effect took place.
What am I misunderstanding here?  As far as I get it, the first argument
is applied when the scanning of the second succeeds since it gives
[stack (stack f i) j] and the argument [stack f i] will be computed.
If arguments are applied to [f] before the scanning is complete, then
what is the purpose of [stack], why not apply them directly instead of
waiting for the next token ?

Now, is it possible to build objects through a format process?  More
precisely, I'd like to have a function that takes (something like) a
format string, say "%i %f", and creates an object like

  object
    method fold : ('a -> int -> float -> 'a) -> 'a -> 'a
  end

It does not look so easy to me since on one hand you would have to
parametrize the object to be able to build its type incrementally
(e.g. with a (int -> float -> 'a, 'a) type) but that would then forbid
the fold method to be fully polymorphic (not really nice...).  Is this
correct?  Are there workarounds?

Thanks for comments,
ChriS

-------------------
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-05-21 16:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-21 16:48 Christophe TROESTLER [this message]
2003-05-21 18:42 ` Damien

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=20030521.184812.24056832.debian00@tiscali.be \
    --to=debian00@tiscali.be \
    --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