All Topics  
D (programming language)

 

   Email Print
   Bookmark   Link






 

D (programming language)



 
 
The D programming language, also known simply as D, is an object-oriented
Object-oriented programming

Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
, imperative
Imperative programming

In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state ....
, multi-paradigm
Multi-paradigm programming language

A multi-paradigm programming language is a programming language that supports more than one programming paradigm. As Lead designer Tim Budd holds it: The idea of a multiparadigm language is to provide a framework in which programmers can work in a variety of styles, freely intermixing constructs from different paradigms. The design goal...
 system programming language
System programming language

System programming languages are programming languages that are static typing, allow arbitrarily complex data structures, compiled language, and meant to operate largely independently of other programs....
 by Walter Bright
Walter Bright

Walter Bright is a computer programmer known for being the designer of the D . He was also the main developer of the first native C++ compiler, Zortech C++ ....
 of Digital Mars
Digital Mars

Digital Mars is a small United States software company owned by Walter Bright that makes C and C++ compilers for Microsoft Windows and DOS. They also distribute the compilers for free on their web site....
. It originated as a re-engineering of C++
C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
, but even though it is predominantly influenced by that language, it is not a variant of it. D has redesigned some C++ features and has been influenced by concepts used in other programming languages, such as Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, C# and Eiffel
Eiffel (programming language)

Eiffel is an International Organization for Standardization-standardized, object-oriented programming language designed to enable programmers to efficiently develop extensible, reusable, reliable software....
. A stable version, 1.0, was released on January 2, 2007.






Discussion
Ask a question about 'D (programming language)'
Start a new discussion about 'D (programming language)'
Answer questions from other users
Full Discussion Forum



Encyclopedia


The D programming language, also known simply as D, is an object-oriented
Object-oriented programming

Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
, imperative
Imperative programming

In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state ....
, multi-paradigm
Multi-paradigm programming language

A multi-paradigm programming language is a programming language that supports more than one programming paradigm. As Lead designer Tim Budd holds it: The idea of a multiparadigm language is to provide a framework in which programmers can work in a variety of styles, freely intermixing constructs from different paradigms. The design goal...
 system programming language
System programming language

System programming languages are programming languages that are static typing, allow arbitrarily complex data structures, compiled language, and meant to operate largely independently of other programs....
 by Walter Bright
Walter Bright

Walter Bright is a computer programmer known for being the designer of the D . He was also the main developer of the first native C++ compiler, Zortech C++ ....
 of Digital Mars
Digital Mars

Digital Mars is a small United States software company owned by Walter Bright that makes C and C++ compilers for Microsoft Windows and DOS. They also distribute the compilers for free on their web site....
. It originated as a re-engineering of C++
C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
, but even though it is predominantly influenced by that language, it is not a variant of it. D has redesigned some C++ features and has been influenced by concepts used in other programming languages, such as Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, C# and Eiffel
Eiffel (programming language)

Eiffel is an International Organization for Standardization-standardized, object-oriented programming language designed to enable programmers to efficiently develop extensible, reusable, reliable software....
. A stable version, 1.0, was released on January 2, 2007. An experimental version, 2.0, was released on June 17, 2007.

Features

D is being designed with lessons learned from practical C++ usage rather than from a theoretical perspective. Even though it uses many C/C++ concepts it also discards some, and as such is not strictly backward compatible with C/C++ source code. It adds to the functionality of C++ by also implementing design by contract
Design by contract

Design by Contract or Programming by Contract is an approach to designing computer software. It prescribes that software designers should define Formal methods, precise and verifiable interface specifications for Component-based software engineering#Software component based upon the theory of abstract data types and the conceptual metaph...
, unit test
Unit test

In computer programming, unit testing is a software design and development method where the programmer gains confidence that individual units of source code are fit for use....
ing, true modules, garbage collection
Garbage collection (computer science)

In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage , or memory used by Object that will never be accessed or mutated again by the Application software....
, first class
First-class object

