A_LispKit Lisp PROGRAMMING LANGUAGE, A

0 downloads 0 Views 181KB Size Report
MODIFIKACIJA METODE DENOTACIJSKOG OPISA. SEMANTIKE ZA .... Some chosen words from this set are the numbers or numeric atoms. There are three ...
Jerinić, Lj., A_LispKit Lisp Programming Language, a Modified Denotational Semantics Approach. In Proceedings of the 37th Conference of Electronics, Telecommunications, Automation and Nuclear engineering (20th - 23rd September, Belgrade, Yugoslavia). Belgrade, 1993, Part VIII, pp. 345 - 351.

Jerinic Ljubomir1 Institute of Mathematics Trg Dositeja Obradovica 4 21000 Novi Sad, Yugoslavia

A_LispKit Lisp PROGRAMMING LANGUAGE, A MODIFIED DENOTATIONAL SEMANTICS APPROACH MODIFIKACIJA METODE DENOTACIJSKOG OPISA SEMANTIKE ZA A_LispKit Lisp PROGRAMSKI JEZIK ABSTRACT A_LispKit Lisp programming language is described in terms of a modified denotational semantics approach. The functional programming language A_LispKit Lisp, developed in the Institute of Mathematics Novi Sad in 1991/92, is described, by a new technique of the defining semantics - denotational approach combined with some object oriented view.

SADRŽAJ U radu je opisana semantika A_LispKit Lisp programski jezik upotrebom modifikovane metode denotacijske semantike. _isto funkcionalni programski jezik A_LispKit Lisp, razvijen na Institutu za matematiku, Univerziteta u Novom Sadu tokom 1991/92 godine, je opisan uvodjenjem objektno orijentisanog pristupa u pozanatu metodu denotacijskog opisa semantike programskih jezika.

1. FUNCTIONAL PROGRAMMING LANGUAGES (FPL) FPL [Ba78, La64, McC60, PaJo87, Tu79] are special kind of applicative programming languages which are based on the mathematical definition of functions. The name - functional, is used because in these programming languages a function (definition and application) is dominant, like an assignment statement in conventional imperative programming language. FPL is more problem oriented then the conventional languages. They have a simple mathematical basis λ calculus, and the program in FPL and its data are of the same form. FPL consist of four components: set of data, function call - applicative operation, set of primitive functions (built-in functions), and the set of functional forms.

2. A_LispKit Lisp LANGUAGE In 1984 in the Institute of Mathematics Novi Sad, a first FPL was designed [St84], following the results of P. Henderson and his group [He80, He83], naturally involving some new results [Je83, St84], such as incorporating of real arithmetic, generalizing some primitive functions , etc. All these extensions has naturally led to a new stage of investigation - definition of a completely new functional language called A_LispKit Lisp language [Je92a, Je92b, Je92c, Je92d, Je92e], which is similar to a modern FPL [Tu85]. The most important differences of A_LispKit Lisp from previous language are: - Completely new syntax and semantics, 1

This research was supported by Science Fund of Serbia

- Different method of implementing based on: environment - SECD method or/and combinatory logic - graph reduction concept, - Syntax and semantics control during compilation time, - Possibility of defining and using functional libraries, - Implementing mechanism - "lazy evaluation" or call-by-need, - Implementations of some built-in functions for interactive work, and so on.

3. SYNTAX AND SEMANTICS OF A_LispKit Lisp LANGUAGE The complete syntax of A_LispKit Lisp language, in extended Backus - Naur form is: := '{' ('Where''WhereRec') ('=''ImportFrom''@') {'And'('=''ImportFrom''@')} '}'. := [ ]. := '='  '='  ''  '='  '> s2  L_SExp(N_Value(s1) > N_Value(s2)), s1, s2  Numeric, s1 = s2  L_SExp(N_Value(s1)  N_Value(s2)), s1, s2  Numeric, s1 => s2  L_SExp(N_Value(s1)  N_Value(s2)), s1, s2  Numeric, where { , _, , ,  } denote the appropriate relational operations in the implementation language. Sequence(s1,s2,...,sk)  Value(Value(s1),Value(s2),...,Value(sk)), si  , i=1, ..., k. Eval(e1, e2)  Value(e1(Value(e2)), ei  , i=1,2. Head(s)  {

