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


Groups > comp.lang.forth > #33789

Re: Can every Forth do this?

From Gerry Jackson <gerry@jackson9000.fsnet.co.uk>
Newsgroups comp.lang.forth
Subject Re: Can every Forth do this?
Date 2014-10-09 19:42 +0100
Organization A noiseless patient Spider
Message-ID <m16kug$c3m$1@dont-email.me> (permalink)
References <9b988010-d503-43f9-bb61-5407e919ac8a@googlegroups.com> <2014Oct7.181615@mips.complang.tuwien.ac.at> <a1d588be-ace9-4253-9496-ce119adef6d9@googlegroups.com> <2014Oct9.172648@mips.complang.tuwien.ac.at>

Show all headers | View raw


On 09/10/2014 16:26, Anton Ertl wrote:
> november.nihal@gmail.com writes:
>> This caught my attention as I wasn't aware this was possible, the ability to have several does> in a word.
>>
>> " [snipped ] ...
>>
>> No, there may be several DOES> in a word, and CREATE and DOES> may be
>> in different words, and there may be several DOES> applied to the same
>> CREATEd word.
>>
>> ... [ snipped ]"
>>
>> Does anyone have any examples I could look at to understand ?
>
> Actually useful exaple (but not sure whether you understand it):
>
> <http://www.complang.tuwien.ac.at/forth/struct.fs>
>
> Look at CREATE-FIELD, DOFIELD, DOZEROFIELD, and FIELD.
>
> Simple contrived example:
>
> : x ( f -- )
>    does> drop ." a"
>    does> drop ." b" ;
>
> create a x
> a
> a
> a
> x
> a
> a
> a
>
> Have fun thinking it through:-)
>

And if you want more amusement here is how you can implement an FSM with 
it. It's not very practical though.

defer init
: ?key ( x ch -- f )  \ f = true if char not recognised
    nip key dup [char] q = abort" Aborted"
    dup emit <>
;

\ all op's are ( ad -- )
: state-d ." state-d " [char] d ?key 0= if cr ." Recognised" cr then init ;
: state-c ." state-c " [char] c ?key if init exit then does> state-d ;
: state-b ." state-b " [char] b ?key if init exit then does> state-c ;
: state-a ." state-a " [char] a ?key if init exit then does> state-b ;

:noname does> state-a ; is init

create run init
cr run 0 >in !       \ loop until 'q' is pressed

All the states can be put into one definition with multiple DOES>'s

-- 
Gerry

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


Thread

Can every Forth do this? JennyB <jennybrien@googlemail.com> - 2014-10-07 07:33 -0700
  Re: Can every Forth do this? Roger Levy <roger.levy@gmail.com> - 2014-10-07 08:58 -0700
  Re: Can every Forth do this? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-10-07 16:16 +0000
    Re: Can every Forth do this? november.nihal@gmail.com - 2014-10-08 06:17 -0700
      Re: Can every Forth do this? Mark Wills <markwills1970@gmail.com> - 2014-10-08 09:55 -0700
      Re: Can every Forth do this? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-10-09 15:26 +0000
        Re: Can every Forth do this? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-10-09 19:42 +0100
  Re: Can every Forth do this? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-10-07 18:16 +0000
    Re: Can every Forth do this? Jason Damisch <jasondamisch@yahoo.com> - 2014-10-07 11:32 -0700
    Re: Can every Forth do this? Mark Wills <markwills1970@gmail.com> - 2014-10-07 14:27 -0700
      Re: Can every Forth do this? "Elizabeth D. Rather" <erather@forth.com> - 2014-10-07 13:38 -1000
        Re: Can every Forth do this? Mark Wills <markwills1970@gmail.com> - 2014-10-07 20:21 -0700
        Re: Can every Forth do this? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-10-08 11:33 +0000
          Re: Can every Forth do this? JennyB <jennybrien@googlemail.com> - 2014-10-08 06:25 -0700
            Re: Can every Forth do this? november.nihal@gmail.com - 2014-10-08 08:14 -0700
              Re: Can every Forth do this? Mark Wills <markwills1970@gmail.com> - 2014-10-08 10:10 -0700
                Re: Can every Forth do this? JennyB <jennybrien@googlemail.com> - 2014-10-08 11:42 -0700
                Re: Can every Forth do this? Roger Levy <roger.levy@gmail.com> - 2014-10-08 12:31 -0700
                Re: Can every Forth do this? JennyB <jennybrien@googlemail.com> - 2014-10-09 07:03 -0700
                Re: Can every Forth do this? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-10-08 19:33 +0000
                Re: Can every Forth do this? november.nihal@gmail.com - 2014-10-08 16:39 -0700
                Re: Can every Forth do this? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-10-08 23:45 +0000
          Re: Can every Forth do this? Harold <hzrabbie@gmail.com> - 2014-10-08 14:23 -0700
            Re: Can every Forth do this? "Elizabeth D. Rather" <erather@forth.com> - 2014-10-08 12:48 -1000
            Re: Can every Forth do this? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-10-08 23:39 +0000
        Re: Can every Forth do this? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-10-08 13:17 +0000
        Re: Can every Forth do this? Roger Levy <roger.levy@gmail.com> - 2014-10-08 07:33 -0700
          Re: Can every Forth do this? Roger Levy <roger.levy@gmail.com> - 2014-10-08 07:33 -0700
  Re: Can every Forth do this? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-10-07 20:23 +0100

csiph-web