Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #29389

Re: Which input to use?

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Which input to use?
Date 2014-04-07 17:45 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2014Apr7.194501@mips.complang.tuwien.ac.at> (permalink)
References <lhrndd$2pa$1@speranza.aioe.org>

Show all headers | View raw


Lauri Alanko <la@iki.fi> writes:
>Hello.
>
>I'm a bit confused by the design of Forth's input system. If I read
>the Forth 2012 draft correctly, we have the following:
>
>* The user input device. This is just some system-dependent input
>source that is read with KEY and ACCEPT.
>
>* Files. These are read with READ-FILE and READ-LINE.
>
>* The input source. This is used by parsing words during
>interpretation. The input source is accessed through the input buffer
>with SOURCE, >IN and REFILL.
>
>This all seems terribly complicated from the programmer's point of
>view. What if I just want to write general-purpose text processing
>code that can be used with arbitrary inputs? Now it seems I have to
>write a separate abstraction layer to deal with the above cases.
...
>Funnily enough, there is one abstraction layer already in place: the
>input source, which can be set to read either from the user input
>device (with QUIT) or from a file (with INCLUDE-FILE). It even has a
>number of useful parsing primitives available already.
>
>But unfortunately it seems that there is no way to change the input
>source without starting to interpret it immediately. So it seems that
>the input source cannot be used as an input abstraction layer if we
>are reading data that isn't structured as Forth words.
>
>Have I understood the situation correctly? Is there some reason for
>these limitations?

You have understood it correctly, as far as the standard is concerned.
As for the reason: I think there are too few people on the standards
committee who are interested in text processing.  Admittedly I have
not tried much in that direction, but even EXECUTE-PARSING, which
would be useful beyond text processing, has been met with resistance.

So I recommend Gforth for this kind of application; it was written
with that stuff in mind, and has been used for that stuff, and it
contains the features you are missing:

* You can use KEY on any file with INFILE-EXECUTE
  <http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Redirection.html>.

* You can use file words like READ-FILE or READ-LINE on standard input
  with STDIN
  <http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/General-files.html>.

* And you can use any file as input source with EXECUTE-PARSING-FILE
  <https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/The-Input-Stream.html>

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2013: http://www.euroforth.org/ef13/

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Which input to use? Lauri Alanko <la@iki.fi> - 2014-04-06 14:13 +0000
  Re: Which input to use? mhx@iae.nl - 2014-04-06 07:59 -0700
    Re: Which input to use? "Elizabeth D. Rather" <erather@forth.com> - 2014-04-06 08:26 -1000
      Re: Which input to use? hughaguilar96@yahoo.com - 2014-04-19 19:48 -0700
        Re: Which input to use? "Alex McDonald" <blog@rivadpm.com> - 2014-04-21 02:09 +0100
          Re: Which input to use? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-04-21 04:01 -0400
  Re: Which input to use? hughaguilar96@yahoo.com - 2014-04-06 23:16 -0700
  Re: Which input to use? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-04-07 10:44 +0000
  Re: Which input to use? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-07 17:45 +0000
    Re: Which input to use? mhx@iae.nl - 2014-04-07 12:09 -0700
      Re: Which input to use? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-08 16:11 +0000
        Re: Which input to use? mhx@iae.nl - 2014-04-08 13:05 -0700
    Re: Which input to use? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-04-08 03:18 -0500
      Re: Which input to use? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-04-08 10:49 +0000
        Re: Which input to use? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-09 16:07 +0000
          Re: Which input to use? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-04-10 01:36 +0000
            Re: Which input to use? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-11 17:59 +0000
      Re: Which input to use? "Alex McDonald" <blog@rivadpm.com> - 2014-04-08 12:28 +0100
      Re: Which input to use? hughaguilar96@yahoo.com - 2014-04-08 21:03 -0700
        Re: Which input to use? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-04-09 03:14 -0500
      EXECUTE-PARSING (was: Which input to use?) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-09 15:13 +0000
        Re: EXECUTE-PARSING (was: Which input to use?) Bernd Paysan <bernd.paysan@gmx.de> - 2014-04-09 18:54 +0200
          Re: EXECUTE-PARSING (was: Which input to use?) Alexander Skobelev <al.skobelev@gmail.com> - 2014-04-09 22:44 -0700

csiph-web