![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

Richard,
*********** REPLY SEPARATOR ***********
On 1/15/2002 at 2:39 PM Richard Owlett wrote:
>OK, let's start over. I think I introduced a 'red herring" in a previous
>post by mentioning the trigger word "string" ;{
>
>BACKGROUND: I am working on a 'problem' of a 'class' which I have solved
>before.
>OBJECTIVE: Learn more about Forth.
>CAVEAT LECTOR: I do not care if my strategy is optimal, I pose explicit
>questions.
>
>Problem redefinition:
>Preamble: any address is assumed to br in units of one CELL.
> Minimum array subscript is 1.
>
>Given an an array X(1) -> X(n), it is desired that ALPHA return the
>value at X(1)
>AND
>BETA return the address of X(1)
>
>Consider the following code fragment
>
>: wierd_VALUE ( n -- )
>HEADER POSTPONE (VALUE) 0 , /ALLOT ;
>
>1000 wierd_VALUE ALPHA
>
>: BETA ['] ALPHA ;
>: GAMMA ['] ALPHA 1 CELLS + ;
>
>QUESTIONs:
>1. Does APLHA respond in all cases as a word defined by VALUE ?
>2. Do BETA and GAMMA respond in all cases as words defined by VARIABLE
>?
> { ignoring ' and ['] and anything else with state-smartnerss etc. ?
>----------------------------------------------------------------------
BETA will never return an address; it returns the XT of ALPHA. Ditto
for GAMMA. To define BETA and GAMMA such that they work as your
questions describe:
: BETA ['] ALPHA >BODY ;
: GAMMA ['] ALPHA 1 CELLS + ;
or better
: GAMMA BETA 1 CELLS + ;
or still better
: GAMMA BETA CELL + ;
Note that your error as in assuming the value returned by ['] was an=
address.
Per the ANS standard, it only returns an XT, which is not constrained to be
any address at all, and in fact is a token. The word >BODY is defined to
translate XT to physical addresses, but is truly only valid (in the ANS
sense) for words that are instantiated by CREATE. So I would have defined
: WIERD_VALUE ( N -- )
CREATE 0 , /ALLOT DOES> @ ;
and then all of the code is correct. HOwever, you would not be allowed to
use TO for modifying ALPHA and would have to use a construct based on=
writing
to the address BETA returns.
Hope this helps,
Rick
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Tue Jan 15 2002 - 13:10:43 PST
This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:21 PST