Dylan (programming language)
Dylan is a multi-paradigm programming language that includes support for functional and object-oriented programming (OOP), and is dynamic and reflective while providing a programming model designed to support generating efficient machine code, including fine-grained control over dynamic and static behaviors. It was created in the early 1990s by a group led by Apple Computer. Dylan derives from Scheme and Common Lisp and adds an integrated object system derived from the Common Lisp Object System (CLOS). In Dylan, all values (including numbers, characters, functions, and classes) are first-class objects. Dylan supports multiple inheritance, polymorphism, multiple dispatch, keyword arguments, object introspection, pattern-based syntax extension macros, and many other advanced features. Programs can express fine-grained control over dynamism, admitting programs that occupy a continuum between dynamic and static programming and supporting evolutionary development (allowing for rapid prototyping followed by incremental refinement and optimization). Dylan's main design goal is to be a dynamic language well-suited for developing commercial software. Dylan attempts to address potential performance issues by introducing "natural" limits to the full flexibility of Lisp systems, allowing the compiler to clearly understand compilable units, such as libraries. Dylan derives much of its semantics from Scheme and other Lisps; some Dylan implementations were initially built within extant Lisp systems. However, Dylan has an ALGOL-like syntax instead of a Lisp-like prefix syntax. HistoryDylan was created in the early 1990s by a group led by Apple Computer. At one time in its development, it was intended for use with the Apple Newton computer, but the Dylan implementation did not reach sufficient maturity in time, and Newton instead used a mix of C and the NewtonScript developed by Walter Smith. Apple ended their Dylan development effort in 1995, though they made a "technology release" version available (Apple Dylan TR1) that included an advanced integrated development environment (IDE). Two other groups contributed to the design of the language and developed implementations: Harlequin released a commercial IDE for Microsoft Windows and Carnegie Mellon University released an open source compiler for Unix systems called Gwydion Dylan. Both of these implementations are now open source. The Harlequin implementation is now named Open Dylan and is maintained by a group of volunteers, the Dylan Hackers. The Dylan language was code-named Ralph. James Joaquin chose the name Dylan for "DYnamic LANguage." SyntaxMany of Dylan's syntax features come from its Lisp heritage. Originally, Dylan used a Lisp-like prefix syntax, which was based on s-expressions. By the time the language design was completed, the syntax was changed to an ALGOL-like syntax, with the expectation that it would be more familiar to a wider audience of programmers. The syntax was designed by Michael Kahl. It is described in great detail in the Dylan Reference Manual.[2] Lexical syntaxDylan is not case sensitive. Dylan's lexical syntax allows the use of a naming convention where hyphen (minus) signs are used to connect the parts of multiple-word identifiers (sometimes called "lisp-case" or "kebab case"). This convention is common in Lisp languages. Besides alphanumeric characters and hyphen-minus signs, Dylan allows a variety of non-alphanumeric characters as part of identifiers. Identifiers may not consist of these non-alphanumeric characters alone.[2] If there is any ambiguity, whitespace is used. Example codeA simple class with several slots: define class <point> (<object>)
slot point-x :: <integer>,
required-init-keyword: x:;
slot point-y :: <integer>,
required-init-keyword: y:;
end class <point>;
By convention, classes are named with less-than and greater-than signs used as angle brackets, e.g. the class named In To make an instance of make(<point>, x: 100, y: 200)
define class <point> (<object>)
slot point-x;
slot point-y;
end;
The slots are now both typed as let p = make(<point>);
point-x(p) := 100; // or p.point-x := 100;
point-y(p) := 200; // or p.point-y := 200;
By convention, constant names begin with "$": define constant $pi :: <double-float> = 3.1415927d0;
A factorial function: define function factorial (n :: <integer>) => (n! :: <integer>)
case
n < 0 => error("Can't take factorial of negative integer: %d\n", n);
n = 0 => 1;
otherwise => n * factorial(n - 1);
end
end;
Here, There is no explicit return statement. The result of a method or function is the last expression evaluated. It is a common style to leave off the semicolon after an expression in return position. Modules vs. namespaceIn many object-oriented languages, classes are the main means of encapsulation and modularity; each class defines a namespace and controls which definitions are externally visible. Further, classes in many languages define an indivisible unit that must be used as a whole. For example, using a Some languages, including Dylan, also include a separate, explicit namespace or module system that performs encapsulation in a more general way. In Dylan, the concepts of compile-unit and import-unit are separated, and classes have nothing specifically to do with either. A library defines items that should be compiled and handled together, while a module defines a namespace. Classes can be placed together in modules, or cut across them, as the programmer wishes. Often the complete definition for a class does not exist in a single module, but is spread across several that are optionally collected together. Different programs can have different definitions of the same class, including only what they need. For example, consider an add-on library for regex support on Under Dylan, many interfaces can be defined for the same code, for instance the String concatenation method could be placed in both the String interface, and the "concat" interface which collects together all of the different concatenation functions from various classes. This is more commonly used in math libraries, where functions tend to be applicable to widely differing object types. A more practical use of the interface construct is to build public and private versions of a module, something that other languages include as a bolt on feature that invariably causes problems and adds syntax. Under Dylan, every function call can be simply placed in the "Private" or "Development" interface, and collect up publicly accessible functions in ClassesClasses in Dylan describe define class <window> (<view>)
slot title :: <string> = "untitled", init-keyword: title:;
slot position :: <point>, required-init-keyword: position:;
end class;
In this example, the class " In languages such as C++ or Java, the class would also define its interface. In this case the definition above has no explicit instructions, so in both languages access to the slots and methods is considered In Dylan, these sorts of visibility rules are not considered part of the code, but of the module/interface system. This adds considerable flexibility. For instance, one interface used during early development could declare everything public, whereas one used in testing and deployment could limit this. With C++ or Java these changes would require changes to the source code, so people won't do it, whereas in Dylan this is a fully unrelated concept. Although this example does not use it, Dylan also supports multiple inheritance. Methods and generic functionsIn Dylan, methods are not intrinsically associated with any specific class; methods can be thought of as existing outside of classes. Like CLOS, Dylan is based on multiple dispatch (multimethods), where the specific method to be called is chosen based on the types of all its arguments. The method need not be known at compile time, the understanding being that the required function may be available, or not, based on a user's preferences. Under Java the same methods would be isolated in a specific class. To use that functionality the programmer is forced to import that class and refer to it explicitly to call the method. If that class is unavailable, or unknown at compile time, the application simply won't compile. In Dylan, code is isolated from storage in functions. Many classes have methods that call their own functions, thereby looking and feeling like most other OO languages. However code may also be located in generic functions, meaning they are not attached to a specific class, and can be called natively by anyone. Linking a specific generic function to a method in a class is accomplished thusly: define method turn-blue (w :: <window>)
w.color := $blue;
end method;
This definition is similar to those in other languages, and would likely be encapsulated within the The utility of generic methods comes into its own when you consider more "generic" examples. For instance, one common function in most languages is the ExtensibilityThis whole concept might strike some readers as very odd. The code to handle The implication here is that a programmer can add functionality to existing classes by defining functions in a separate file. For instance, you might wish to add spell checking to all Apple DylanApple Dylan is the implementation of Dylan produced by Apple Computer. It was originally developed for the Apple Newton product. References
External links
|
Portal di Ensiklopedia Dunia