In computing, a first-class object , in the context of a particular programming language, is an entity which can be used in programs without restriction ....
 array
Array

In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory....
s, associative array
Associative array

An associative array is an abstract data type composed of a Collection of unique keys and a collection of values, where each key is associated with one value ....
s, dynamic array
Dynamic array

In computer science, a dynamic array, growable array, resizable array, dynamic table, or array list is an array data structure that can be resized and allows elements to be added or removed....
s, array slicing
Array slicing

In computer programming, array slicing is an operation that extracts certain elements from an array and packages them as another array, possibly with different number of indices and different index ranges....
, nested function
Nested function

In computer programming, a nested function is a subroutine which is lexically encapsulated within another function. It can only be called by the enclosing function or by functions directly or indirectly nested within the same enclosing function....
s, inner class
Inner class

In object-oriented programming, an inner class is a class declared entirely within the body of another class or interface.Inner classes became a feature of the Java starting with version 1.1....
es, closure
Closure (computer science)

In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables....
s, anonymous functions, compile time function execution
Compile time function execution

Compile time function execution is the ability of a compiler, that would normally compile a function to machine code and execute it at run time, to execute the function at compile time....
, lazy evaluation
Lazy evaluation

In computer programming, lazy evaluation is the technique of delaying a computation until such time as the result of the computation is known to be needed....
 and has a reengineered template
Generic programming

Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters and was pioneered by Ada which appeared in 1983....
 syntax. D retains C++'s ability to do low-level coding
Low-level programming language

In computer science, a low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture....
, and adds to it with support for an integrated inline
Inline assembler

In computer programming, the inline assembler is a feature of some compilers that allows very low level code written in Assembly Language to be embedded in a high level language like C or Ada programming language....
 assembler
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
. C++ multiple inheritance
Multiple inheritance

Multiple inheritance refers to a feature of some object-oriented programming programming languages in which a class can inheritance behaviors and features from more than one superclass ....
 is replaced by Java style single inheritance
Multiple inheritance

Multiple inheritance refers to a feature of some object-oriented programming programming languages in which a class can inheritance behaviors and features from more than one superclass ....
 with interfaces
Interface (computer science)

Interface generally refers to an Abstraction_%28computer_science%29 that an entity provides of itself to the outside. This separates the methods of external communication from internal operation, and allows it to be internally modified without affecting the way outside entities interact with it, as well as provide Polymorphism in object-orien...
 and mixin
Mixin

In object-oriented programming languages, a mixin is a class that provides a certain functionality to be Inheritance by a subclass, but is not meant to stand alone....
s. D's declaration, statement and expression syntax
Syntax

In linguistics, syntax is the study of the principles and rules for constructing Sentence s in natural languages. In addition to referring to the discipline, the term syntax is also used to refer directly to the rules and principles that govern the sentence structure of any individual language, as in "the Irish syntax"....
 closely matches that of C++.

The inline assembler typifies the differences between D and application languages like Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
 and C#. An inline assembler lets programmers enter machine-specific assembly
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
 code in with standard D code—a technique often used by system programmers to access the low-level features of the processor
Central processing unit

A central processing unit is an electronic circuit that can execute computer programs. This broad definition can easily be applied to many early computers that existed long before the term "CPU" ever came into widespread usage....
 needed to run programs that interface directly with the underlying hardware
Hardware

Hardware is a general term that refers to the physical cultural artifacts of a technology. It may also mean the physical components of a computer system, in the form of computer hardware....
, such as operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
s and device driver
Device driver

In computing, a device driver or software driver is a computer program allowing higher-level computer programs to interact with a hardware device....
s.

D has built-in support for documentation comments, but so far only the compiler supplied by Digital Mars implements a documentation generator
Documentation generator

A documentation generator is a programming tool that generates documentation intended for programmers or end users , or both, from a set of specially comment ed source code files, and in some cases, binary files....
.

Programming paradigms

D supports three main programming paradigms
Programming paradigm

