pForth

pForth, un Forth ANS portabile: programmazione interattiva a stack, con virgola mobile e parole per i file. Scrivi pforth per il prompt, pforth file.fth per caricare un file.

versione 2.0.1 · Licenza: 0BSD · Sito del progetto

pForth

A cosa serve

Forth è un linguaggio a stack: i numeri vanno su una pila e le "parole" li consumano, per esempio 2 3 + lascia 5. Si definiscono parole nuove con : e ;, e si prova tutto al volo. pForth è un Forth ANS portabile, con numeri in virgola mobile, stringhe, variabili, cicli e parole per leggere e scrivere file.

Come si usa

Comando Cosa fa
pforth apre il prompt interattivo
pforth -q come sopra, senza intestazione né ok dopo ogni riga
pforth programma.fth esegue un file dalla cartella home e termina

Nel prompt scrivi parole separate da spazi e premi Invio; dopo ogni riga pForth risponde ok e mostra lo stack (Stack<10> vuol dire base 10, stack vuoto):

2 3 + .                            \ stampa 5
: QUADRATO ( n -- n*n ) DUP * ;    \ una parola nuova
12 QUADRATO .                      \ stampa 144
10 0 DO I . LOOP                   \ stampa 0 1 2 ... 9
VARIABLE CONTO  5 CONTO !  CONTO @ 2 * .
2.5e0 3.0e0 F* F.                  \ stampa 7.500000

Per caricare un file senza uscire: include programma.fth. Per vedere le parole disponibili: words. Per uscire: bye, oppure EOF.

Limiti

Le celle sono a 32 bit. Niente editor di riga né cronologia (il Terminale manda righe intere). Una divisione per zero dà l'errore THROW code = -10 invece di chiudere il programma. RESIZE-FILE non può accorciare i file. Memoria disponibile: fino a 4 MB.

Nel Terminale

pForth

pForth, a portable ANS Forth: stack-based interactive programming, with floating point and file words. Type pforth for the prompt, pforth file.fth to load a file.

version 2.0.1 · License: 0BSD · Project site

pForth

What it is

Forth is a stack language: numbers go on a stack and "words" consume them, e.g. 2 3 + leaves 5. You define new words with : and ; and try everything on the fly. pForth is a portable ANS Forth with floating point, strings, variables, loops and words to read and write files.

How to use it

Command What it does
pforth opens the interactive prompt
pforth -q same, without the banner and the ok after each line
pforth program.fth runs a file from the home folder and exits

At the prompt type words separated by spaces and press Enter; after each line pForth answers ok and shows the stack (Stack<10> means base 10, empty stack):

2 3 + .                            \ prints 5
: SQUARE ( n -- n*n ) DUP * ;      \ a new word
12 SQUARE .                        \ prints 144
10 0 DO I . LOOP                   \ prints 0 1 2 ... 9
VARIABLE COUNTER  5 COUNTER !  COUNTER @ 2 * .
2.5e0 3.0e0 F* F.                  \ prints 7.500000

To load a file and stay: include program.fth. To list the available words: words. To quit: bye, or EOF.

Limits

Cells are 32-bit. No line editor or history (the Terminal sends whole lines). Division by zero gives the error THROW code = -10 instead of killing the program. RESIZE-FILE cannot shrink files. Memory: up to 4 MB.

In the Terminal