Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Dylan (programming language)
(section)
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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)