A programming paradigm is a fundamental style of computer programming. . Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation ....
imperative
Imperative programming

In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state ....
, object-oriented, and metaprogramming
Metaprogramming

Metaprogramming is the writing of computer programs that write or manipulate other programs as their data, or that do part of the work at runtime that would otherwise be done at compile time....
.

Imperative
Imperative programming in D is almost identical to C. Functions, data, statements, declarations and expressions work just as in C, and the C runtime library can be accessed directly. Some notable differences between D and C in the area of imperative programming include D's foreach
Foreach

For each is a computer language idiom for traversing items in a Collection class. Foreach is usually used in place of a standard for loop statement ....
 loop construct, which allows looping over a collection, and nested function
Nested function

In computer programming, a nested function is a subroutine which is lexically encapsulated within another function. It can only be called by the enclosing function or by functions directly or indirectly nested within the same enclosing function....
s, which are functions that are declared inside of another and may access the enclosing function's local variable
Local variable

In computer science, a local variable is a variable that is given local scope . Such a variable is accessible only from the subroutine or statement block in which it is declared....
s.

Object oriented
Object oriented programming in D is based on a single inheritance hierarchy, with all classes derived from class Object. D does not support multiple inheritance; instead, it uses Java-style interfaces
Interface (Java)

An interface in the Java is an abstract type that is used to specify an interface that class must implement. Interfaces are declared using the interface Java keywords, and may only contain Method signatures and constant declarations ....
, which are comparable to C++ pure abstract classes.

Metaprogramming
Metaprogramming is supported by a combination of templates, compile time function execution, tuple
Tuple

In mathematics, a tuple is a sequence of a specific number of values, called the components of the tuple. These components can be any kind of mathematical objects, where each component of a tuple is a value of a specified type....
s, and string mixins. The following examples demonstrate some of D's compile-time features.

Templates in D can be written in a more function-like style than those in C++. Here the use of static if, D's compile-time conditional construct, is demonstrated to construct a factorial
Factorial

In mathematics, the factorial of a negative and non-negative numbers integer n, denoted by n!, is the Product of all positive integers less than or equal to n....
 template.

template Factorial(ulong n)



This is a regular function that performs the same calculation. The template version's code is similar to that of this function.

ulong factorial(ulong n)



In the following two examples, the template and function defined above are used to compute factorials. The types of constants need not be specified explicitly as the compiler infers their types
Type inference

Type inference, or implicit typing, refers to the ability to deduce automatically the type of a value in a programming language. It is a feature present in some strongly-typed programming language static typing#Static and dynamic typing languages....
 from the right-hand sides of assignments.

const fact_7 = Factorial!(7);

This is an example of compile-time function execution. Ordinary functions may be used in constant, compile-time expressions provided they meet certain criteria.

const fact_9 = factorial(9);

The std.metastrings.Format template performs printf
Printf

The class of printf functions is a class of function , typically associated with curly bracket programming languages, that accept a string parameter which specifies a method for rendering a number of other parameters into a string....
-like data formatting, and the "msg" pragma displays the result at compile time.

import std.metastrings; pragma(msg, Format!("7! = %s", fact_7)); pragma(msg, Format!("9! = %s", fact_9));

Memory management

Memory is usually managed with garbage collection
Garbage collection (computer science)

In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage , or memory used by Object that will never be accessed or mutated again by the Application software....
, but specific objects can be finalized immediately when they go out of scope. Explicit memory management is possible using the overloaded operators
Operator overloading

In computer programming, operator overloading is a specific case of polymorphism in which some or all of operator s like +, =, or have different implementations depending on the types of their arguments....
 new and delete, and by simply calling C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
's malloc and free
Malloc

In computing, malloc is a subroutine provided in the C and C++'s standard library for performing dynamic memory allocation....
 directly. Garbage collection can be controlled: programmers can add and exclude memory ranges from being observed by the collector, can pause and resume the collector and force a generational or a full collection cycle. The manual gives many examples of how to implement different highly optimized memory management schemes for when garbage collection is inadequate in a program.

