Factor/FAQ/DevelopI've found a bug. What should I do? First, check Bug reports to see if its a known issue. Then, report the bug on that page, in the Concatenative IRC channel, or on the Mailing list. How do I store my code outside of the Factor source tree? See http://docs.factorcode.org/content/article-add-vocab-roots.html. What are compiler errors/warnings? See the following two help articles:
Compiler errors and warnings indicate problems in your code and should be fixed. If a combinator compiles with a warning, declare it I tried entering some code in the listener that came from the docs or from a Factor programmer, however I get a "no word found" error. Is the code wrong? If you invoke a word that does not exist, you get an error like the following, ( scratchpad ) fadf 1: fadf ^ Word not found in current vocabulary search path "name" "fadf" The following restarts are available: :1 Defer word in current vocabulary Type :help for debugging help. However, note that the message says "Word not found in current vocabulary search path". Sometimes the word might exist, but its vocabulary won't be in the listener's search path (not all vocabularies are added by default). In that case, the error looks similar, but you get restarts: ( scratchpad ) "Hello world" <label> 1: "Hello world" <label> ^ Word not found in current vocabulary search path "name" "<label>" The following restarts are available: :1 Use the cpu.architecture vocabulary :2 Use the ui.gadgets.labels vocabulary :3 Defer word in current vocabulary Type :help for debugging help. In the above case, you can invoke What is the difference between USE: foo and USING: foo ; ? There is none. If I do When parsing a file and executing toplevel code, a new dynamic scope is created. If you want to have that value of foo be accessable elsewhere, use 1 foo set-global or : foo 1 ; depending on whether foo's value needs to change. You may, instead, want to make a word like : init-foo 1 foo set ; to initialize that value. How can hashtables and arrays be implemented efficiently within a language where the principal data structure is a stack? This is actually a common misconception. Factor's stack is not a data structure -- it is a means of passing values between words. Factor supports hashtables easily enough; you create a new hashtable by calling See the following for details:
I have a word pushing a vector on the stack, and it's written as an empty vector, V{ }, in the source, but when the word runs the vector has random objects in it. What's going on? Literals are a source of confusion for some beginners. Literals are pushed to the stack in the place they are used. A literal in Factor refers to one specific object in memory, and is not automatically cloned. If you modify a literal without cloning it, that modification will be global. For more information, see the help document about literals. One stack is not enough. Is it possible to define new stacks? If you find it hard to express your dataflow using the data stack alone, consider either refactoring your code, or using locals, before you start thinking about adding new stacks. However, if you really need an additional stack (for example, you're writing a parser and need to track nested structure), you can make one easily enough, in one of several ways. The easiest way is to store the stack in a dynamic variable: SYMBOL: my-stack : >my-stack ( value -- ) my-stack get push ; : my-stack> ( -- value ) my-stack get pop ; : with-my-stack ( quot -- ) [ V{ } clone my-stack ] dip with-variable ; inline Do stack shuffle words like dup copy my objects? No. The stack is a stack of pointers, so My code is too slow. How do I make it faster? First, make sure your algorithm is right. Once you've eliminated any time and space complexity issues, you can start looking at low-level optimization. See Optimization. This revision created on Fri, 17 Apr 2009 04:25:39 by slava |
|
All content is © 2008-2010 by its respective authors. By adding content to this wiki, you agree to release it under the BSD license. |