I am tempted to reply in detail to the proposed ‘abstract’ data type ‘stack’, but I shall refrain from doing so.
The implementation is very much a ‘concrete’ data type – stack implemented as a list! Not abstract at all!
It is completely insecure, because knowing what the implementation is, I can get hold of the element below the top by invoking (nth 2 stack), or whatever.
In Shen, not everything that is listed under the dataype heading makes an abstract data type. As a matter of fact, and Mark was very kind not to point this out, what is listed under datatype stack is completely redundant, as it does not convey any information to the Shen system. (Just as in the attempted ‘abstract’ data type, complex, proposed by the same author a couple of months ago).
An abstract data type, mathematically speaking, is a rather difficult concept. It requires knowledge of algebraic structures and operations (homomorphisms).
Implementing an abstract data type in a programming language, basically, amounts to restricting the user to the operations that are associated with the data type. This is often not so easy, especially when the code cannot be hidden.
In C/C++, there is a public interface (a .h file) which informs the user of the syntax and functionality of the available functions. The actual code is contained in a .c or .c++ file not seen by the user.
In Shen, certainly in the OS version, the source code of all libraries is publicly available, and implementation details are readily available, and could be exploited for nefarious purposes.
Implementing data types by means of absvectors makes such a practice much more difficult. absvectors, in Shen come very close to a (readable) and secure implementation of abstract data types.
--
You received this message because you are subscribed to a topic in the Google Groups "Shen" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/qilang/UEJyD7W7iBQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to qilang+unsubscribe@googlegroups.com.
To post to this group, send email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.
(datatype rules-00 PUSH : (A --> (list A) --> (list A)); TOP : ((list A) --> A); POP : ((list A) --> (list A)); DATA : (list A); ================================================== [stack DATA [POP TOP PUSH]] : (stack A);)
(datatype rules-01 PUSH : (string --> string --> string); TOP : (string --> string); POP : (string --> string); DATA : string; ================================================== [stack DATA [POP TOP PUSH]] : (stack string);)
\\ Abstract API boilerplate
(define stack-push { A --> (stack A) --> (stack A) } A [stack S [P T Push]] -> [stack (Push A S) [P T Push]])
\\ Instances
(define empty-string-stack { --> (stack string) } -> [stack "" [(function tlstr) (function hdstr) (function cn)]])
(define empty-list-stack { --> (stack A) } -> [stack [] [(function tail) (function head) (function cons)]])
\\ Test
(stack-push "a" (stack-push "b" (empty-string-stack))) (stack-push "a" (stack-push "b" (empty-list-stack)))
By hiding inessential information on how the abstract datatype is implemented and allowing access to the data structure only through the accessor functions, abstract datatypes build a barrier of abstraction between the essential properties of the datatype and the accidental properties of how we choose to implement it. This in turn, reduces information load and allows flexibility in making changes to the representation without having to rewrite large stretches of code.
TBoS p 250
Mark
The value of ADTs in Shen is that of other languages; TBoS explains it in a paragraph.
The value of ADTs in Shen is that of other languages; TBoS explains it in a paragraph.By hiding inessential information on how the abstract datatype is implemented and allowing access to the data structure only through the accessor functions, abstract datatypes build a barrier of abstraction between the essential properties of the datatype and the accidental properties of how we choose to implement it. This in turn, reduces information load and allows flexibility in making changes to the representation without having to rewrite large stretches of code.