[comp.lang.forth] Input Stream

ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/27/90)

Category 3,  Topic 45
Message 1         Sun Aug 26, 1990
R.BERKEY [Robert]            at 19:30 PDT
 
 
 Subject: Re: Factoring of CREATE

Doug Phillips writes <24 Aug 90, in comp.lang.forth>:

   > > From where we stand today, the QUOTE-TO solution as given by
   > > Robert Berkey is probably the best way out of the jam.  QUOTE-TO
   > > allows you pass a stack string to an existing defining word,
   > > e.g.,

   > >   " FOOBAR"  ' CREATE  QUOTE-TO

   > Boy, that sounds really familiar.  Was it written up anywhere (FD,
   > etc?)?


QUOTE-TO.SCR is a Forth-83 Standard Program available on GEnie and BCFB.  It
was written in part as an exercise in writing a Standard Program, as well as
for the perennial question concerning the code that passes <name>s to defining
words.  QUOTE-TO.SCR includes the word "> ("quote-to"), which is a one-word
syntax, and there is also a two-word syntax such as Mitch has shown.

The word "> is state-smart:

   " NEW-NAME"   "> CREATE

  or

   : "CREATE   ( <name>   \ addr len -- )
      "> CREATE ;

   " NEW-NAME" "CREATE

The alternate two-word syntax is easier to implement.  QUOTE-TO.SCR shows it
with the word <NAME> .

  Interpretively:

   " NEW-NAME"   ' CREATE <NAME>

  In a colon definition:

   : "CREATE   ( <name>   \ addr len -- )
      ['] CREATE <NAME>   ;

   " NEW-NAME" "CREATE



   > [The obvious question:  Can QUOTE-TO be done in
   > BASIS/dpANS-Forth?]

<NAME> (or QUOTE-TO ) should be easier in BASIS than Forth-83 as the string
need not be moved into TIB .  This eliminates the three string moves needed in
Forth-83, i.e., (1) saving TIB , (2) loading TIB , and (3) restoring TIB .

However, it's not clear on how to set >IN in BASIS.  "Input stream" remains on
the burning issues list.

   : <NAME>   ( addr len token -- )
      BLK @ >R   >IN @ >R   #TIB @ >R   SOURCE-FILE @ >R   \ save-it
      ROT ROT   ( token addr len)
      0 BLK !                                     \ prepare BLK
      0 SOURCE-FILE !                             \ prepare SOURCE-FILE
      TIB ROT - DUP >IN !   ( token len tib-addr) \ prepare >IN
      + #TIB !   ( token)                         \ prepare #TIB
      EXECUTE                                              \ do-it!
      R> SOURCE-FILE !   R> #TIB !   R> >IN !   R> BLK !   \ restore-it
      ;

(This is here so that Mitch or anyone else can tell me how to fix or improve
it.)


   > [The obvious question:  Can QUOTE-TO be done in
   > BASIS/dpANS-Forth?]

Actual translation of QUOTE-TO.SCR from Forth-83 to BASIS has been left as an
exercise to the Net in Puzzles and Problems.  I'm sure that QUOTE-TO.SCR is
non-compliant with BASIS, but just how much makes it a puzzle for me too.

 Robert

-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us

ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/29/90)

Category 3,  Topic 45
Message 2         Mon Aug 27, 1990
R.BERKEY [Robert]            at 21:39 PDT
 
 
  > This is to be used in the form IF( c1 e1 ... ck ek )IF

The solutions given to this problem depend on the source code being on one
line.  Let's pretty print it:

   This is to be used in the form:

      IF(
         c1 e1
         ...
         ck ek
      )IF

Now what?

Here's another recent example of a compiler, from Doug Philips:

  > Message-ID: <1569.UUL1.3#5129@willett.pgh.pa.us>
  > Date: Wed, 22 Aug 90 20:53:31 EDT

  > CLASS Foo
  > METHOD m1 ( code for method m1. )
  > METHOD m2 ( ... )
  > METHOD m3 ( ... )
  > ENDCLASS
  >
  > The above code can compile into a series of if-then tests, much
  > like Wavrik's recently posted IF( )IF might.  The SEND method (in
  > my scheme) pops the object, arranges for it to be the result of
  > SELF, which leaves the message name on the top of stack.  It then
  > jumps to the if-then code above (based on information gotten from
  > the object).  The code then figures out which method to invoke, if
  > it finds one, it executes it and returns.  If the code falls
  > through to ENDCLASS, ENDCLASS could arrange for a search of the
  > super-classes dictionary, or whatever.

Robert

-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us

dwp@willett.pgh.pa.us (Doug Philips) (08/29/90)

In <1612.UUL1.3#5129@willett.pgh.pa.us>, R.BERKEY [Robert] writes:

> QUOTE-TO.SCR is a Forth-83 Standard Program available on GEnie and BCFB.  It
> was written in part as an exercise in writing a Standard Program, as well as
> for the perennial question concerning the code that passes <name>s to defining
> words.  QUOTE-TO.SCR includes the word "> ("quote-to"), which is a one-word
> syntax, and there is also a two-word syntax such as Mitch has shown.

[ I have QUOTE-TO.SCR on willett, if anyone would like a copy, drop me a
  mail message at one of the addresses at the end of this posting.  I will
  send you a UUENCODED copy.  -dwp]

Thanks for the reply.  (I should have remembered this stuff, *blush*).
-Doug

---
Preferred: ( dwp@willett.pgh.pa.us  OR  ...!{sei,pitt}!willett!dwp )
Daily: ...!{uunet,nfsun}!willett!dwp  [last resort: dwp@vega.fac.cs.cmu.edu]