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


Groups > comp.lang.forth > #15135

Re: Implementing ." in forth

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Implementing ." in forth
Date 2012-08-24 14:41 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2012Aug24.164144@mips.complang.tuwien.ac.at> (permalink)
References <k15dp4$kag$1@dont-email.me> <2012Aug23.164507@mips.complang.tuwien.ac.at> <k17ojv$6ei$1@dont-email.me>

Show all headers | View raw


Arnold Doray <invalid@invalid.com> writes:
>Thanks -- this would work only in compilation mode as you say. I was 
>hoping to get ." to work in both compilation AND interpretation mode, as 
>GForth does. 

If you want it to work properly, like Gforth does, you need to
implement a way to have words with independent interpretation and
compilation semantics, like Gforth does.

These days I think that having a recognizer for string literals and
then writing

"hello, world" type

is a better alternative, though.

>Now, even if I had a COMPILATION? word to test if we are in compilation 
>mode:
>
>: [."]  [char] " parse ` sliteral ` type ; immediate
>: (.")  [char] " parse type ; 
>
>: ." compilation? if [."] else (.") then ; \ CLEARLY DOES NOT WORK

Well, a slight variation of that would work when text-interpreted, but
not always when ticked or POSTPONEd:

: ." state @ if postpone [."] else postpone (.") then ; immediate

That's one of the infamous STATE-smart words.

>Is there no ANS Forth only solution to this problem of "mixed modes"??

You could fix the problem of the STATE-smart version as follows:

: ' 
  ' dup ['] ." = if drop ['] (.") then ;

: ['] ' postpone literal ; immediate

: postpone
  >in @ ['] ' catch if >in ! postpone postpone exit then
  ['] ." = if drop postpone [."] else >in ! postpone postpone then
; immediate

>SEEing GForth's solution: 
>
>------
>see ." 
>noname : 
>  34 parse type ;
>latestxt
>
>noname : 
>  34 parse  POSTPONE SLiteral 16227928 compile, ;
>latestxt
>interpret/compile: ."  ok
>-----
>
>I don't really understand this. Could anyone explain what's happening 
>here? 

The first colon definition is your (.").  It's a noname: definition,
which the decompiler decompiles a little differently (using the
Gforth-specific NONAME and LATESTXT words).  The second colon
definition is your [."].  The POSTPONE TYPE is compiled as "['] TYPE
COMPILE,", and the decompiler only shows the numerical value of the xt
of TYPE.  The Gforth word for building words with independent
interpretation and compilation semantics is "INTERPRET/COMPILE:", and
it takes the two xts and the name '."' and defines the word '."'.

- 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 2012: http://www.euroforth.org/ef12/

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


Thread

Implementing ." in forth Arnold Doray <invalid@invalid.com> - 2012-08-23 14:12 +0000
  Re: Implementing ." in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-23 14:45 +0000
    Re: Implementing ." in forth Arnold Doray <invalid@invalid.com> - 2012-08-24 11:30 +0000
      Re: Implementing ." in forth Josh Grams <josh@qualdan.com> - 2012-08-24 12:56 +0000
      Re: Implementing ." in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-24 14:41 +0000
        Re: Implementing ." in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-24 16:45 +0000
        Re: Implementing ." in forth Arnold Doray <invalid@invalid.com> - 2012-08-25 03:41 +0000
          Re: Implementing ." in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-25 09:05 +0000
            Re: Implementing ." in forth Arnold Doray <invalid@invalid.com> - 2012-08-29 15:48 +0000
              Re: Implementing ." in forth Coos Haak <chforth@hccnet.nl> - 2012-08-29 21:19 +0200
              Re: Implementing ." in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-30 13:00 +0000
  Re: Implementing ." in forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-23 12:00 -0500
  Re: Implementing ." in forth Spam@ControlQ.com - 2012-08-23 14:16 -0400
  Re: Implementing ." in forth Mark Wills <markrobertwills@yahoo.co.uk> - 2012-08-23 14:37 -0700
  Re: Implementing ." in forth "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-23 19:37 -0400
  Re: Implementing ." in forth hughaguilar96@yahoo.com - 2012-08-24 00:06 -0700
    Re: Implementing ." in forth Arnold Doray <invalid@invalid.com> - 2012-08-24 11:32 +0000
      Re: Implementing ." in forth Doug Hoffman <glidedog@gmail.com> - 2012-08-24 08:33 -0400
  Re: Implementing ." in forth jim@rainbarrel.com - 2012-08-24 09:15 -0700
  Re: Implementing ." in forth Chris Hinsley <chris.hinsley@gmail.com> - 2012-08-25 15:15 +0100

csiph-web