Category:Forth: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
(split Forth common practice to its own page)
Line 2: Line 2:
'''Forth''', a procedural, stack-oriented and reflective programming language without type checking, Forth features both interactive execution of commands (making it suitable as a shell for systems that lack a more formal operating system) and the ability to compile sequences of commands for later execution. Some Forth versions (especially early ones) compile threaded code, but many implementations today generate optimized machine code like other language compilers.
'''Forth''', a procedural, stack-oriented and reflective programming language without type checking, Forth features both interactive execution of commands (making it suitable as a shell for systems that lack a more formal operating system) and the ability to compile sequences of commands for later execution. Some Forth versions (especially early ones) compile threaded code, but many implementations today generate optimized machine code like other language compilers.


Where not otherwise specified, examples conform to the 1994 ANSI Standard, also known as '''ANS Forth'''. Most Forth implementations now conform to this standard, often with system-specific extensions and convenience libraries. Some examples use words that are not in the standard, but which have become accepted as common practice since 1994:
Where not otherwise specified, examples conform to the 1994 ANSI Standard, also known as '''ANS Forth'''. Most Forth implementations now conform to this standard, often with system-specific extensions and convenience libraries. Some examples use words that are not in the standard, but which have become accepted as [[Forth common practice|common practice]] since 1994.

1 cells constant cell
-1 cells constant -cell
: cell- -cell + ;

: -rot ( a b c -- c a b ) rot rot ;

: bounds ( addr len -- limit addr ) over + swap ; \ convert string/array to DO-LOOP limits

DEFER-IS for late-bound, revectorable, and forward-referenced words:
: noop ( -- ) ;
: defer create ( "name" -- ) ['] noop , does> ( -- ) @ execute ;
: is ( xt "name" -- ) ' >body ! ;
defer lessthan
' < is lessthan
2 3 lessthan . \ -1 (true)

Alternate local variable syntax using curly braces, designed to look like a regular stack comment:
: muldiv { a b -- a*b a/b } \ all stuff after "--" is ignored
a b * a b / ;

Some counted string utilities:
: c+! ( n caddr -- ) dup >r c@ + r> c! ;
: append ( src len dest -- ) 2dup 2>r count + swap move 2r> c+! ;
: place ( src len dest -- ) 2dup 2>r 1+ swap move 2r> c! ;
: scan ( str len char -- str' len' ) >r begin dup while over c@ r@ <> while 1 /string repeat then r> drop ;
: skip ( str len char -- str' len' ) >r begin dup while over c@ r@ = while 1 /string repeat then r> drop ;
: split ( str len char -- str1 len1 str2 len2 ) >r 2dup r> scan 2swap 2 pick - ;


==Citations==
==Citations==

Revision as of 20:43, 17 September 2007

Forth, a procedural, stack-oriented and reflective programming language without type checking, Forth features both interactive execution of commands (making it suitable as a shell for systems that lack a more formal operating system) and the ability to compile sequences of commands for later execution. Some Forth versions (especially early ones) compile threaded code, but many implementations today generate optimized machine code like other language compilers.

Where not otherwise specified, examples conform to the 1994 ANSI Standard, also known as ANS Forth. Most Forth implementations now conform to this standard, often with system-specific extensions and convenience libraries. Some examples use words that are not in the standard, but which have become accepted as common practice since 1994.

Citations

Subcategories

This category has the following 3 subcategories, out of 3 total.

Pages in category "Forth"

The following 200 pages are in this category, out of 616 total.

(previous page) (next page)
(previous page) (next page)