Front Page All Articles Recent Changes Random Article

Contents

Concatenative language

  • ACL
  • Ait
  • Aocla
  • Breeze
  • Callisto
  • Cat
  • Cognate
  • colorForth
  • Concata
  • CoSy
  • Deque
  • DSSP
  • dt
  • Elymas
  • Enchilada
  • ETAC
  • F
  • Factor
  • Fiveth
  • Forth
  • Fourth
  • Freelang
  • Gershwin
  • hex
  • iNet
  • Joy
  • Joy of Postfix App
  • kcats
  • Kitten
  • lang5
  • Listack
  • LSE64
  • Lviv
  • Meow5
  • min
  • Mirth
  • mjoy
  • Mlatu
  • Ode
  • OForth
  • Om
  • Onyx
  • Plorth
  • Popr
  • Porth
  • PostScript
  • Prowl
  • Quest32
  • Quackery
  • r3
  • Raven
  • Retro
  • RPL
  • SPL
  • Staapl
  • Stabel
  • Tal
  • Titan
  • Trith
  • Uiua
  • Worst
  • xs
  • XY
  • 5th
  • 8th

Concatenative topics

  • Compilers
  • Interpreters
  • Type systems
  • Object systems
  • Quotations
  • Variables
  • Garbage collection
  • Example programs

Concatenative meta

  • People
  • Communities

Other languages

  • APL
  • C++
  • Erlang
  • FP trivia
  • Haskell
  • Io
  • Java
  • JavaScript
  • Lisp
  • ML
  • Oberon
  • RPL
  • Self
  • Slate
  • Smalltalk

Meta

  • Search
  • Farkup wiki format
  • Etiquette
  • Sandbox

Factor/FAQ/Develop

I'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:

  • http://docs.factorcode.org/content/article-compiler-errors.html
  • http://docs.factorcode.org/content/article-inference-errors.html

Basically, compiler errors always indicate problems in your code and should be fixed -- however, your code will still run if it has compiler errors (but it will probably fail with some kind of runtime error).

Compiler warnings are not fatal; you should minimize their number, because they indicate words which could not be compiled with optimizations. Some words will always have warnings, namely combinators which call non-literal quotations. Combinators can be declared inline, and their callers will then compile without warnings, however. See the above two links for full details.

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 :1 or :2 to add the cpu.architecture or ui.gadgets.labels vocabularies to the search path, as if you had typed USE: cpu.architecture or USE: ui.gadgets.labels. See http://docs.factorcode.org/content/article-errors-restartable.html for more information.

What is the difference between USE: foo and USING: foo ; ?

There is none. USING: is equivalent to multiple USE: in a row.

If I do 1 foo set at the toplevel of a file, then why does foo get in the listener give me f after loading that file?

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 <hashtable>, which pushes an object on the stack, then you manipulate it with words such as at and set-at. The important thing is that the hashtable sits on the stack as a single value; values on the stack are not limited to scalars such as numbers and booleans, they can be complex types too (arrays, hashtables, tuples, ...). Furthermore, if you really want a stack data structure, don't use the data stack; use a vector and call push and pop on it.

See the following for details:

  • http://docs.factorcode.org/content/tag-collections.html
  • http://docs.factorcode.org/content/article-hashtables.html
  • http://docs.factorcode.org/content/article-assocs-protocol.html
  • http://docs.factorcode.org/content/article-sequences-stacks.html

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

This revision created on Fri, 9 Jan 2009 23:37:37 by JoshGrams (principle -> principal)

Latest Revisions Edit

All content is © 2008-2024 by its respective authors. By adding content to this wiki, you agree to release it under the BSD license.