From a FaceBook Messenger
exchange
What does
APL add to open native Forth ?
Speaking to a Forther who understands the unique simplicity , openness and and understanding of the nature of ` compiling and direct interaction with hardware of Charles Moore's language , I'll address what Ken Iverson's , as retold by Arthur Whitney , APL adds . ( If not familiar with APL I strongly suggest reading or watching some of the many references to APL . See the 1998 K Reference Manual for the direct legacy from which 4th.CoSy evolves . ) In a word , I'd
say plurals .
And that implies objects . The most basic object on all computers is an address space . Forth provides a minimal vocabulary laying out in a single address space a dictionary capable of appending new words to itself . An address space is an integer indexed list of constant sized cells themselves lists of bits . Nouns
Lists are CoSy's nouns . So the most fundamental
vocabulary CoSy
adds to a Forth vocabulary is lexicon to allocate and free address
spaces with a simple 3 cell header containing the fundamental
information about themselves :`( type count refCount )`
CoSy
verbs generally expect addresses of CoSy
lists as arguments . Ones which expect a naked cell are
generally prefixed by a ` _
.A cell gives an awful lot of space for types and currently only `( char int float )` are defined in addition to a general list , a list of addresses of lists , which is type 0 . When a list is created , its reference count is set to 0 . No other object , no other list refers to it . But , for instance , if it's just an item in a higher level list , it reference count will be incremented appropriately . In general on exit most Forth level verbs free any argument which has a ref count of 0 . The vocabulary , I'm inclined to call it algebra , for the accounting of references is the enabler for everything else . But a crucial piece of this vocabulary is the ability to convert these recursive lists of address spaces to and from a linear form for transfer and storage . Verbs & Adverbs Iverson came to prefer the ordinary words verbs and adverbs to APL's original functions and operators . A verb is simply a word which takes nouns as arguments . Adverbs take verbs along with nouns among their arguments . See the top of the distribution ` text log for executable examples . Two of Moore's brilliances make these constructions much simpler and flexible than other APLs .
5 _i iota
|>| 0 1 2 3 4 | takes a naked 5 off the stack convert it
to a 1 item
Most of the adverbs in CoSy
, as in previous APLs , apply a verb to each item in a list or each
corresponding pair of items in a pair lists . | then ' iota ( an ancient APL name ) returns a list of first 5 integers , ie: an | index into an address space . It
can do this because the count of items in a list , for which I'm stuck
on the venerable APL name rho , is the second cell in the header . And
, an inovation which eliminates a lot of complexity in APL and
possibility of bounds errors , is
all indexing is modulo .
Thus almost all loops become words taking a list or lists , a verb , and an adverb . Following Arthur Whitney , there are 4 basic flavors : list ' verb 'm
| 'm for monadic , ie: single argument
For example :Llist Rlist ' verb 'd | 'd for dyadic , ie: 2 argument . apply verb to each pair Llist Rlist ' verb 'L | 'L for apply the Rlist as a whole to each item in Llist Llist Rlist ' verb 'R | 'R for apply the Llist as a whole to each item in Rlist ` asdf 5 _i iota ' take 'R
( a as asd asdf ) This is why I consider APL kind of like a Fourier transform of scalar programming language space .
--
|