We have seen in this group a functional ADT done with Shen tuples, and
one implemented with lists. I made an example of a functional Shen
program with ADTs implemented with Shen vectors. The demo program is
in the attachment mccpv.shen. (It is the McCulloch--Pitts neuron
program that I mentioned earlier.)
A sample run is below.
------------------------------------------------------------
antti@antti-HP-630-Notebook-PC:~/ShenADT$ ./Shen
Shen, copyright (C) 2010-2015 Mark Tarver
running under Common Lisp, implementation: CLisp
port 1.9 ported by Mark Tarver
(0-) (load "mccpv.shen")
type#aneuron
mk-aneuron
pNN
pNDoc
pInp
pWts
pActL
pNOut
sNN
sNDoc
sInp
sWts
sActL
sNOut
type#aneuron-net
<"McCullough-Pitts neuron" "Luger textbook 6th ed. Exercise #1, Ch. 11 neuron" [(@p 0 "neuron-input") (@p 0 "neuron-input") (@p 1 "bias")] [(@p -1 "neuron-input") (@p 1 "neuron-input") (@p 1 "bias")] 0 0>
transfer-function
activation-level-aux
activation-level-aux-h
thres-f
ann-demo
dn
dn
run time: 1.2120000086724758 secs
loaded
(1-) (ann-demo)
Give A: 1
Give B: 1
Neuron name:
McCullough-Pitts neuron
Neuron documentation:
Luger textbook 6th ed. Exercise #1, Ch. 11 neuron
Neuron inputs:
[(@p 1 "user-input") (@p 1 "user-input") (@p 1 "bias")]
Neuron weights:
[(@p -1 "neuron-input") (@p 1 "neuron-input") (@p 1 "bias")]
Neuron activation:
0
Neuron output:
0
Output of neuron: 1
[]
(2-) (ann-demo)
Give A: -1
Give B: -1
Neuron name:
McCullough-Pitts neuron
Neuron documentation:
Luger textbook 6th ed. Exercise #1, Ch. 11 neuron
Neuron inputs:
[(@p -1 "user-input") (@p -1 "user-input") (@p 1 "bias")]
Neuron weights:
[(@p -1 "neuron-input") (@p 1 "neuron-input") (@p 1 "bias")]
Neuron activation:
0
Neuron output:
1
Output of neuron: 1
[]
(3-) (ann-demo)
Give A: 1
Give B: -1
Neuron name:
McCullough-Pitts neuron
Neuron documentation:
Luger textbook 6th ed. Exercise #1, Ch. 11 neuron
Neuron inputs:
[(@p 1 "user-input") (@p -1 "user-input") (@p 1 "bias")]
Neuron weights:
[(@p -1 "neuron-input") (@p 1 "neuron-input") (@p 1 "bias")]
Neuron activation:
0
Neuron output:
1
Output of neuron: -1
[]
(4-) (QUIT)
antti@antti-HP-630-Notebook-PC:~/ShenADT$
------------------------------------------------------------
I had a problem with interfacing the input functions with the Shen
type system: With the OS Shen, the type system generates an error if
one calls (input) or (lineread), and the (read) returns an object of
type unit, which object I cannot assign into a number with the
let ...) form.
========================================
We have here seen that the same abstract datatype, the artificial
neuron, has been implemented:
I) with the Shen tuples; and,
II) with the Shen lists; and,
III) with the Shen vectors; and,
IV) it could be implemented with a dispatching lambda (the author will
leave this one for the reader as an exercise). Interestingly, calling
a lambda expression and executing a Shen (cases ...) could be cheaper
than eg taking apart a list and replacing one of its elements.
And all this has been done functionally, with the support of the type
system of Shen.
Indeed, the ADTs are a nice thing to have!
yours, A. J. Y.