programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: Which defining word do I want?

From: Richard Owlett <rcowlett_at_atlascomm.net>
Date: Fri, 11 Aug 2006 14:48:16 -0500

Rick VanNorman wrote:
> On 8/11/06, Richard Owlett <rcowlett_at_atlascomm.net> wrote:
>
>>Richard Owlett wrote:
>>
>>>Thanks.
>>>It works. I think I see why, but will have to sleep on it.
>>>
>>
>>I see now. Your use of 2>R for >R >R threw me for a little while.
>>But it made me STOP _READ_ *THINK* ;]
>>
>>Is there any restriction on what can be done inside either the CREATE or
>>DOES> phrase?
>>
>>
> First, the CREATE phrase runs at the time you create the object. Execution
> does not, at that time, continue thru the DOES>.

I figured that, but phrased my question more openly to not appear to
know more than I actually do. I wasn't sure what other gotcha's might
appear because part executed at compile time and another at execution time.

When asking the questions I have in mind, it's safer to appear MORE
ignorant than less if useful answers desired.

> Second, the DOES> portion runs only when the newly created object is
> executed. It begins execution with the address of the object on the top
> of the stack, and you must use it or discard it.

If that is *not* a _leading question_ to another thread I was
considering, I don't know what is? LOL

You wrote:
> Try this for a start with defining words:
> : FOOD
> CREATE ( cal fat carb prot sod)
> 2>R 2>R , R> , R> , R> , R> ,
> DOES>
> 5 0 DO ( portion addr)
> 2DUP @ * . CELL+
> LOOP 2DROP ;
>
> 3 4 5 6 7 FOOD YOGURT
>

That met all the criteria I specified.
You can blame length of thread on *JERRY AVINS*
  he has taught me to ask *ONLY* _ONE_ QUESTION at a time ;)
      [ i hope he reads this group snicker snicker ]

The use would be
   3 YOGURT
which would result in following on output device of
   9 12 15 18 21

(OK already supplied code did not explicitly supply CRLF pair)

As my intention is human readability, I'd like output as

YOGURT 3 9 12 15 18 21

The presence of 2DROP suggests I could get an output of
9 12 15 18 21 3 YOGURT

I just thought of three ways to phrase my question.
That lead me to suspect I did not know what to ask ;)

>
> Third, you may use things like LOCALS| in either of the two phrases, but
> due to the way the compiler handles the LOCALS| construct, you can't
> use it in both.

Actually I was thinking in terms of items defined with VALUE.
I ran a couple experiments which indicated that might be proper.

>
> Fourth, because each section is execution time independent, you can't
> carry data from one to the other on the return stack or the data stack, and
> anything you do on the return stack must be cleaned up within the section
> where it is done.
>

understood and in sense presumed

Thank you for your time.

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Fri Aug 11 2006 - 12:48:06 PDT

This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:16 PST