Forth Questions / Answers Flashcards
(26 cards)
Difference between ‘ and [’]
The tick, ‘ reads the next word from the input stream and attempts to find its address in the dictionary, while [’] reads the next word in the definition.
Simplified form of quit
: quit begin reset query interepret .” ok” cr
false until ;
Why can quit be used to keep the message “ok” from appearing?
It clears the return stack and calls query, which waits for the next user input.
What are the effects of r> drop?
It skips one level of execution by removing one return address from the return stack.
What is the difference between quit and exit?
The word quit returns to the top level loop, and exit returns to the previous level.
Why can’t exit be used inside a do loop?
The do loop uses the return stack for its own purposes, which is unknown to exit. It cannot accomplish its task correctly because it uses values on the return stack.
What is a parameter field for a constant, variable, and colon definition?
For a constant and a variable it’s the value. For a colon definition, the list of addresses of words that are to be executed when the definition is executed.
What does the precompiled portion usually include?
- the text interpreter and the address interpreter
- defining, branching, and structure-control words
- single-length number conversion and formatting commands
- the editor
- the assembler
What does the run-time code perform for a colon definition?
Invokes the address interpreter.
What does the run-time code perform for a variable?
Pushes its address onto the stack.
What are the uses of a vectored execution?
- allows to change a behavior of a function after it has been compiled
- allows to call a not yet compiled function in order to avoid rearranging the order of definitions
What is the job of the interpreter?
To pick words out of the input stream and try to find the definitions in the dictionary, and then execute them.
What does the word ; do at the end of definitions?
It compiles the word exit which performs the return from the function by removing the return address from the return stack and jumping to it.
What are the different uses of the return stack?
- keep the return addresses
- hold temporary values
- keep the index and limit (in a do loop)
What is the word recurse used for?
It is used to call the current word in a recursive way.
hat are h and here?
The word h is a variable that contains the address of the first available cell in a user dictionary, here is the value of this variable.
How does pushing onto the data stack work?
The stack pointer is decremented and a number is stored where the pointer is pointing.
How does popping from the data stack work?
The number is fetched from the location where the pointer is pointing, and the pointer is incremented.
What are the two types of tasks?
Control tasks and terminal tasks. Control tasks have no terminal, while terminal tasks are interactive.
Difference between current and context vocabulary.
The current vocabulary specifies where new words are defined. The context vocabulary specifies where words are searched.
Difference between user and ordinary variables.
Ordinary variables are defined by the word variable Their value is kept in the parameter field of the dictionary entry. User variables are unique for each task, they are defined system-wide and their definitions can be used by all tasks in the system. The data of a user variable is kept in the user table.
What is the meaning of store?
To write a value at a certain address.
What is the meaning of fetch?
To return a value from an address.
What is the difference between variable and constant?
The invocation of a constant returns the value, whereas an invocation of a variable returns the address and the value needs to be “fetched”.