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


Groups > comp.lang.forth > #21364

Re: Anonymous code/data/create-does

Newsgroups comp.lang.forth
Subject Re: Anonymous code/data/create-does
References <93571201998434@frunobulax.edu> <02591300998434@frunobulax.edu>
From Lars Brinkhoff <lars.spam@nocrew.org>
Organization nocrew
Date 2013-04-04 12:42 +0200
Message-ID <85vc82shk7.fsf@junk.nocrew.org> (permalink)

Show all headers | View raw


mhx@iae.nl (Marcel Hendrix) writes:
> The new ^, word ( does-xt -- child-xt ) creates an anonymous child
> and returns it xt. The data for the child is supposed to be at
> HERE. When putting both [: ... ;], ^, and (e.g.) "," inside a
> definer-word, children can be dynamically created. Such children
> inherit the anonymous code and have a data field (at HERE) that can
> be initialized from the data passed to the definer word.

In my experiments with this, I arrived at a [does> ... ;] construction
which use is quite similar to create ... does>.

An example with three "closures" sharing some state:

   : counter ( n -- xt1 xt2 xt3 )
      here swap ,  dup [does> ! ;]  over [does> @ ;]  rot [does> +! ;] ;


This is equivalent with the following "nonymous" code:

   : setter   create , does> @ ! ;
   : getter   create , does> @ @ ;
   : counter ( n "name1 name2 name3" -- )
      here swap ,  dup setter  dup getter  create , does> @ +! ;

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


Thread

Anonymous code/data/create-does mhx@iae.nl (Marcel Hendrix) - 2013-04-02 23:46 +0200
  Re: Anonymous code/data/create-does "WJ" <w_a_x_man@yahoo.com> - 2013-04-02 22:51 +0000
  Re: Anonymous code/data/create-does "WJ" <w_a_x_man@yahoo.com> - 2013-04-02 23:00 +0000
  Re: Anonymous code/data/create-does Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-04-03 11:07 +0100
    Re: Anonymous code/data/create-does m.a.m.hendrix@tue.nl - 2013-04-03 06:53 -0700
      Re: Anonymous code/data/create-does Alex McDonald <blog@rivadpm.com> - 2013-04-03 13:43 -0700
        Re: Anonymous code/data/create-does Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-04-04 18:07 +0100
    Re: Anonymous code/data/create-does mhx@iae.nl (Marcel Hendrix) - 2013-04-04 00:38 +0200
      Re: Anonymous code/data/create-does Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-04-04 18:18 +0100
        Re: Anonymous code/data/create-does mhx@iae.nl (Marcel Hendrix) - 2013-04-04 20:29 +0200
          Re: Anonymous code/data/create-does mhx@iae.nl (Marcel Hendrix) - 2013-04-06 20:40 +0200
            Re: Anonymous code/data/create-does Alex McDonald <blog@rivadpm.com> - 2013-04-06 14:09 -0700
              Re: Anonymous code/data/create-does mhx@iae.nl (Marcel Hendrix) - 2013-04-07 02:04 +0200
                Re: Anonymous code/data/create-does Alex McDonald <blog@rivadpm.com> - 2013-04-06 20:34 -0700
                Re: Anonymous code/data/create-does mhx@iae.nl (Marcel Hendrix) - 2013-04-07 14:00 +0200
                Re: Anonymous code/data/create-does kenney@cix.compulink.co.uk - 2013-04-08 02:38 -0500
                Re: Anonymous code/data/create-does Roelf Toxopeus <rt4all@notthis.hetnet.nl> - 2013-04-08 10:58 +0200
                Re: Anonymous code/data/create-does Alex McDonald <blog@rivadpm.com> - 2013-04-08 14:57 -0700
                Re: Anonymous code/data/create-does Bernd Paysan <bernd.paysan@gmx.de> - 2013-04-08 19:26 +0200
                Re: Anonymous code/data/create-does kenney@cix.compulink.co.uk - 2013-04-09 02:07 -0500
  Re: Anonymous code/data/create-does mhx@iae.nl (Marcel Hendrix) - 2013-04-03 22:44 +0200
    Re: Anonymous code/data/create-does Lars Brinkhoff <lars.spam@nocrew.org> - 2013-04-04 12:42 +0200
      Re: Anonymous code/data/create-does Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-04 07:04 -0500
        Re: Anonymous code/data/create-does Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-04 07:07 -0500

csiph-web