Interaction with other systems

C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
's application binary interface (ABI)
Application binary interface

In computer software, an application binary interface describes the low-level interface between an application program and the operating system or an other application....
  is supported as well as all of C's fundamental and derived types, enabling direct access to existing C code and libraries. C's standard library
Library (computer science)

In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs....
 is part of standard D. Unless you use very explicit namespaces it can be somewhat messy to access, as it is spread throughout the D modules that use it -- but the pure D standard library is usually sufficient unless interfacing with C code.

C++'s ABI is not fully supported, although D can access C++ code that is written to the C ABI, and can access C++ COM (Component Object Model)
Component Object Model

Component Object Model is an interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages....
 code. The D parser understands an extern (C++) calling convention for linking to C++ objects, but it is only implemented in the currently experimental D 2.0.

D 2.0

D 2.0, a branch version of D that includes experimental features, was released on June 17, 2007. Some of these features are:

  • Support for enforcing const-correctness
    Const-correctness

    In computer science, const-correctness is the form of program correctness that deals with the proper declaration of objects as mutable object or immutable object....
    :
    • D differentiates between mutable references to immutable data, const references to mutable data, and combinations thereof
    • const and invariant keywords are transitive.
  • Limited support for linking with code written in C++.
  • Iteration with foreach over defined range only.
  • Support for "real" closures. Previously closures couldn't be safely returned from functions, because stack-allocated variables would become inaccessible.
  • Support for pure functions
    Pure function

    In computer programming, a function may be described as pure if both these statements about the function hold:# The function always evaluates the same result value given the same argument value....
     which can only access immutable data and call other pure functions. This ensures a pure function has no side effects (the same stack inputs always result in the same outputs and outputs exist only through return values). Together with real closure support this allows Functional Programming in D and also opens theoretical paths for safe automatic threading.
  • nothrow functions.
  • "safe" code, which can't directly access memory not belonging to process (only limited set of casts and pointer arithmetic is possible in such code).
  • Vector operations, i.e. a[] = b[] + c[] (element wide summation of two dynamic/static arrays), or a[] *= 3 (multiply by 3 each element of array).
  • Changes to standard Phobos library.


Implementation

Current D implementations compile
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
 directly into machine code
Machine code

Machine code or machine language is a system of instructions and data executed directly by a computer's central processing unit. Machine code may be regarded as a primitive programming language or as the lowest-level representation of a compiled and/or assembly language computer program....
 for efficient execution.

Even though D is still under development, changes to the language are no longer made regularly since version 1.0 of January 2, 2007. The design is currently virtually frozen, and newer releases focus on resolving existing bugs. Version 1.0 is not completely compatible with older versions of the language and compiler. The official compiler by Walter Bright defines the language itself.

DMD
The Digital Mars D compiler, the official D compiler by Walter Bright. The compiler front-end
Front-end and back-end

Front-end and back-end are generalized terms that refer to the initial and the end stages of a process. The front-end is responsible for collecting input in various forms from the user and processing it to conform to a specification the back-end can use....
 is licensed under both the Artistic License
Artistic License

The Artistic License refers most commonly to the original Artistic License , a software license used for certain free software packages, most notably the standard Perl implementation and most CPAN modules, which are dual-licensed under the Artistic License and the GNU General Public License ....
 and the GNU GPL; sources for the front-end are distributed along with the compiler binaries. The compiler back-end sources are available but not under open source licence.
GDC
A front-end for the GCC
GNU Compiler Collection

The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain....
 back-end, built using the open DMD compiler sources. Development snapshots also support D version 2.0.
LDC
A compiler based on DMD for the front-end that uses LLVM
Low Level Virtual Machine

The Low Level Virtual Machine, generally known as LLVM, is a compiler infrastructure, written in C++, which is designed for compile-time, link-time, run-time, and "idle-time" optimization of programs written in arbitrary programming languages....
 as its compiler back-end. The first release quality version was published on January 9, 2009.


