To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.pbforthOpen lugnet.robotics.rcx.pbforth in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / pbFORTH / 379
378  |  380
Subject: 
Re: Forth question
Newsgroups: 
lugnet.robotics.rcx.pbforth
Date: 
Wed, 24 May 2000 11:09:57 GMT
Reply-To: 
sjm@SAYNOTOSPAMjudgement.com
Viewed: 
1254 times
  
Ralph Hempel wrote:

I'm trying to define a constant in a compiled word.

: zzz 1 CONSTANT ONE ;

I know its not right. It tries to compile "ONE" which is not
what is wanted. What is the right way to say this?

1 CONSTANT ONE

Recall that CONSTANT is a *defining* word, just like the ":"

I still want to create a constant from within a definition. I
have an initializing word that will calculate the value of
the constant. For various reasons I can't do this calculation
except within the runtime behavior of the word.

This is not critical. I have since replaced the constant
with a variable that I define in advance and then set
within my word, but then I have to use variable semantics
instead of constant semantics to access the value, which is
not what I wanted. I get around that by defining a new
word which leaves the value of the "constant" on the stack
": fake_constant varname @ ;" However this is a hack
and I was trying to understand how to do it right, i.e.
create a constant during the runtime behavior of a word.

I guess that the reason that this is hard is that I
effectively want my word to be a defining word. I guess
I need a new word that behaves like:

1 CONSTANT" name"

which saves the string at compile time and then uses it at
runtime to create the constant.

or perhaps one that behaves like:

1 S" name" SCONSTANT

Which expects a string on the stack instead of parsing
forward through the input stream.

As I said this is not important. I have a workaround.
It is more a matter of self education. I am trying to
learn to create new compile time behavior.



Message has 3 Replies:
  Re: Forth question
 
(...) Actually the various reasons are simple so I might as well state them. The serial port is not available at the time I want to create a constant because the serial port will be broken and therefor can't be used as the forth input stream. I am (...) (24 years ago, 24-May-00, to lugnet.robotics.rcx.pbforth)
  Re: Forth question
 
(...) You might want to try : zzz S" CONSTANT ONE" EVALUATE ; 1 zzz (...) I think VALUE can be used for that. Ernst (24 years ago, 24-May-00, to lugnet.robotics.rcx.pbforth)
  CONSTANTS and VALUES in pbForth
 
(...) There are a couple of things in this note. One is an introduction to CREATE DOES> and the other is a solution to your actual problem. Basically, what CREATE DOES> does is separate the run-time and compile time semantics of a word. This is (...) (24 years ago, 24-May-00, to lugnet.robotics.rcx.pbforth)

Message is in Reply To:
  RE: Forth question
 
(...) 1 CONSTANT ONE Recall that CONSTANT is a *defining* word, just like the ":" It makes a name in the dictionary, in this case "ONE" and then links to a special bit of code that is executed every time ONE is interpreted. It grabs the value out of (...) (24 years ago, 24-May-00, to lugnet.robotics.rcx.pbforth)

9 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR