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


Groups > comp.lang.forth > #1650

Re: STATE

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Subject Re: STATE
Newsgroups comp.lang.forth
References <496ffa3f-5ac9-45a9-9190-bb3875e8b44e@m40g2000vbt.googlegroups.com> <2011Apr28.105956@mips.complang.tuwien.ac.at> <e45c4bf6-2f6b-4e40-907a-ac5246f18dd0@f30g2000yqa.googlegroups.com>
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Date 2011-04-29 17:30 +0000
Message-ID <2011Apr29.193023@mips.complang.tuwien.ac.at> (permalink)

Show all headers | View raw


Brad <hwfwguy@gmail.com> writes:
>On Apr 28, 1:59=A0am, an...@mips.complang.tuwien.ac.at (Anton Ertl)
>wrote:
>> ... but nowadays I don't believe
>> that one would use this pattern for maintaining the text interpreter
>> mode (aka STATE), so I don't see a reason for using STATE in
>> well-written code.
>
>User code has no reason to write to STATE, but sometimes it needs to
>read from it:
>
>: H#  ( <hex> -- u )
>   ( code to get number )
>   STATE @ IF POSTPONE LITERAL THEN
>; IMMEDIATE

Ugh.  Still, it can be replaced with code that does not mention STATE:

: eval-num ( c-addr u -- |n|d )
  get-order n>r 0 set-order
  ['] evaluate catch
  nr> set-order
  throw ;

: base-exec ( ... xt ubase -- ... )
  base @ >r
  base !
  catch
  r> base !
  throw ;

: h#
  parse-name ['] eval-num $10 base-execute ; immediate

h# add .
: foo h# add ;

Works even with double numbers, unlike the original version.  Still, I
don't like H# approach.

On a tangent: I used three Forth200x extensions in this short piece of
code to good effect (PARSE-NAME, number prefixes, N>R/NR>); these
extensions do prove useful.

- 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 2010: http://www.euroforth.org/ef10/

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


Thread

STATE MarkWills <markrobertwills@yahoo.co.uk> - 2011-04-27 12:41 -0700
  Re: STATE Alex McDonald <blog@rivadpm.com> - 2011-04-27 13:04 -0700
    Re: STATE MarkWills <markrobertwills@yahoo.co.uk> - 2011-04-27 13:13 -0700
      Re: STATE Alex McDonald <blog@rivadpm.com> - 2011-04-27 13:45 -0700
    Re: STATE "P.M.Lawrence" <pml540114@gmail.com> - 2011-04-28 03:00 -0700
      Re: STATE Alex McDonald <blog@rivadpm.com> - 2011-04-28 04:09 -0700
        Re: STATE Alex McDonald <blog@rivadpm.com> - 2011-04-28 04:10 -0700
  Re: STATE Micke <oh2aun@gmail.com> - 2011-04-27 13:20 -0700
    Re: STATE MarkWills <markrobertwills@yahoo.co.uk> - 2011-04-27 13:26 -0700
      Re: STATE MarkWills <markrobertwills@yahoo.co.uk> - 2011-04-27 13:30 -0700
      Re: STATE Elizabeth D Rather <erather@forth.com> - 2011-04-27 11:13 -1000
        Re: STATE Elizabeth D Rather <erather@forth.com> - 2011-04-27 17:17 -1000
        Re: STATE Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-04-29 06:14 -0500
          Re: STATE Elizabeth D Rather <erather@forth.com> - 2011-04-29 08:47 -1000
            Re: STATE MarkWills <markrobertwills@yahoo.co.uk> - 2011-04-29 14:07 -0700
  Re: STATE BruceMcF <agila61@netscape.net> - 2011-04-27 19:22 -0700
  Re: STATE BruceMcF <agila61@netscape.net> - 2011-04-30 08:18 -0700
  Re: STATE BruceMcF <agila61@netscape.net> - 2011-04-30 08:26 -0700
  Re: STATE "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2011-04-30 03:24 -0400
  Re: STATE stephenXXX@mpeforth.com (Stephen Pelc) - 2011-04-30 11:41 +0000
  Re: STATE stephenXXX@mpeforth.com (Stephen Pelc) - 2011-04-30 11:53 +0000
    Re: STATE BruceMcF <agila61@netscape.net> - 2011-04-30 08:48 -0700
  Re: STATE anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-04-28 08:59 +0000
    Re: STATE Brad <hwfwguy@gmail.com> - 2011-04-28 08:01 -0700
      Re: STATE Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-04-28 12:16 -0500
        Re: STATE Elizabeth D Rather <erather@forth.com> - 2011-04-28 09:47 -1000
      Re: STATE BruceMcF <agila61@netscape.net> - 2011-04-28 15:56 -0700
        Re: STATE Brad <hwfwguy@gmail.com> - 2011-04-29 07:49 -0700
          Re: STATE BruceMcF <agila61@netscape.net> - 2011-04-29 11:47 -0700
      Re: STATE anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-04-29 17:30 +0000
    Re: STATE Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-04-28 17:47 +0000
      Re: STATE Elizabeth D Rather <erather@forth.com> - 2011-04-28 09:50 -1000
  Re: STATE "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2011-04-28 16:32 -0400
    Re: STATE MarkWills <markrobertwills@yahoo.co.uk> - 2011-04-29 02:11 -0700
      Re: STATE BruceMcF <agila61@netscape.net> - 2011-04-29 07:24 -0700
      Re: STATE "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2011-04-29 13:56 -0400
        Re: STATE BruceMcF <agila61@netscape.net> - 2011-04-29 11:44 -0700
          Re: STATE "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2011-04-29 15:45 -0400
            Re: STATE Elizabeth D Rather <erather@forth.com> - 2011-04-29 10:22 -1000
            Re: STATE BruceMcF <agila61@netscape.net> - 2011-04-29 13:31 -0700
        Re: STATE Elizabeth D Rather <erather@forth.com> - 2011-04-29 09:07 -1000

csiph-web