Oz and Mozart Users Mailing List

Re: "Read" procedure?


From: Denys Duchier (duchier@ps.uni-sb.de)
Date: Sat Sep 27 2003 - 14:19:42 CEST


grzegorz@pithekos.net (Grzegorz Chrupa³a) writes:

> I have been searching the documentation for a procedure analogous to
> Lisp/Scheme's read or Prolog's read/read_term but haven't found anything
> similar (that may be because I don't know my way about the docs well yet).
>
> I wanted a procedure that would let me sequentially read-in expressions
> from a an input stream. Is there an easy way of doing it in Oz?

Several ways.

- I assume you know about the Open module for IO, so I'll let you
  figure the IO part for yourself if it's needed :-)

- {Compiler.virtualStringToValue +VS ?X}
  takes a virtual string as input (arg 1) and returns the
  corresponding Oz value as output (arg 2). Example:

  {Inspect {Compiler.virtualStringToValue "foo(a b:c)"}}

- more generally you can instantiate a compiler engine and use it to
  perform this job. That's somewhat advanced :-)

- The most general way is to define your own parser using Gump, see
  the documentation:

        http://www.mozart-oz.org/documentation/gump/index.html

  This way you can implement a parser for the concrete language that
  suits your needs best.

- if your target application is for reading persistent data, then you
  should consider using pickling instead. Example:

        {Save foo(a b:c) '/tmp/PickledData'}
        {Inspect {Load '/tmp/PickledData'}}

  This is a lot simpler and MUCH more efficient.

Cheers,

-- 
Dr. Denys Duchier
Équipe Calligramme
LORIA, Nancy, FRANCE
-
Please send submissions to users@mozart-oz.org
and administriva mail to users-request@mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.
Please send bug reports to bugs@mozart-oz.org.



This archive was generated by hypermail 2b29.