Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Dylan (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Syntax== Many of Dylan's syntax features come from its Lisp heritage. Originally, Dylan used a Lisp-like prefix syntax, which was based on [[s-expression]]s. 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.<ref name="refman"/> ===Lexical syntax=== Dylan is not [[Case sensitivity|case sensitive]]. Dylan's [[lexical syntax]] allows the use of a naming convention where [[hyphen-minus|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.<ref name="refman"/> If there is any ambiguity, whitespace is used. ===Example code=== A simple class with several slots: <syntaxhighlight lang="dylan"> define class <point> (<object>) slot point-x :: <integer>, required-init-keyword: x:; slot point-y :: <integer>, required-init-keyword: y:; end class <point>; </syntaxhighlight> By convention, classes are named with less-than and greater-than signs used as [[angle bracket]]s, e.g. the class named <code><point></code> in the code example. In <code>end class <point></code> both <code>class</code> and <code><point></code> are optional. This is true for all <code>end</code> clauses. For example, you may write <code>end if</code> or just <code>end</code> to terminate an <code>if</code> statement. To make an instance of <code><point></code>: <syntaxhighlight lang="dylan"> make(<point>, x: 100, y: 200) </syntaxhighlight> The same class, rewritten in the most minimal way possible: <syntaxhighlight lang="dylan"> define class <point> (<object>) slot point-x; slot point-y; end; </syntaxhighlight> The slots are now both typed as <code><object></code>. The slots must be initialized manually: <syntaxhighlight lang="dylan"> let p = make(<point>); point-x(p) := 100; // or p.point-x := 100; point-y(p) := 200; // or p.point-y := 200; </syntaxhighlight> By convention, constant names begin with "$": <syntaxhighlight lang="dylan"> define constant $pi :: <double-float> = 3.1415927d0; </syntaxhighlight> A factorial function: <syntaxhighlight lang="dylan"> 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; </syntaxhighlight> Here, <code>n!</code> and <code><integer></code> are just normal identifiers. 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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Dylan (programming language)
(section)
Add topic