i've wrapped up work on functional False, which i'm calling
"F", and i've started writing some simple programs in the
language. for example, here's the factorial function in F:
[dup!1=dup![swap!%1swap!]}not![dup!1sub!fac!*]}]fac
not as concise as False, but some might think that a virtue. :)
my design goals were:
1. F should be concatenative
2. F should be purely functional
3. F should include all the K verbs
4. no multi-symbol primitives
5. the symbols should be mnemonic
i never thought that a complete mapping of K verbs to symbols
was possible -- there are, after all, 40 K verbs and only 32
symbols on the keyboard, and some of those are required for
non-K operators.
my first surprise, then, was that such a mapping is possible.
that is, it turns out that there is a subset of the K verbs
from which the rest can be derived (with the help of a few
stack manipulation steps) in a very natural way.
my second surprise was that the only stack operation i needed
was 'pop'. all the rest can be derived with the help of the
list operations of K. (See the prelude for examples.) 'pop'
really is special!
F has four primitive combinators: ! (i), $ (dip), } (if-then)
and { (while).
surprise number 3 was that a nicely mnemonic mapping of
the core functions to symbols was possible. (opinions here
may differ!)
a symbol can be mnemonic in several ways:
(1) it's in common use for the associated function (e.g. +)
(2) the name of the symbol begins with the same letter as
the name of associated function (e.g. "$" for 'dip')
(3) the symbol is used for that function in K (e.g. "."
and "?")
(4) two symbols form a pair, and so do their functions
(e.g. "{" and "}" and 'while' and 'if'; "(" and ")" and
'unique' and 'group', &c.)
(5) the symbol "looks like" the behavior of the associated
function (e.g. "^" for 'uncons', since it splits a list into
two parts.)
surprise number 4 was that single-assignment semantics
can be enforced through a simple syntactic device, which
also allowed me to dispense with an assignment operator:
10 a
assigns the name 'a' to 10 if 'a' is unassigned; else
it places the value of 'a' on the stack. the value of
an unassigned name is ` (null):
a
`
surprise number 5 was that i could get so much mileage
out of the double-quote symbol """.
"blah blah blah"
is a comment. since the empty comment "" conveys no
useful information, i've used that as my "stop" operator.
moreover, since a comment has no effect on the stack,
i've defined the identity function as
[" "]id
i've also found ' useful -- the quote operator. so
for example,
'+
puts [+] on the stack, and
'[1 2 3]
puts [[1 2 3]] on the stack.
also note that the stack may contain naked primitives:
[+ 2]^
pushes + and [2] onto the stack, and that the combinators
treat them as though they were quoted:
2[3+]^head!
2 3 +
!
5
so: five design goals, five surprises, and five ways a
symbol can be mnemonic. behold the occult power of five!
documentation for F (not yet complete) is here:
http://www.nsl.com/papers/f.htm
the code is here:
http://www.nsl.com/k/f.k
and the prelude is here:
http://www.nsl.com/k/f/f.k
eventually, i'll have a go at implementing the Joy and K
combinators, and adding further examples.
concatenative@yahoogroups.com wrote on 06/18/2006 01:07:24 PM:
> i've wrapped up work on functional Falsei lied.
the implementation i described was a modification of one i wrote
for False, and was, for that very simple language, just adequate.
False has quotations, but contains no operators for constructing
or deconstructing them, so representing them as strings will suffice.
not so in F, and i should have realized that sooner.
so the revised implementation is completely different, and i've
taken the opportunity to clean up the design.
one major departure was to eliminate 'if' and 'while' as
primitives, and to define their Joy-like replacements in
the F prelude. so now the only combinators in F are ! (Joy's
'i') and $ (Joy's 'dip'):
[pair![dupd!]$'!$swap!not!pair!@!] cond "[i][t][f]cond!"
[[]cond!] if "[i][t]if!"
[unit!;dup![^^%]$[while!],,if!] while "[i][t]while!"
; is 'cons', ^ is 'uncons', % is 'pop', @ is 'index', and
'x
puts [x] on the stack. (note: 'cons' can be defined as
[[']$]$,
where , is 'append'.)
with these building blocks, it should be relatively easy to
write 'map', 'filter', and 'fold'.
http://www.nsl.com/papers/f.htm
> , which i'm calling
> "F", and i've started writing some simple programs in the
> language. for example, here's the factorial function in F:
>
> [dup!1=dup![swap!%1swap!]}not![dup!1sub!fac!*]}]fac
>
> not as concise as False, but some might think that a virtue. :)
>
> my design goals were:
>
> 1. F should be concatenative
> 2. F should be purely functional
> 3. F should include all the K verbs
> 4. no multi-symbol primitives
> 5. the symbols should be mnemonic
>
> i never thought that a complete mapping of K verbs to symbols
> was possible -- there are, after all, 40 K verbs and only 32
> symbols on the keyboard, and some of those are required for
> non-K operators.
>
> my first surprise, then, was that such a mapping is possible.
> that is, it turns out that there is a subset of the K verbs
> from which the rest can be derived (with the help of a few
> stack manipulation steps) in a very natural way.
>
> my second surprise was that the only stack operation i needed
> was 'pop'. all the rest can be derived with the help of the
> list operations of K. (See the prelude for examples.) 'pop'
> really is special!
>
> F has four primitive combinators: ! (i), $ (dip), } (if-then)
> and { (while).
>
> surprise number 3 was that a nicely mnemonic mapping of
> the core functions to symbols was possible. (opinions here
> may differ!)
>
> a symbol can be mnemonic in several ways:
>
> (1) it's in common use for the associated function (e.g. +)
>
> (2) the name of the symbol begins with the same letter as
> the name of associated function (e.g. "$" for 'dip')
>
> (3) the symbol is used for that function in K (e.g. "."
> and "?")
>
> (4) two symbols form a pair, and so do their functions
> (e.g. "{" and "}" and 'while' and 'if'; "(" and ")" and
> 'unique' and 'group', &c.)
>
> (5) the symbol "looks like" the behavior of the associated
> function (e.g. "^" for 'uncons', since it splits a list into
> two parts.)
>
> surprise number 4 was that single-assignment semantics
> can be enforced through a simple syntactic device, which
> also allowed me to dispense with an assignment operator:
>
> 10 a
>
> assigns the name 'a' to 10 if 'a' is unassigned; else
> it places the value of 'a' on the stack. the value of
> an unassigned name is ` (null):
>
> a
> `
>
> surprise number 5 was that i could get so much mileage
> out of the double-quote symbol """.
>
> "blah blah blah"
>
> is a comment. since the empty comment "" conveys no
> useful information, i've used that as my "stop" operator.
> moreover, since a comment has no effect on the stack,
> i've defined the identity function as
>
> [" "]id
>
> i've also found ' useful -- the quote operator. so
> for example,
>
> '+
>
> puts [+] on the stack, and
>
> '[1 2 3]
>
> puts [[1 2 3]] on the stack.
>
> also note that the stack may contain naked primitives:
>
> [+ 2]^
>
> pushes + and [2] onto the stack, and that the combinators
> treat them as though they were quoted:
>
> 2[3+]^head!
> 2 3 +
> !
> 5
>
> so: five design goals, five surprises, and five ways a
> symbol can be mnemonic. behold the occult power of five!
>
> documentation for F (not yet complete) is here:
>
> http://www.nsl.com/papers/f.htm
>
> the code is here:
>
> http://www.nsl.com/k/f.k
>
> and the prelude is here:
>
> http://www.nsl.com/k/f/f.k
>
> eventually, i'll have a go at implementing the Joy and K
> combinators, and adding further examples.
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>