Development tools

D is still lacking support in many IDEs
Integrated development environment

An integrated development environment also known as integrated design environment or integrated debugging environment is a software application that provides comprehensive facilities to computer programmers for software development....
, which is a potential stumbling block for some users. Editors used include Entice Designer, emacs
Emacs

Emacs is a class of feature-rich text editors, usually characterized by their extensibility. Emacs has, perhaps, more editing commands than any other editor or word processor, numbering over 1,000....
, vim, SciTE
SciTE

SciTE or SCIntilla based Text Editor is a cross-platform text editor written by Neil Hodgson using the Scintilla . It is licensed under a minimal version of the Historical Permission Notice and Disclaimer....
, Smultron
Smultron

Smultron is an open source text editor for Mac OS X that is designed for both beginning and advanced users. It is written in Objective-C using Cocoa ....
, TextMate
TextMate

TextMate is a general-purpose Graphical user interface text editor for Mac OS X created by Allan Odgaard. Its users are mostly programmers, though it has been used for screenwriting ....
, Zeus
Zeus for Windows

Zeus is a general-purpose, configurable and scriptable commercial IDE specificallydesigned for Windows software developers....
, and Geany
Geany

Geany is a lightweight cross-platform GTK+ text editor based on Scintilla with basic Integrated Development Environment features. It is designed to have limited dependency on separate packages and short load times....
 among others. Vim supports both syntax highlighting and code completion (through patched ctags). A bundle is available for TextMate
TextMate

TextMate is a general-purpose Graphical user interface text editor for Mac OS X created by Allan Odgaard. Its users are mostly programmers, though it has been used for screenwriting ....
, and the CodeBlocks IDE includes partial support for the language. However, standard IDE features such as code completion or refactoring
Refactoring

