Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: The OO appr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 29 of 36 Topic 3978 of 4285
Post > Topic >>

Re: The OO approach

by Jonah Thomas <jethomas5@[EMAIL PROTECTED] > Mar 29, 2008 at 12:39 PM

Doug Hoffman <no.spam> wrote:

> I think that if any "over hyping" of OOP has occurred it was because 
> suddenly it gave users of languages other than Forth the power of a 
> create/does> construct.  I can see where people using other languages 
> would become excited over suddenly having the power (and more) of 
> Forth's create/does>.

Let's review again what CREATE DOES> does.

It lets you associate an action with an address. The action can be
re-used for many addresses. One to many. But the address can't easily be
associated with other actions, no many-to-one. Once an address has been
linked by DOES> it's actually harder to associate it with any other
action.

You can mimic DOES> easily without anything special, and get *most* of
the same results.

CREATE FOO-addr 5 CELLS ALLOT
: FOO 
   FOO-addr ACTION ;

This has an extra name, but the extra name lets you get to the base
address easily any time. It takes more typing to make a second one than 

: DO-ACTION
   CREATE CELLS ALLOT
   DOES> ACTION ;

5 DO-ACTION FOO	

You can reduce that.

: DOESIT ( xt addr "name" -- )
   : postpone literal compile, postpone ; ;

HERE 5 CELLS ALLOT ' ACTION DOESIT FOO

and it could be reduced further.

: DOES-ONE ( "name" "action" -- )
   HERE 1 CELLS ALLOT DUP >R
   :                \ start "name"
   R> ]] LITERAL    \ compile pointer address
    @[EMAIL PROTECTED]
               \ compile base address  
   [[ ] PARSE-NAME  \ get action name
   EVALUATE         \ compile action
   POSTPONE ;       \ "name" definition done
   HERE SWAP !      \ base address for data
;

DOES-ONE FOO ACTION 5 CELLS ALLOT

This isn't the same as DOES> because it restricts the DOES>  .... ;
clause to a single name, and it creates its own new data field instead
of using the latest CREATEd field. In both cases the data field can be
as big as you like, where the earlier versions needed you to allot all
its space before you compiled another definition (at least when
dataspace and codespace or namespace are mixed).

Again, what DOES> gives you isn't that much. It's simple to use DOES> so
that you can have an array, and instead of doing

FOO 5 TH   instead you do

5 FOO

You can have a complicated data structure and instead of doing

FOO ( addr ) SPECIAL-DATA-FIELD ( addr')

you can do

SPECIAL-DATA-FIELD ( token ) FOO ( addr')

I'm sure there are times when this is vitally im****tant.

It's possible to get these results in a way that's both simpler and more
powerful than CREATE DOES> . But we don't need the simplicity,
particularly when we have such a long tradition with CREATE DOES> . And
we may not have any use for the additional power.
 




 36 Posts in Topic:
The OO approach
Jonah Thomas <jethomas  2008-03-27 18:11:17 
Re: The OO approach
Bruce McFarling <agila  2008-03-27 18:58:22 
Re: The OO approach
John Passaniti <nntp@[  2008-03-28 21:10:34 
Re: The OO approach
Bruce McFarling <agila  2008-03-28 22:50:39 
Re: The OO approach
John Passaniti <put-my  2008-03-29 15:17:29 
Re: The OO approach
kenney@[EMAIL PROTECTED]   2008-03-30 10:56:21 
Re: The OO approach
Bruce McFarling <agila  2008-03-29 17:09:06 
Re: The OO approach
kenney@[EMAIL PROTECTED]   2008-03-30 10:56:21 
Re: The OO approach
Bruce McFarling <agila  2008-03-30 10:13:54 
Re: The OO approach
John Passaniti <john.p  2008-03-27 23:14:16 
Re: The OO approach
Gerry <gerry@[EMAIL PR  2008-03-28 03:40:23 
Re: The OO approach
Albert van der Horst <  2008-03-28 10:59:05 
Re: The OO approach
John Passaniti <nntp@[  2008-03-28 16:30:25 
Re: The OO approach
Bruce McFarling <agila  2008-03-28 08:40:42 
Re: The OO approach
"Jenny Brien" &  2008-03-28 17:44:14 
Re: The OO approach
Bruce McFarling <agila  2008-03-28 09:02:15 
Re: The OO approach
Bruce McFarling <agila  2008-03-28 11:08:40 
Re: The OO approach
William James <w_a_x_m  2008-03-29 14:30:10 
Re: The OO approach
Jonah Thomas <jethomas  2008-03-28 07:11:12 
Re: The OO approach
Bernd Paysan <bernd.pa  2008-03-28 14:18:04 
Re: The OO approach
Jonah Thomas <jethomas  2008-03-28 08:32:11 
Re: The OO approach
John Passaniti <nntp@[  2008-03-28 20:57:19 
Re: The OO approach
Helmar <helmwo@[EMAIL   2008-03-28 12:48:52 
Re: The OO approach
Doug Hoffman <no.spam&  2008-03-29 08:57:02 
Re: The OO approach
Bruce McFarling <agila  2008-03-29 09:41:35 
Re: The OO approach
Bruce McFarling <agila  2008-03-29 09:56:23 
Re: The OO approach
Bruce McFarling <agila  2008-03-29 10:44:15 
Re: The OO approach
Jonah Thomas <jethomas  2008-03-29 12:08:22 
Re: The OO approach
Jonah Thomas <jethomas  2008-03-29 12:39:02 
Re: The OO approach
Elizabeth D Rather <er  2008-03-29 07:30:55 
Re: The OO approach
Bruce McFarling <agila  2008-03-29 10:54:20 
Re: The OO approach
Jonah Thomas <jethomas  2008-03-29 13:34:25 
Re: The OO approach
Jonah Thomas <jethomas  2008-03-29 22:33:31 
Re: The OO approach
John Passaniti <nntp@[  2008-03-30 06:09:07 
Re: The OO approach
Andrew Haley <andrew29  2008-03-30 10:06:31 
Re: The OO approach
Jonah Thomas <jethomas  2008-03-30 08:39:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 13:34:57 CDT 2008.