Menu

Vectors

Vectors (1)
Claus Kuehnel

Vectors in Forth

Programming in Forth means defining new words built on the current vocabulary. It does not necessarily mean that the words have already defined the final properties. Forth offers the possibility to vary the properties of such words afterwards.

The program sample vectors.ff explains the mechanism of vectorization based on a query of an analog-digital converter.
Download: http://sourceforge.net/projects/flashforthforarduino/files/vectors.ff

\ *********************************************************************
\   Filename:      vectors.ff                                         *
\   Date:          14.01.2015                                         *
\   FF Version:    5.0                                                *
\   Copyright:     Claus Kuhnel                                       *
\   Author:        Claus Kuhnel                                       *
\ *********************************************************************
\   FlashForth is licensed according to the GNU General Public License*
\ *********************************************************************

\ Vectors in FlashForth

-vectors
marker -vectors

decimal ram

\ Pseudo-random numbers 
\ according to L. Brodie: Programmieren in FORTH. Hanser Verlag 1984

variable rnd
here rnd !

: random   ( -- w )
    rnd @ 31421 * 6927 + dup rnd !
;

: randNumber   ( range -- 0...range-1 )
    random um* swap drop
;

: (ADC)   ( -- 0...1023 )   \ emulates ADC output, as an example
    1024 randNumber
;

defer ADC@        \ Definition of vector variable

' (ADC) is ADC@   \ Initialization with dummy function

\ if "readADC" is the final ADC readout word then 
\ " ' readADC is ADC@" will give ADC@ the expected functionality
\ until this step you can test the operations following the ADC
\ with the dummy word (ADC)

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.