Code refactoring is the process of changing a computer program's internal structure without modifying its external Functional requirement behavior or existing functionality....
 are not yet available, though they do work partially in CodeBlocks (due to D's similarity to C).

There are at least two actively developed Eclipse plug-ins for D, and Mmrnmhrm.

Additionally, there are open source
Open source

Open source is an approach to design, development, and distribution offering practical accessibility to a product's source . Some consider open source as one of various possible design approaches, while others consider it a critical Strategy element of their business operations....
 D IDEs written in the D language itself such as , which does feature code completion, syntax highlighting
Syntax highlighting

Syntax highlighting is a feature of some text editors that displays text—especially source code—in different colors and typefaces according to the category of terms....
, and integrated debugging
Debugging

Debugging is a methodical process of finding and reducing the number of computer bugs, or defects, in a computer program or a piece of electronic hardware thus making it behave as expected....
.

D applications can be debugged using any C/C++ debugger, like GDB
GNU Debugger

The GNU Debugger, usually called just GDB, is the standard debugger for the GNU software system. It is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada programming language, C , C++, FreeBASIC, and Fortran programming language....
 or WinDbg
WinDbg

WinDbg is a multipurpose debugger for Microsoft Windows, distributed on the web by Microsoft. It can be used to debug user mode applications, drivers, and the operating system itself in kernel mode....
, although support for various fundamental language features is extremely limited. A debugger with explicit support for D is Ddbg for Windows. The commercial ZeroBUGS debugger for Linux has experimental support for the D language. Ddbg can be used with various IDEs or from the command line; ZeroBUGS has its own GUI
Graphical user interface

A graphical user interface is a type of user interface which allows people to human-computer interaction such as computers; hand-held devices such as MP3 Players, Portable Media Players or Gaming devices; household appliances and office equipment....
.

Problems and controversies


Division concerning the standard library

The standard library in D is called Phobos. Some members of the D community think Phobos is too simplistic and that it has numerous quirks and other issues, and a replacement of the library called Tango was written. However, in the D 1.0 branch, Tango and Phobos are incompatible due to different runtime libraries (the garbage collector, threading support, etc). The existence of two libraries, both widely in use, has led to significant problems where some packages use Phobos and others use Tango.

This problem is being addressed in the D 2.0 branch by creating a stand-alone runtime called druntime, and porting both Phobos and Tango to druntime. As of October, 2008, Phobos has been ported to druntime in the newest alpha version of the Digital Mars compiler. Tango is in the process of being ported to D 2.0, and is expected to eventually run on top of druntime. For the foreseeable future, D will have two standard libraries, but in the D 2.0 branch, they will be compatible and usable side-by-side in the same codebase.

Unfinished support for shared/dynamic libraries

Unix's ELF
Executable and Linkable Format

In computing, the Executable and Linking Format is a common standard file format for executables, object code, shared libraries, and core dumps....
 shared libraries are supported to an extent using the GDC compiler. On Windows systems, DLLs
Dynamic-link library

Dynamic-link library , or DLL, is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems....
 are supported and allow D's garbage collector-allocated objects to be safely passed to C functions, since the garbage collector scans the stack for pointers. However, there are still limitations with DLLs in D including the fact that run-time type information
Run-time type information

In programming, RTTI refers to a C++ system that keeps information about an object's data type in memory at runtime. Run-time type information can apply to simple data types, such as integers and characters, or to generic objects....
 of classes defined in the DLL is incompatible with those defined in the executable, and that any object created from within the DLL must be finalized before the DLL is unloaded.

Other

D has no built-in support for weak references
Weak reference

In computer programming, a weak reference is a Reference that does not protect the referent object from collection by a garbage collection . An object referenced only by weak references is considered Unreachable memory and so may be collected at any time....
, although there are some libraries that implement them. Operations on Unicode
Unicode

Unicode is a computing industry standard allowing computers to consistently represent and manipulate Character expressed in most of the world's writing systems....
 strings are unintuitive (compiler accepts Unicode source code, standard library and foreach constructs operate on UTF-8, but string slicing and length property operate on bytes rather than characters).

Examples


Example 1

This example program prints its command line arguments. The main function is the entry point of a D program, and args is an array of strings representing the command line arguments. A string in D is an array of characters, represented by char[] in D 1.0, or invariant(char)[] in D 2.0 alpha. Newer versions of the language define string as an alias for char[] or invariant(char)[], however, an explicit alias definition is necessary for compatibility with older versions.

import std.stdio: writefln;

void main(string[] args)



The foreach statement can iterate over any collection, in this case it is producing a sequence of indexes (i) and values (arg) from the array args. The index i and the value arg have their types inferred from the type of the array args.

Example 2

The following shows several capabilities of D in a very short program. It iterates the lines of a text file named words.txt that contains a different word on each line, and prints all the words that are anagrams of other words.

import std.stdio: writefln; import std.stream: BufferedFile; import std.string: tolower, join;

void main



  1. The type of signature2words is a built-in associative array that maps string keys to arrays of strings. It is similar to defaultdict(list) in Python
    Python (programming language)

    Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
    .
  2. BufferedFile yields lines lazily, without their newline, for performance the line it yields is just a view on a string, so it has to be copied with dup to have an actual string copy that can be used later.
  3. The ~= operator appends a new string to the values of the associate array.
  4. tolower and join are string functions that D allows to use with a method syntax, their names are often similar to Python string methods. The tolower converts an ASCII string to lower case and join(" ") joins an array of strings into a single string using a single space as separator.
  5. The sort sorts the array in place, creating an unique signature for words that are anagrams of each other.
  6. The second foreach iterates on the values of the associative array, it's able to infer the type of words.


See also

  • Ddoc
    Ddoc

    Ddoc is the Documentation generator for the D programming language designed by Walter Bright. Its emphasis is on being able to write documentation in code comments in a natural style, minimizing the need for embedded markup and thus improving the legibility of the code comments....


External links

  • , D front-end for GCC
    GNU Compiler Collection

    The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain....