Hannes Mehnert [email protected] December
Total Page:16
File Type:pdf, Size:1020Kb
Introduction Dylan Going Further Dylan Hannes Mehnert [email protected] December 16, 2004 Hannes Mehnert [email protected] Dylan Introduction Dylan Going Further Introduction Overview Hello World History Dylan Libraries and Modules Classes Generic Functions Types Sealing Going Further Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History Overview I DYnamic LANguage Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History Overview I DYnamic LANguage I Object Oriented: everything is an object Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History Overview I DYnamic LANguage I Object Oriented: everything is an object I Safe: type-checking of arguments and values, no buffer overruns, no implicit casting, no raw pointers Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History Overview I DYnamic LANguage I Object Oriented: everything is an object I Safe: type-checking of arguments and values, no buffer overruns, no implicit casting, no raw pointers I Efficient: can compile to code nearly as efficient as C Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History Hello world define method hello-world () format-out(``Hello world\n''); end method; Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History factorial define method factorial ( i ) if (i = 0) 1 else i * factorial( i - 1) end if end method; Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History History I Created by Apple Computer in the early 1990's Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History History I Created by Apple Computer in the early 1990's I sold as Technology Release by Apple in 1995 Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History History I Created by Apple Computer in the early 1990's I sold as Technology Release by Apple in 1995 I CMU created Gwydion Dylan 1994 which is open source and maintained by Gwydion Dylan Maintainers (from USA, Germay, Japan, New Zealand, Hawaii,...) Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History History I Created by Apple Computer in the early 1990's I sold as Technology Release by Apple in 1995 I CMU created Gwydion Dylan 1994 which is open source and maintained by Gwydion Dylan Maintainers (from USA, Germay, Japan, New Zealand, Hawaii,...) I Harlequin developed Harlequin Dylan, now called Functional Developer, owned by Functional Objects, since 9 months open source (also maintained by Geydion Dylan Maintainers) Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History Dylan roots I Dylan was developed with object-orientated ideas from Lisp and smalltalk Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History Dylan roots I Dylan was developed with object-orientated ideas from Lisp and smalltalk I But Syntax looks more like Pascal Hannes Mehnert [email protected] Dylan Introduction Overview Dylan Hello World Going Further History Dylan roots I Dylan was developed with object-orientated ideas from Lisp and smalltalk I But Syntax looks more like Pascal I Unlike C and C++, Dylan uses no malloc() and free(), it has a garbage collector; no double-free bugs Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Libraries I Each Dylan program consist of one ore more Libraries Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Libraries I Each Dylan program consist of one ore more Libraries I Libraries are the unit of compilation and boundaries of optimizations Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Libraries I Each Dylan program consist of one ore more Libraries I Libraries are the unit of compilation and boundaries of optimizations I Libraries contain modules Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Library hello define library hello use common-dylan; use io; export hello-world; end library; Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Modules I Modules are namespaces Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Modules I Modules are namespaces I Binding names are defined in a module Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Modules I Modules are namespaces I Binding names are defined in a module I Modules import names from other modules, and export names of bindings defined within Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Modules I Modules are namespaces I Binding names are defined in a module I Modules import names from other modules, and export names of bindings defined within I Bindings that aren't exported are only visible in the module Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Module hello-world define module hello-world use common-dylan; use format-out; export hello-world; end module; Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Importing, Exporting and Renaming use common-dylan, import: all; use streams, import: { <string-stream> }; use io, exclude: { flush, seek }; use dylan, rename: { sort => dylan-sort }; use xml-parser, prefiz: ``xml-''; use png-utils, export: { decode-png }; Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Interfaces I Many Dylan libraries only contain one module Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Interfaces I Many Dylan libraries only contain one module I Libraries may define several export modules that represent different \interfaces" on the same functionality, similar to c++'s public:, private:, and protected: Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Library plug-in define library plug-in use dylan; export plug-in, plug-in-implementor; end library; Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Module plug-in define module plug-in use dylan; create <plug-in>, load-plug-in, plug-in-action, unload-plug-in; create plug-in-name; end module; Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Module plug-in-implementor define module plug-in-implementor use dylan; create <simple-plug-in>, do-load-plug-in, do-plug-in-action, do-unload-plug-in; end module; Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Classes I Classes define a type in the class hierarchy, and storage for object state, called "slots" Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Classes I Classes define a type in the class hierarchy, and storage for object state, called "slots" I Every instance object has a class Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Classes I Classes define a type in the class hierarchy, and storage for object state, called "slots" I Every instance object has a class I Classes have no member functions Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Classes I Classes define a type in the class hierarchy, and storage for object state, called "slots" I Every instance object has a class I Classes have no member functions I Classes are not namespaces (modules are) Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Classes I Classes are types. There are also types that are not classes. Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Classes I Classes are types. There are also types that are not classes. I There is a root class "<object>". It is the root of the class and type hierarchy. Hannes Mehnert [email protected] Dylan Libraries and Modules Introduction Classes Dylan Generic Functions Going Further Types Sealing Classes I Classes are types. There are also types that are not classes. I There is a root class "<object>". It is the root of the class and