Category:Forth: Difference between revisions

types, grammar...
No edit summary
(types, grammar...)
 
(15 intermediate revisions by 6 users not shown)
Line 1:
{{language|Forth
[[Category:Solutions by Programming Language]]
|gc=no
'''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.
|untyped=yes
|LCT=yes}}
{{language programming paradigm|concatenative}}
{{language programming paradigm|imperative}}
'''Forth''' is a [[procedural programming|procedural]], [[stack]]-oriented and [[reflective programming]] language without type checking which is also a concatenative programming language. Forth features both interactive execution of commands (making it suitable as a shell for systems that lack a more formal [[:Category:Operating_Systems|operating system]]) and the ability to compile sequences of commands for later execution; due to its ability to easily cross-compile a version of itself to other target architectures and because it does not need to rely on an underlying operating system, it is often used for embedded systems. Some Forth versions (especially early ones) compile concatenative threaded code, but many implementations today generate optimized machine code like other language compilers. While it has quite competitive performance on its own (comparable to Just-In-Time - JIT - compiled languages such as JavaScript, or those used on the Java Virtual Machine - JVM - such as Kotlin, or on DotNet such as C# or F#); however, if a particular application requires it, there is a closely integrated machine code Assembler that can be used to write the most time critical functions/"words" or to supply features not available in the standard language implementation.
 
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:. Standard words should be uppercase, but most Forth systems are case-insensitive.
 
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 / ;
 
==Citations==
* [http[wp://en.wikipedia.org/wiki/Forth_%28programming_language%29 |Wikipedia:Forth (programming language)]]
* [http://wwwlars.forthfreaknocrew.netorg/dpans/dpansf.htm Index to the ANS Forth words]
* [[wp:Concatenative_programming_language|Wikipedia:Concatenative Programing language]]
474

edits