Value(s1), s  Constructor, s  (s1.p), p   ?, else.

Car(s)  {

Value(s1), s  Constructor, s  (s1.p), p   ?, else.

Tail(s)  {

Value(s1), s  Constructor, s  (p.s1), p   ?, else.

Cdr(s)  {

Value(s1), s  Constructor, s  (s1.p), p  

?, else. C{ad}r(s)  Value(Value(C{ad}r(Value(C{ad}r(...Value(C{ad}r(s)...))), where s  Constructor. Atom(s)  L_SExp(Value(s)), s  , L_SExp(Value(s)) = 'T, if s  Atoms  {NIL}, else 'F. Null(s)  L_SExp(Value(s)), s  , L_SExp(Value(s)) = 'T, if s  NIL, else 'F. If l Then s1 Else s2  (Value(s3))  (L_SExp(l)  'T  s3  s1)  (L_SExp(l)  'F  s3  s2)  (Value(s3)  ?, else), where l  Logical, and s1, s2, s3  . Case

l1 : s1 ... or lk : sk other sk+1 EndCase  Value(sk+2), where li  Logic, i = 1, ..., k+1, sj  , j = 1, ..., k+2, and

L_SExp(l1)  'T  sk+2  s1, ... L_SExp(lk)  'T  sk+2  sk, or sk+2  sk+1.

f = Lambda(x1, x2, ..., xn) e  f _ Value( [ e ] ρ), where the context ρ is: ρ{x1 _ Value(x1), x2 _ Value(x2),..., xn _ Value(xn)}, e  , xi  , i=1,..., n, i  N  {0}, and the symbol _ denotes the binding operations, i.e. the binding of a variable to a value. f(x1, x2, ..., xn)  Value( [ e ] ρ), where a function f is define with f = Lambda(x1, x2, ..., xn) e, and a context ρ  {x1 _ Value(x1), x2 _ Value(x2), ..., xn _ Value(xn)}. { E Where{Rec} I1 = (e1  ImportFrom Lib1  @Fun) And I2 = (e2  ImportFrom Lib2  @Fun) And ... And In = (en  ImportFrom Libn  @Fun) }  Value( [ E ] ρ), where ρ  {I1 _ Value(e1), I2 _ Value(e2), ..., In _ Value(en)}.

5. FORMAL SEMANTICS THEOREMS OF A_LispKit Lisp PRIMITIVES Now, we can define and prove some semantics theorems: Theorem 1. (  s1, s2   )  Head(Cons(s1, s2))  s1.  Proof. (  s1, s2   )  Cons(s1, s2)  (s1.s2)  Head(s1.s2)  s1 . Theorem 2. (  s1, s2   )  Tail(Cons(s1, s2))  s2.  Proof. (  s1, s2   )  Cons(s1, s2)  (s1.s2)  Tail(s1.s2)  s2 . Theorem 3. 'T # 'T  'T.  Proof. 'T # 'T  Value-1(L_SExp('T)  L_SExp('T)), (a) as semantics definition of Quote is Quote(s)  Value(L_SExp(s)), s  Logic, then from (a) is: Value-1(L_SExp('T  'T))  Value-1(L_SExp(Value(T)  Value(T))), T  Logic. (b) As we also define that Value(T)  True, T  Logic, L_SExp(True)  T, T  Logic, Value-1(T)  'T, (c) where True is a logically true value in the implementation language. Form (b) and (c) follows: Value-1(L_SExp(Value(T)  Value(T))  Value-1(L_SExp(True  True))  Value-1 (L_SExp(True))  Value-1(T)  'T, -1 -1 where Value is the inverse function of the function Value defined by: Value : _ {  _ ...  _ } , and _ is the set of all values of implementation object LispCell by which are realized the data type .  Similarly, the following theorems can be easily proved: Theorem 4. 'T # 'F  'T.  Theorem 5. 'F # 'T  'T.  Theorem 6. 'F # 'F  'F.  Theorem 7. 'T & 'T  'T. 

Theorem 8. 'F & 'T  'F.  Theorem 9. 'T & 'F  'F.  Theorem 10. 'F & 'F  'F.  Theorem 11. Atom(Cons(s1,s2))  ('F).  Proof. From semantics definition of the function Cons follows: (  s1, s2   )  Cons(s1, s2)  (s1.s2), and from the semantics definition of the function Atom follows: (  s1, s2   )  Atom(Cons(s1, s2))  Atom((s1.s2))  L_SExp(Value((s1.s2)))  'F, because (s1.s2)  Constructor. Theorem 12. Atom(s)  ('T), (  s  Atoms ). The proof of this theorem is similar to the proof of Theorem 11.

6. CONCLUSION The approach to the definition of the semantics of a FPL, based on the introduced denotational methods, has an advantage over the traditional way of semantics definition, in its strict mathematical view. This approach is very suitable for the application in axiomatic definition of a programming language, because it is easy to construct and prove a lot of theorems which hold in that programming language. Also, the implementation of some FPL, using the above definition of the semantics objects and appropriate operation is very suitable for the efficient realization that FPL, based on the object LispCell [Je92a, Je92e].

REFERENCES [Ba78]Backus J., " Can Programming Be Liberated from the von Neumann Style? A Functional Style and Its Algebra of Programs ", Comm. of the ACM, Vol. 21 No 8, pp. 613-641, 1978. [Ca84]Cardelli L., "Compiling a Functional Language", Proc. of the ACM Symp. on Lisp and Fun. Prog., Austin, pp. 208-217, 1984. [Fa85]Fairbairn J., Design and implementation of a simple typed language based on the lambda calculus, PhD thesis, Tehnical Report 75, University of Cambridge, 1985. [He80]Henderson P., Functional Programming: Application and Implementation, Prentice Hall, New York, 1980. [He83]Henderson P., Jones G. A., Jones S. B., The LispKit Lisp Manual, Tecnnical Monograph PRG-32(1), Oxford, 1983. [Je83]Jerinic Lj., Stojkovic V., "An Extension of LispKit Lisp Language Version ARL by the Generalized Functions and Their Implementation", Rew. of Res. Ser. Mat. Vol. 13, 389-404, 1983. [Je92a]Jerinic Lj., "A_LispKit Lisp - Description and Implementation", Informatica, Ljubljana (in print), 1992. [Je92b]Jerinic Lj., "Functional Programming Language A_LispKit Lisp", Rew. of Res. Ser. Mat. (in print), 1992. [Je92c]Jerinic Lj., "A_LispKit Lisp Demand Evaluation", Rew. of Res. Ser. Mat. (in print). [Je92d]Jerinic Lj., "Functional Library Manager for A_LispKit Lisp Programming Language", Builletins for Applied mathematics, Budapest, pp. 53-62, 1992. [Je92e]Jerinic Lj., Implementation of a Translator for Lisp-Like Programming Language by Using the Attribute Grammar, Master Thesis, University of Novi Sad, Novi Sad, 247 pages, (in Serbian), 1992. [Jo84]Johansson T., "Efficient compilation of lazy evaluation", Proc. of the ACM Conf. on Compiler Construction, Montreal, pp. 58-69, 1984. [La64]Landin P. J.,"The mechanical evaluation of expressions", Computer Journal, Vol. 6, pp. 308-320, 1964. [McC60]McCharty J., The LISP Programmer's Manual, MIT Computation Center, 1960. [PaJo87]Payton Jones S. L., The Implementation of Functional Programming Languages, Prentice Hall, New York, 1987. [St83]Stojkovic V., Jerinic Lj., "An extension of LispKit Lisp language", Proc. of VII Balkan congress of math. Athens, pp. 186-195, 1983. [St84]Stojkovic V., Mircevski J., Jerinic Lj., Stojmenovic I., "LispKit Lisp language - version ARL" (in Serbian), Bulletin of the Region Department of Informatic Novi Sad, pp. 55-61, 1984. [Tu79]Turner D. A., "A New Implementation Technique for Applicative Languages", Software Practice and Experience, Vol. 9, pp. 31-49.

[Tu85]Turner D. A., "Mirinda - a non-strict functional language with polymorphic types", in Conference on Functional Programming Languages and Computer Architecture, Nency Jouannaud (ed.), LNCS 201, Springer Verlag, pp. 1-16, 1985. [Wad71]Wadsworth C. P., Semantics and pragmatics of the lambda calculus, Chapter 4, PhD thesis, Oxford, 1971.