Documentation: Difference between revisions

Content added Content deleted
(Added Arturo implementation)
m (syntax highlighting fixup automation)
Line 16: Line 16:


Example ADS file for instrumenting sorting functions:
Example ADS file for instrumenting sorting functions:
<lang ada>with Ada.Text_Io; use Ada.Text_Io;
<syntaxhighlight lang="ada">with Ada.Text_Io; use Ada.Text_Io;


generic
generic
Line 40: Line 40:
procedure Put (File : in out File_Type);
procedure Put (File : in out File_Type);


end Instrument;</lang>
end Instrument;</syntaxhighlight>
There is also a tool called [http://sourceforge.net/projects/adadoc/ AdaDoc]. This can be used to generate documentation of an Ada module (or modules?) for a variety of different formats: HTML, LaTeX, plain text and more.
There is also a tool called [http://sourceforge.net/projects/adadoc/ AdaDoc]. This can be used to generate documentation of an Ada module (or modules?) for a variety of different formats: HTML, LaTeX, plain text and more.


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>f: function [x :integer, y :integer][
<syntaxhighlight lang="rebol">f: function [x :integer, y :integer][
;; description: « takes two integers and adds them up
;; description: « takes two integers and adds them up
;; options: [
;; options: [
Line 57: Line 57:
]
]


info'f</lang>
info'f</syntaxhighlight>


{{out}}
{{out}}
Line 78: Line 78:
It generates html documentation in the style of the canonical ahk [http://www.autohotkey.com/docs/commands/MsgBox.htm documentation]. <br>
It generates html documentation in the style of the canonical ahk [http://www.autohotkey.com/docs/commands/MsgBox.htm documentation]. <br>
[http://en.wikipedia.org/wiki/BBCode BBCode] is supported for markup. <br>
[http://en.wikipedia.org/wiki/BBCode BBCode] is supported for markup. <br>
Example from the library distribution:<lang AutoHotkey>;
Example from the library distribution:<syntaxhighlight lang="autohotkey">;
; Function: example_add
; Function: example_add
; Description:
; Description:
Line 94: Line 94:
example_add(number1, number2, number3=0){
example_add(number1, number2, number3=0){
return number1 + number2 + number3
return number1 + number2 + number3
}</lang>[http://www.autohotkey.net/~tinku99/test/example_add.htm Resulting Documentation]
}</syntaxhighlight>[http://www.autohotkey.net/~tinku99/test/example_add.htm Resulting Documentation]


=={{header|C}}==
=={{header|C}}==
A common tool for generating documentation is [http://www.stack.nl/~dimitri/doxygen/ Doxygen]:
A common tool for generating documentation is [http://www.stack.nl/~dimitri/doxygen/ Doxygen]:
<lang c>/**
<syntaxhighlight lang="c">/**
* \brief Perform addition on \p a and \p b.
* \brief Perform addition on \p a and \p b.
*
*
Line 111: Line 111:
return a + b;
return a + b;
}
}
</syntaxhighlight>
</lang>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
This documentation method will work perfectly with the built in object browser in Visual Studio. The object browser can then show detailed information for each component. To make documentation that can be parsed, a triple slash (///) must be used. Further information can be found in [http://aspalliance.com/696 this tutorial]. A list of available xml elements for use in documentation [http://aspalliance.com/696_Code_Documentation_in_NET.2 is here].
This documentation method will work perfectly with the built in object browser in Visual Studio. The object browser can then show detailed information for each component. To make documentation that can be parsed, a triple slash (///) must be used. Further information can be found in [http://aspalliance.com/696 this tutorial]. A list of available xml elements for use in documentation [http://aspalliance.com/696_Code_Documentation_in_NET.2 is here].


<lang csharp>/// <summary>
<syntaxhighlight lang="csharp">/// <summary>
/// The XMLSystem class is here to help handle XML items in this site.
/// The XMLSystem class is here to help handle XML items in this site.
/// </summary>
/// </summary>
Line 135: Line 135:
return null;
return null;
}
}
}</lang>
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang lisp>(def
<syntaxhighlight lang="lisp">(def
#^{:doc "Metadata can contain documentation and can be added to vars like this."}
#^{:doc "Metadata can contain documentation and can be added to vars like this."}
test1)
test1)
Line 144: Line 144:
(defn test2
(defn test2
"defn and some other macros allow you add documentation like this. Works the same way"
"defn and some other macros allow you add documentation like this. Works the same way"
[])</lang>
[])</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
Line 161: Line 161:
the HTML generation process.
the HTML generation process.


<syntaxhighlight lang="cobol">
<lang COBOL>
*>****L* cobweb/cobweb-gtk [0.2]
*>****L* cobweb/cobweb-gtk [0.2]
*> Author:
*> Author:
Line 219: Line 219:
end program cobweb-gtk.
end program cobweb-gtk.
*>****
*>****
</lang>
</syntaxhighlight>


{{works with|GnuCOBOL}}
{{works with|GnuCOBOL}}
Line 228: Line 228:
markup processors, like Sphinx ReStructureText or Markdown.
markup processors, like Sphinx ReStructureText or Markdown.


<syntaxhighlight lang="cobol">
<lang COBOL>
>>IF docpass NOT DEFINED
>>IF docpass NOT DEFINED


Line 245: Line 245:
ReStructuredText or other markup source ...
ReStructuredText or other markup source ...
>>END-IF
>>END-IF
</syntaxhighlight>
</lang>


Extraction of documentation segments is feasible using just the Compiler
Extraction of documentation segments is feasible using just the Compiler
Line 286: Line 286:
=={{header|Crystal}}==
=={{header|Crystal}}==
The Crystal compiler comes with the <code>crystal docs</code> tool, which generates documentation from markdown embedded in source comments. The language's [https://crystal-lang.org/reference/conventions/documenting_code.html reference] goes into detail about the intricacies of the tool
The Crystal compiler comes with the <code>crystal docs</code> tool, which generates documentation from markdown embedded in source comments. The language's [https://crystal-lang.org/reference/conventions/documenting_code.html reference] goes into detail about the intricacies of the tool
<lang ruby># Any block of comments *directly* before (no blank lines) a module, class, or method is used as a doc comment
<syntaxhighlight lang="ruby"># Any block of comments *directly* before (no blank lines) a module, class, or method is used as a doc comment
# This one is for a module
# This one is for a module
module Documentation
module Documentation
Line 299: Line 299:
end
end
end
end
end</lang>
end</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
D compiler comes with a builtin documentation system called [http://digitalmars.com/d/1.0/ddoc.html Ddoc]. Alternative systems may be used (a common alternative is [http://www.stack.nl/~dimitri/doxygen/ Doxygen] which includes some D support).
D compiler comes with a builtin documentation system called [http://digitalmars.com/d/1.0/ddoc.html Ddoc]. Alternative systems may be used (a common alternative is [http://www.stack.nl/~dimitri/doxygen/ Doxygen] which includes some D support).
<lang d>/**
<syntaxhighlight lang="d">/**
This is a documentation comment for someFunc and someFunc2.
This is a documentation comment for someFunc and someFunc2.
$(DDOC_COMMENT comment inside a documentation comment
$(DDOC_COMMENT comment inside a documentation comment
Line 344: Line 344:


/++ Another documentation comment +/
/++ Another documentation comment +/
void main() {}</lang>
void main() {}</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==
XML comments are shown in the IDE and is included in the XML documentation produced by the compiler when using --docs.
XML comments are shown in the IDE and is included in the XML documentation produced by the compiler when using --docs.
<syntaxhighlight lang="delphi">type
<lang Delphi>type
/// <summary>Sample class.</summary>
/// <summary>Sample class.</summary>
TMyClass = class
TMyClass = class
Line 358: Line 358:
/// <exception cref="EConvertError">aValue is not a valid integer.</exception>
/// <exception cref="EConvertError">aValue is not a valid integer.</exception>
function StringToNumber(aValue: string): Integer;
function StringToNumber(aValue: string): Integer;
end;</lang>
end;</syntaxhighlight>


=={{header|E}}==
=={{header|E}}==
Line 368: Line 368:
The documentation syntax is in some ways underdefined: there is no layer which discards the leading '*'s as in Javadoc, so the documentation string contains all leading indentation (which is problematic for the source prettyprinter), and there is no formal definition yet of the syntax used within the doc-comments.
The documentation syntax is in some ways underdefined: there is no layer which discards the leading '*'s as in Javadoc, so the documentation string contains all leading indentation (which is problematic for the source prettyprinter), and there is no formal definition yet of the syntax used within the doc-comments.


<lang e>? /** This is an object with documentation */
<syntaxhighlight lang="e">? /** This is an object with documentation */
> def foo {
> def foo {
> # ...
> # ...
Line 375: Line 375:


? foo.__getAllegedType().getDocComment()
? foo.__getAllegedType().getDocComment()
# value: " This is an object with documentation "</lang>
# value: " This is an object with documentation "</syntaxhighlight>


Variables may not have doc-comments, because they are never part of the public interface of an object.
Variables may not have doc-comments, because they are never part of the public interface of an object.
Line 385: Line 385:
The following is a simple class written in Eiffel:
The following is a simple class written in Eiffel:


<lang eiffel>note
<syntaxhighlight lang="eiffel">note
description: "Objects that model Times of Day: 00:00:00 - 23:59:59"
description: "Objects that model Times of Day: 00:00:00 - 23:59:59"
author: "Eiffel Software Construction Students"
author: "Eiffel Software Construction Students"
Line 472: Line 472:
second_valid: 0 <= second and second <= 59
second_valid: 0 <= second and second <= 59


end -- class TIME_OF_DAY</lang>
end -- class TIME_OF_DAY</syntaxhighlight>


Below is the '''Contract''' (documentation) view of the same class. It is the view that potential reuse consumers would reference when writing clients.
Below is the '''Contract''' (documentation) view of the same class. It is the view that potential reuse consumers would reference when writing clients.


<lang eiffel>note
<syntaxhighlight lang="eiffel">note
description: "Objects that model Times of Day: 00:00:00 - 23:59:59"
description: "Objects that model Times of Day: 00:00:00 - 23:59:59"
author: "Eiffel Software Construction Students"
author: "Eiffel Software Construction Students"
Line 538: Line 538:
second_valid: 0 <= second and second <= 59
second_valid: 0 <= second and second <= 59


end -- class TIME_OF_DAY</lang>
end -- class TIME_OF_DAY</syntaxhighlight>


It is important to notice what is missing from this view. It shows only the specification of the class. The implementations of routines and any routines which are not public are not visible. The notes and comments, public features (including contracts for routines), and the class invariant all remain as components of the specification.
It is important to notice what is missing from this view. It shows only the specification of the class. The implementations of routines and any routines which are not public are not visible. The notes and comments, public features (including contracts for routines), and the class invariant all remain as components of the specification.
Line 546: Line 546:
=={{header|Elixir}}==
=={{header|Elixir}}==
Elixir uses [https://github.com/elixir-lang/ex_doc ExDoc] in order to document code. ExDoc allows users to pull data (such as name, version, source link) into their app. For example (taken from the ExDoc documentation):
Elixir uses [https://github.com/elixir-lang/ex_doc ExDoc] in order to document code. ExDoc allows users to pull data (such as name, version, source link) into their app. For example (taken from the ExDoc documentation):
<syntaxhighlight lang="elixir">
<lang Elixir>
def project do
def project do
[app: :repo
[app: :repo
Line 555: Line 555:
deps: deps]
deps: deps]
end
end
</syntaxhighlight>
</lang>


Individual modules can be documented using the @moduledoc attribute and heredocs (with markdown):
Individual modules can be documented using the @moduledoc attribute and heredocs (with markdown):
<syntaxhighlight lang="elixir">
<lang Elixir>
defmodule MyModule do
defmodule MyModule do
@moduledoc """
@moduledoc """
Line 569: Line 569:
"""
"""
end
end
</syntaxhighlight>
</lang>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
In <code>defun</code>, <code>defmacro</code> and <code>defsubst</code> an optional docstring can follow the formal parameters.
In <code>defun</code>, <code>defmacro</code> and <code>defsubst</code> an optional docstring can follow the formal parameters.


<lang Lisp>(defun hello (n)
<syntaxhighlight lang="lisp">(defun hello (n)
"Say hello to the user."
"Say hello to the user."
(message "hello %d" n))</lang>
(message "hello %d" n))</syntaxhighlight>


For <code>defvar</code>, <code>defconst</code> or <code>defcustom</code> an optional docstring follows the value.
For <code>defvar</code>, <code>defconst</code> or <code>defcustom</code> an optional docstring follows the value.


<lang Lisp>(defvar one-hundred 100
<syntaxhighlight lang="lisp">(defvar one-hundred 100
"The number one hundred.")</lang>
"The number one hundred.")</syntaxhighlight>


Most other defining forms have similar optional docstrings. In all cases they must be a string constant.
Most other defining forms have similar optional docstrings. In all cases they must be a string constant.
Line 598: Line 598:


=={{header|Fancy}}==
=={{header|Fancy}}==
<lang fancy>def class Foo {
<syntaxhighlight lang="fancy">def class Foo {
"""
"""
This is a docstring. Every object in Fancy can have it's own docstring.
This is a docstring. Every object in Fancy can have it's own docstring.
Line 610: Line 610:
}
}
Foo docstring println # prints docstring Foo class
Foo docstring println # prints docstring Foo class
Foo instance_method: 'a_method . docstring println # prints method's docstring</lang>
Foo instance_method: 'a_method . docstring println # prints method's docstring</syntaxhighlight>


=={{header|Forth}}==
=={{header|Forth}}==
Line 617: Line 617:
example :
example :


<lang>\ this is a comment</lang>
<syntaxhighlight lang="text">\ this is a comment</syntaxhighlight>


Another good practice is describing the stack use of a function : function ( stack before -- stack at end )
Another good practice is describing the stack use of a function : function ( stack before -- stack at end )
Line 623: Line 623:
example :
example :


<lang>: cubed ( n -- n^3 ) dup dup * * ; </lang>
<syntaxhighlight lang="text">: cubed ( n -- n^3 ) dup dup * * ; </syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
Line 646: Line 646:
Outside systems are available to assist. It is common for text editors to employ syntax highlighting, but their designers rarely handle the full complexity of Fortran syntax correctly. For instance, the format of a number such as -3.145E+07 is difficult to scan, especially since in Fortran source, spaces are ignored outside of text literals. Then, consider the FORMAT codes, such as <code>31E16.7</code> and similar sequences. More serious efforts scan the Fortran source in order to extract information useful for documentation. There have long been available systems that will identify every routine in a programme and for each identify what routine calls it, and what routines it calls, along with further analysis on their parameters and their usage - this well before F90 introduced the optional INTENT feature. Similarly, within each routine, identify which variables are used (possibly as parameters) where and whether they are read or written there. And, analyse the usage of COMMON variables... Likewise, documentation might include a flowchart, and systems exist to produce these as well.
Outside systems are available to assist. It is common for text editors to employ syntax highlighting, but their designers rarely handle the full complexity of Fortran syntax correctly. For instance, the format of a number such as -3.145E+07 is difficult to scan, especially since in Fortran source, spaces are ignored outside of text literals. Then, consider the FORMAT codes, such as <code>31E16.7</code> and similar sequences. More serious efforts scan the Fortran source in order to extract information useful for documentation. There have long been available systems that will identify every routine in a programme and for each identify what routine calls it, and what routines it calls, along with further analysis on their parameters and their usage - this well before F90 introduced the optional INTENT feature. Similarly, within each routine, identify which variables are used (possibly as parameters) where and whether they are read or written there. And, analyse the usage of COMMON variables... Likewise, documentation might include a flowchart, and systems exist to produce these as well.


Aside from the Fortran source code alone, there are systems that will also inspect the commentary associated with the code, and, if their conventions are followed (quite reasonable conventions, quoth the designer: declare ''and describe'' each parameter straight away, ''etc. etc.''), will produce for example a .html file with all manner of crosslinkages. For instance, given <lang Fortran> SUBROUTINE SHOW(A,N) !Prints details to I/O unit LINPR.
Aside from the Fortran source code alone, there are systems that will also inspect the commentary associated with the code, and, if their conventions are followed (quite reasonable conventions, quoth the designer: declare ''and describe'' each parameter straight away, ''etc. etc.''), will produce for example a .html file with all manner of crosslinkages. For instance, given <syntaxhighlight lang="fortran"> SUBROUTINE SHOW(A,N) !Prints details to I/O unit LINPR.
REAL*8 A !Distance to the next node.
REAL*8 A !Distance to the next node.
INTEGER N !Number of the current node.</lang>
INTEGER N !Number of the current node.</syntaxhighlight>
Quite useful documentation could be extracted just from that. By mixing actual source statements with the commentary and extracting ''both'', inane clashes can be reduced, as in <code>CHARACTER*6 TLA !Three-character name.</code> that arose because a modification to the nature of the parameter had been made, but, while revising every routine that employed such a parameter, the programmer's consciousness faded out as soon as it saw the comment start and noted "non-Fortran source", to the puzzlement of subsequent readers. A system that extracted only the commentary part from that would not give a correct report, whereas with it known that the actual declaration would be included, there would be no longer any need to repeat its details in the comment and the comment could confine itself to expounding on meaning and usage. On the other hand, F90 introduced a verbose scheme for declarations wherein something like <code>SELECTED_REAL_KIND(6, 70)</code> might appear and copying that may well merely copy obfuscation.
Quite useful documentation could be extracted just from that. By mixing actual source statements with the commentary and extracting ''both'', inane clashes can be reduced, as in <code>CHARACTER*6 TLA !Three-character name.</code> that arose because a modification to the nature of the parameter had been made, but, while revising every routine that employed such a parameter, the programmer's consciousness faded out as soon as it saw the comment start and noted "non-Fortran source", to the puzzlement of subsequent readers. A system that extracted only the commentary part from that would not give a correct report, whereas with it known that the actual declaration would be included, there would be no longer any need to repeat its details in the comment and the comment could confine itself to expounding on meaning and usage. On the other hand, F90 introduced a verbose scheme for declarations wherein something like <code>SELECTED_REAL_KIND(6, 70)</code> might appear and copying that may well merely copy obfuscation.


Line 666: Line 666:


Example code demonstrating what godoc extracts and what it doesn't:
Example code demonstrating what godoc extracts and what it doesn't:
<lang go>// Example serves as an example but does nothing useful.
<syntaxhighlight lang="go">// Example serves as an example but does nothing useful.
//
//
// A package comment preceeds the package clause and explains the purpose
// A package comment preceeds the package clause and explains the purpose
Line 690: Line 690:
// Doc not extracted.
// Doc not extracted.


var MEMEME int</lang>
var MEMEME int</syntaxhighlight>
Text output of godoc: (HTML looks nicer, of course)
Text output of godoc: (HTML looks nicer, of course)
<pre>
<pre>
Line 726: Line 726:
New commands can have optional help text between the command name line and the opening <code>{</code> brace.
New commands can have optional help text between the command name line and the opening <code>{</code> brace.


<lang Gri>`My Hello Message'
<syntaxhighlight lang="gri">`My Hello Message'
Print a greeting to the user.
Print a greeting to the user.
This is only a short greeting.
This is only a short greeting.
{
{
show "hello"
show "hello"
}</lang>
}</syntaxhighlight>


Any literal braces in the text must be backslash escaped <code>\{</code>. The text is shown by the online help system, similar to builtin commands.
Any literal braces in the text must be backslash escaped <code>\{</code>. The text is shown by the online help system, similar to builtin commands.


<lang Gri>help My Hello Message</lang>
<syntaxhighlight lang="gri">help My Hello Message</syntaxhighlight>


(See section "Simple New Command" in the GRI manual.)
(See section "Simple New Command" in the GRI manual.)
Line 742: Line 742:
[http://haskell.org/haddock/ Haddock] is a popular documentation generator for the Haskell language.
[http://haskell.org/haddock/ Haddock] is a popular documentation generator for the Haskell language.


<lang haskell>-- |This is a documentation comment for the following function
<syntaxhighlight lang="haskell">-- |This is a documentation comment for the following function
square1 :: Int -> Int
square1 :: Int -> Int
square1 x = x * x
square1 x = x * x
Line 767: Line 767:
-- |This is a documentation comment for the following type class
-- |This is a documentation comment for the following type class
class Foo a where
class Foo a where
bar :: a</lang>
bar :: a</syntaxhighlight>


See [http://haskell.org/haddock/doc/html/markup.html this chapter] for more information about the markup.
See [http://haskell.org/haddock/doc/html/markup.html this chapter] for more information about the markup.
Line 774: Line 774:
==={{header|Icon}}===
==={{header|Icon}}===
There are no formal conventions for documentation built into the Icon/Unicon. However, there are conventions for the different libraries that are supported by automation.
There are no formal conventions for documentation built into the Icon/Unicon. However, there are conventions for the different libraries that are supported by automation.
<lang Icon>############################################################################
<syntaxhighlight lang="icon">############################################################################
#
#
# File: filename.icn
# File: filename.icn
Line 799: Line 799:


procedure x1() #: short description of procedure
procedure x1() #: short description of procedure
</syntaxhighlight>
</lang>


{{libheader|Icon Programming Library}}
{{libheader|Icon Programming Library}}
Line 806: Line 806:


=={{header|Isabelle}}==
=={{header|Isabelle}}==
<lang Isabelle>theory Text
<syntaxhighlight lang="isabelle">theory Text
imports Main
imports Main
begin
begin
Line 831: Line 831:
text ‹This text will only compile if the constant \<^const>‹True› is defined.›
text ‹This text will only compile if the constant \<^const>‹True› is defined.›


end</lang>
end</syntaxhighlight>




==={{header|Unicon}}===
==={{header|Unicon}}===
<lang Unicon>XYZ</lang>
<syntaxhighlight lang="unicon">XYZ</syntaxhighlight>
{{improve|Unicon|Needs corresponding Unilib formats}}
{{improve|Unicon|Needs corresponding Unilib formats}}


Line 843: Line 843:
=={{header|J}}==
=={{header|J}}==
Use [http://www.jsoftware.com/trac/base/browser/trunk/main/script/doc.ijs?rev=1 scripdoc]:
Use [http://www.jsoftware.com/trac/base/browser/trunk/main/script/doc.ijs?rev=1 scripdoc]:
<lang j>NB. =========================================================
<syntaxhighlight lang="j">NB. =========================================================
NB.*apply v apply verb x to y
NB.*apply v apply verb x to y
apply=: 128!:2
apply=: 128!:2
Line 867: Line 867:
usleep
usleep
3 : '''libc.so.6 usleep > i i''&(15!:0) >.y'
3 : '''libc.so.6 usleep > i i''&(15!:0) >.y'
</syntaxhighlight>
</lang>


=={{header|Java}}==
=={{header|Java}}==
Documentation is typically given using [http://www.j2ee.me/j2se/javadoc/index.jsp Javadoc] comments. Documentation is generated from these comments using the Javadoc tool. The default output (from the standard doclet) takes the form of an [[HTML]] page with frames, so HTML is frequently embedded in the comments. The comments all start with <code>/**</code>, end with <code>*/</code>, and usually have "tags" embedded starting with <code>@</code>.
Documentation is typically given using [http://www.j2ee.me/j2se/javadoc/index.jsp Javadoc] comments. Documentation is generated from these comments using the Javadoc tool. The default output (from the standard doclet) takes the form of an [[HTML]] page with frames, so HTML is frequently embedded in the comments. The comments all start with <code>/**</code>, end with <code>*/</code>, and usually have "tags" embedded starting with <code>@</code>.
<lang java>/**
<syntaxhighlight lang="java">/**
* This is a class documentation comment. This text shows at the top of the page for this class
* This is a class documentation comment. This text shows at the top of the page for this class
* @author Joe Schmoe
* @author Joe Schmoe
Line 892: Line 892:
//...code here
//...code here
}
}
}</lang>
}</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
Line 901: Line 901:
Any string appearing at the top-level right before an object (function, macro, type or instance) will be interpreted as documenting it (these are called docstrings). Note that no blank lines or comments may intervene between a docstring and the documented object. Here is a basic example:
Any string appearing at the top-level right before an object (function, macro, type or instance) will be interpreted as documenting it (these are called docstrings). Note that no blank lines or comments may intervene between a docstring and the documented object. Here is a basic example:


<lang julia>
<syntaxhighlight lang="julia">
"Tell whether there are too foo items in the array."
"Tell whether there are too foo items in the array."
foo(xs::Array) = ...
foo(xs::Array) = ...
</syntaxhighlight>
</lang>


Documentation is interpreted as Markdown, so you can use indentation and code fences to delimit code examples from text. Technically, any object can be associated with any other as metadata; Markdown happens to be the default, but one can construct other string macros and pass them to the @doc macro just as well.
Documentation is interpreted as Markdown, so you can use indentation and code fences to delimit code examples from text. Technically, any object can be associated with any other as metadata; Markdown happens to be the default, but one can construct other string macros and pass them to the @doc macro just as well.
Line 910: Line 910:
Here is a more complex example, still using Markdown:
Here is a more complex example, still using Markdown:


<lang julia>
<syntaxhighlight lang="julia">
"""
"""
bar(x[, y])
bar(x[, y])
Line 926: Line 926:
"""
"""
function bar(x, y) ...
function bar(x, y) ...
</lang>When running Julia from the REPL, functions and types documented with docstrings have online help accessible with the ? key, just like Julia's builtin functions.
</syntaxhighlight>When running Julia from the REPL, functions and types documented with docstrings have online help accessible with the ? key, just like Julia's builtin functions.


=={{header|Kotlin}}==
=={{header|Kotlin}}==
Line 936: Line 936:


The following is a slightly extended version of the example in the official Kotlin documentation:
The following is a slightly extended version of the example in the official Kotlin documentation:
<lang scala>/**
<syntaxhighlight lang="scala">/**
* A group of *members*.
* A group of *members*.
* @author A Programmer.
* @author A Programmer.
Line 954: Line 954:
*/
*/
fun add(member: T): Int { ... }
fun add(member: T): Int { ... }
}</lang>
}</syntaxhighlight>


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==


Lambdatalk works in a small wiki, lambdatank, where can be written easily (as in a standard text editor) any informations about the keywords, the set of primitives, and the eventual user defined functions and libraries. For instance this is how a function is built, displayed and tested in the browser's window:
Lambdatalk works in a small wiki, lambdatank, where can be written easily (as in a standard text editor) any informations about the keywords, the set of primitives, and the eventual user defined functions and libraries. For instance this is how a function is built, displayed and tested in the browser's window:
<lang scheme>
<syntaxhighlight lang="scheme">
'{def add // define the name
'{def add // define the name
{lambda {:a :b} // for a function with two arguments
{lambda {:a :b} // for a function with two arguments
Line 969: Line 969:
'{add 3 4} // call the function on two values
'{add 3 4} // call the function on two values
-> 7 // the result
-> 7 // the result
</syntaxhighlight>
</lang>


=={{header|Logtalk}}==
=={{header|Logtalk}}==
Logtalk provides a set of entity and predicate documenting directives. The content of these and other directives can be retrieved using the language reflection features. A companion tool, "lgtdoc", uses the reflection API to extract the documenting information and export it as XML files and provides a set of stylesheets to convert these file to e.g. HTML and PDF files.
Logtalk provides a set of entity and predicate documenting directives. The content of these and other directives can be retrieved using the language reflection features. A companion tool, "lgtdoc", uses the reflection API to extract the documenting information and export it as XML files and provides a set of stylesheets to convert these file to e.g. HTML and PDF files.


<lang logtalk>
<syntaxhighlight lang="logtalk">
:- object(set(_Type),
:- object(set(_Type),
extends(set)).
extends(set)).
Line 1,000: Line 1,000:


:- end_object.
:- end_object.
</syntaxhighlight>
</lang>


=={{header|Lua}}==
=={{header|Lua}}==
Requires an external tool, the most widely-used of which (at present) is [https://github.com/lunarmodules/LDoc LDoc].
Requires an external tool, the most widely-used of which (at present) is [https://github.com/lunarmodules/LDoc LDoc].
<lang lua>--- Converts degrees to radians (summary).
<syntaxhighlight lang="lua">--- Converts degrees to radians (summary).
-- Given an angle measure in degrees, return an equivalent angle measure in radians (long description).
-- Given an angle measure in degrees, return an equivalent angle measure in radians (long description).
-- @param deg the angle measure in degrees
-- @param deg the angle measure in degrees
-- @return the angle measure in radians
-- @return the angle measure in radians
-- @see rad2deg
-- @see rad2deg
function deg2rad(deg) return deg*math.pi/180 end</lang>
function deg2rad(deg) return deg*math.pi/180 end</syntaxhighlight>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Mathematica inline documentation can be accessed directly in the code by pressing F1. No external tools required
Mathematica inline documentation can be accessed directly in the code by pressing F1. No external tools required
<lang Mathematica>f[x_,y_] := x + y (* Function comment : adds two numbers *)
<syntaxhighlight lang="mathematica">f[x_,y_] := x + y (* Function comment : adds two numbers *)
f::usage = "f[x,y] gives the sum of x and y"
f::usage = "f[x,y] gives the sum of x and y"


?f
?f
-> f[x,y] gives the sum of x and y</lang>
-> f[x,y] gives the sum of x and y</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
Script files can contain comments (being whatever follows a % character) and for a script in file Gnash.m that is in the current execute path (so that typing "Gnash" will initiate it), the command "help Gnash" will instead display the first comment block at the start of the file. So, if it starts <lang MATLAB>function Gnash(GnashFile); %Convert to a "function". Data is placed in the "global" area.
Script files can contain comments (being whatever follows a % character) and for a script in file Gnash.m that is in the current execute path (so that typing "Gnash" will initiate it), the command "help Gnash" will instead display the first comment block at the start of the file. So, if it starts <syntaxhighlight lang="matlab">function Gnash(GnashFile); %Convert to a "function". Data is placed in the "global" area.
% My first MatLab attempt, to swallow data as produced by Gnash's DUMP
% My first MatLab attempt, to swallow data as produced by Gnash's DUMP
%command in a comma-separated format. Such files start with a line</lang>
%command in a comma-separated format. Such files start with a line</syntaxhighlight>
The comments will be revealed. However, a test with Octave elicited only the comment on the "function" line. If the file contained merely a sequence of commands (i.e. did not constitute the definition of a function) the first line of the above example would be absent and the file would start with a comment block.
The comments will be revealed. However, a test with Octave elicited only the comment on the "function" line. If the file contained merely a sequence of commands (i.e. did not constitute the definition of a function) the first line of the above example would be absent and the file would start with a comment block.


=={{header|Neko}}==
=={{header|Neko}}==
'''nekoc -doc <file>''' generates XHTML documentation from within source. The compiler scans for <lang ActionScript>/** ... **/</lang> multi line comments.
'''nekoc -doc <file>''' generates XHTML documentation from within source. The compiler scans for <syntaxhighlight lang="actionscript">/** ... **/</syntaxhighlight> multi line comments.


Special <lang html><doc> ... </doc></lang> tags can be used inside these documentation blocks and are parsed as XML nodes; and checked for valid XHTML. Outside of the doc tags, the documentation parser can be used to create API documentation.
Special <syntaxhighlight lang="html"><doc> ... </doc></syntaxhighlight> tags can be used inside these documentation blocks and are parsed as XML nodes; and checked for valid XHTML. Outside of the doc tags, the documentation parser can be used to create API documentation.


The feature does not care what file type is used for input, and most C sources for Neko libraries include documentation blocks of this type.
The feature does not care what file type is used for input, and most C sources for Neko libraries include documentation blocks of this type.


<lang C>/**
<syntaxhighlight lang="c">/**
result_set_conv_date : 'result -> function:1 -> void
result_set_conv_date : 'result -> function:1 -> void
<doc>Set the function that will convert a Date or DateTime string
<doc>Set the function that will convert a Date or DateTime string
to the corresponding value.</doc>
to the corresponding value.</doc>
**/</lang> produces '''void result_set_conv_date('result, function:1)''' for the API documentation, along with the prose. The syntax of the API style documentation is picky.
**/</syntaxhighlight> produces '''void result_set_conv_date('result, function:1)''' for the API documentation, along with the prose. The syntax of the API style documentation is picky.


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>## Nim directly supports documentation using comments that start with two
<syntaxhighlight lang="nim">## Nim directly supports documentation using comments that start with two
## hashes (##). To create the documentation run ``nim doc file.nim``.
## hashes (##). To create the documentation run ``nim doc file.nim``.
## ``nim doc2 file.nim`` is the same, but run after semantic checking, which
## ``nim doc2 file.nim`` is the same, but run after semantic checking, which
Line 1,069: Line 1,069:
## A useful procedure
## A useful procedure
for i in 1..times:
for i in 1..times:
echo "hello world"</lang>
echo "hello world"</syntaxhighlight>


=={{header|Objeck}}==
=={{header|Objeck}}==
Documentation can be produced for bundles, classes and methods/functions.
Documentation can be produced for bundles, classes and methods/functions.


<lang objeck>#~
<syntaxhighlight lang="objeck">#~
Sets the named row value
Sets the named row value
@param name name
@param name name
Line 1,083: Line 1,083:
return Set(@table->GetRowId(name), value);
return Set(@table->GetRowId(name), value);
}
}
</syntaxhighlight>
</lang>


=={{header|Objective-C}}==
=={{header|Objective-C}}==
Line 1,089: Line 1,089:


===HeaderDoc===
===HeaderDoc===
<lang objc>/*!
<syntaxhighlight lang="objc">/*!
@function add
@function add
@abstract Adds two numbers
@abstract Adds two numbers
Line 1,099: Line 1,099:
int add(int a, int b) {
int add(int a, int b) {
return a + b;
return a + b;
}</lang>
}</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
Line 1,108: Line 1,108:


i.e.
i.e.
<lang scheme>
<syntaxhighlight lang="scheme">
; note: use this script to generate a markdown file
; note: use this script to generate a markdown file
; sed -n 's/\s*;!\s*//gp'
; sed -n 's/\s*;!\s*//gp'
Line 1,125: Line 1,125:
;! Returns any amount (including 0) of whitespaces. Used as whitespace characters skipper in parses.
;! Returns any amount (including 0) of whitespaces. Used as whitespace characters skipper in parses.
(define maybe-whitespaces (greedy* whitespace))
(define maybe-whitespaces (greedy* whitespace))
</syntaxhighlight>
</lang>


Sed script:
Sed script:
Line 1,143: Line 1,143:
=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
The primary method for documenting GP functions is the <code>addhelp()</code> command:
The primary method for documenting GP functions is the <code>addhelp()</code> command:
<lang parigp>addhelp(funcName, "funcName(v, n): This is a description of the function named funcName.");</lang>
<syntaxhighlight lang="parigp">addhelp(funcName, "funcName(v, n): This is a description of the function named funcName.");</syntaxhighlight>
PARI documentation is done as for [[#C|C]].
PARI documentation is done as for [[#C|C]].


Line 1,158: Line 1,158:
from the project tree of the last run/file being edited. Pressing F1 again cycles through them.<br>
from the project tree of the last run/file being edited. Pressing F1 again cycles through them.<br>
Ideally any routine-specific comments should be placed within the routine itself, eg (from pmain.e):
Ideally any routine-specific comments should be placed within the routine itself, eg (from pmain.e):
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">procedure</span> <span style="color: #000000;">StoreVar</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">N</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">NTyp</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">StoreVar</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">N</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">NTyp</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">--
<span style="color: #000080;font-style:italic;">--
Line 1,169: Line 1,169:
<span style="color: #0000FF;">...</span>
<span style="color: #0000FF;">...</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
Note: As I understand it, tools such as Doxygen usually expect their markup to precede the actual definitions.
Note: As I understand it, tools such as Doxygen usually expect their markup to precede the actual definitions.


Line 1,179: Line 1,179:
=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
PicoLisp doesn't yet support inline documentation directly in the code. However, it has built-in runtime documentation via the '[http://software-lab.de/doc/refD.html#doc doc]' function. This requires no external tools, except that the interpreter must have been started in debug mode.
PicoLisp doesn't yet support inline documentation directly in the code. However, it has built-in runtime documentation via the '[http://software-lab.de/doc/refD.html#doc doc]' function. This requires no external tools, except that the interpreter must have been started in debug mode.
<lang PicoLisp>: (doc 'car) # View documentation of a function
<syntaxhighlight lang="picolisp">: (doc 'car) # View documentation of a function


: (doc '+Entity) # View documentation of a class
: (doc '+Entity) # View documentation of a class


: (doc '+ 'firefox) # Explicitly specify a browser</lang>
: (doc '+ 'firefox) # Explicitly specify a browser</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
Line 1,192: Line 1,192:
=={{header|PowerShell}}==
=={{header|PowerShell}}==
PowerShell includes complete built-in help for comment-based help: Just run help about_comment_based_help.
PowerShell includes complete built-in help for comment-based help: Just run help about_comment_based_help.
<syntaxhighlight lang="powershell">
<lang PowerShell>
help about_comment_based_help
help about_comment_based_help
</syntaxhighlight>
</lang>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>; This is a small demo-code to demonstrate PureBasic’s internal
<syntaxhighlight lang="purebasic">; This is a small demo-code to demonstrate PureBasic’s internal
; documentation system.
; documentation system.


Line 1,231: Line 1,231:
CloseFile(file)
CloseFile(file)
EndIf
EndIf
EndProcedure</lang>
EndProcedure</syntaxhighlight>
This would as an example be shown in the code over view as the picture below.
This would as an example be shown in the code over view as the picture below.


Line 1,239: Line 1,239:
A string literal which is the first expression in a class, function, or module definition is called a [http://docs.python.org/glossary.html#term-docstring docstring]. It can be subsequently accessed at runtime using the <code>.__doc__</code> attribute of the class, function, or module.
A string literal which is the first expression in a class, function, or module definition is called a [http://docs.python.org/glossary.html#term-docstring docstring]. It can be subsequently accessed at runtime using the <code>.__doc__</code> attribute of the class, function, or module.


<lang python>class Doc(object):
<syntaxhighlight lang="python">class Doc(object):
"""
"""
This is a class docstring. Traditionally triple-quoted strings are used because
This is a class docstring. Traditionally triple-quoted strings are used because
Line 1,246: Line 1,246:
def method(self, num):
def method(self, num):
"""This is a method docstring."""
"""This is a method docstring."""
pass</lang>
pass</syntaxhighlight>


'''[http://docs.python.org/library/pydoc.html pydoc]''', a module of the Python standard library, can automatically generate documentation gleaned from docstrings of modules. The documentation can be presented as pages of text on a terminal; automatically served to a Web Browser; or saved as HTML. The command line pydoc command , in addition, can display docstring information in a TK based GUI browser.
'''[http://docs.python.org/library/pydoc.html pydoc]''', a module of the Python standard library, can automatically generate documentation gleaned from docstrings of modules. The documentation can be presented as pages of text on a terminal; automatically served to a Web Browser; or saved as HTML. The command line pydoc command , in addition, can display docstring information in a TK based GUI browser.


The built-in help() function uses the pydoc module to display docstring information at the command prompt of the Python interactive shell.
The built-in help() function uses the pydoc module to display docstring information at the command prompt of the Python interactive shell.
<lang python>>>> def somefunction():
<syntaxhighlight lang="python">>>> def somefunction():
"takes no args and returns None after doing not a lot"
"takes no args and returns None after doing not a lot"


Line 1,261: Line 1,261:
takes no args and returns None after doing not a lot
takes no args and returns None after doing not a lot


>>></lang>
>>></syntaxhighlight>


===Sphinx===
===Sphinx===
Line 1,268: Line 1,268:
=={{header|R}}==
=={{header|R}}==
R objects are documented in files written in "R documentation" (Rd) format, which is similar to LaTeX markup. See Chapter 2 of [http://cran.r-project.org/doc/manuals/R-exts.pdf Writing R Extensions] for the full details. Example function document files can be created using
R objects are documented in files written in "R documentation" (Rd) format, which is similar to LaTeX markup. See Chapter 2 of [http://cran.r-project.org/doc/manuals/R-exts.pdf Writing R Extensions] for the full details. Example function document files can be created using
<lang r>example(package.skeleton)</lang>
<syntaxhighlight lang="r">example(package.skeleton)</syntaxhighlight>
An example documentation file for a function 'f', taking arguments 'x' and 'y' is
An example documentation file for a function 'f', taking arguments 'x' and 'y' is
<lang r>\name{f}
<syntaxhighlight lang="r">\name{f}
\Rdversion{1.1}
\Rdversion{1.1}
\alias{f}
\alias{f}
Line 1,328: Line 1,328:
% R documentation directory.
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line</lang>
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Line 1,335: Line 1,335:
domain-specific language called Scribble:
domain-specific language called Scribble:


<lang racket>
<syntaxhighlight lang="racket">
#lang scribble/manual
#lang scribble/manual
(require (for-label "sandwiches.rkt"))
(require (for-label "sandwiches.rkt"))
Line 1,343: Line 1,343:
Returns a sandwich given the right ingredients.
Returns a sandwich given the right ingredients.
}
}
</syntaxhighlight>
</lang>


Programs can also be written with inline documentation using either the
Programs can also be written with inline documentation using either the
Line 1,353: Line 1,353:
Similarly to Perl 5, Raku is documented using [https://docs.raku.org/language/pod Pod] (a redesigned version of POD). However, it's not simply ignored by the parser as in Perl 5, it's an internal part of the language spec and can be used to attach documentation objects to almost any part of the code.
Similarly to Perl 5, Raku is documented using [https://docs.raku.org/language/pod Pod] (a redesigned version of POD). However, it's not simply ignored by the parser as in Perl 5, it's an internal part of the language spec and can be used to attach documentation objects to almost any part of the code.


<syntaxhighlight lang="raku" line>
<lang perl6>
#= it's yellow
#= it's yellow
sub marine { ... }
sub marine { ... }
Line 1,364: Line 1,364:
}
}
say Sheep.WHY; # "a shaggy little thing"
say Sheep.WHY; # "a shaggy little thing"
say Sheep.^find_method('roar').WHY; # "not too scary"</lang>
say Sheep.^find_method('roar').WHY; # "not too scary"</syntaxhighlight>


A compiler has a built-in <code>--doc</code> switch that will generate documentation from a given source file. An output format can be specified in the switch. For example, <code>--doc=Markdown</code> will generate Markdown from Pod provided that the <code>Pod::To::Markdown</code> is installed.
A compiler has a built-in <code>--doc</code> switch that will generate documentation from a given source file. An output format can be specified in the switch. For example, <code>--doc=Markdown</code> will generate Markdown from Pod provided that the <code>Pod::To::Markdown</code> is installed.


=={{header|REBOL}}==
=={{header|REBOL}}==
<lang REBOL>REBOL [
<syntaxhighlight lang="rebol">REBOL [
Title: "Documentation"
Title: "Documentation"
URL: http://rosettacode.org/wiki/Documentation
URL: http://rosettacode.org/wiki/Documentation
Line 1,432: Line 1,432:
x: get in bob 'hi help x print ""
x: get in bob 'hi help x print ""


probe get in bob 'hi</lang>
probe get in bob 'hi</syntaxhighlight>


Output:
Output:
Line 1,482: Line 1,482:
Retro uses a literate source format called Unu. Sources are typically using a subset of Markdown.
Retro uses a literate source format called Unu. Sources are typically using a subset of Markdown.


<syntaxhighlight lang="retro">
<lang Retro>
# Determine The Average Word Name Length
# Determine The Average Word Name Length


Line 1,511: Line 1,511:
'Average_name_length:_%n\n s:format s:put
'Average_name_length:_%n\n s:format s:put
~~~
~~~
</syntaxhighlight>
</lang>


This illustrates the format. Only code in the fenced blocks (between \[[User:Crc|Crc]] ([[User talk:Crc|talk]]) pairs) get extracted and run.
This illustrates the format. Only code in the fenced blocks (between \[[User:Crc|Crc]] ([[User talk:Crc|talk]]) pairs) get extracted and run.
Line 1,528: Line 1,528:


<br>Note that the documentation is bracketed by the standard REXX comment delimiters to preserve program lexicographical integrity.
<br>Note that the documentation is bracketed by the standard REXX comment delimiters to preserve program lexicographical integrity.
<lang rexx>/*REXX program illustrates how to display embedded documentation (help) within REXX code*/
<syntaxhighlight lang="rexx">/*REXX program illustrates how to display embedded documentation (help) within REXX code*/
parse arg doc /*obtain (all) the arguments from C.L. */
parse arg doc /*obtain (all) the arguments from C.L. */
if doc='?' then call help /*show documentation if arg=a single ? */
if doc='?' then call help /*show documentation if arg=a single ? */
Line 1,556: Line 1,556:
If no "numberOfItems" are entered, the default of 100 is used.
If no "numberOfItems" are entered, the default of 100 is used.
</help>
</help>
════════════════════════════════════end of the in═line documentation BEFORE the </help> */</lang>
════════════════════════════════════end of the in═line documentation BEFORE the </help> */</syntaxhighlight>


===version 2===
===version 2===
<lang rexx>/* REXX ***************************************************************
<syntaxhighlight lang="rexx">/* REXX ***************************************************************
* 13.10.2013 Walter Pachl another way to show documentation
* 13.10.2013 Walter Pachl another way to show documentation
* no tags and good enough if only one documentation block
* no tags and good enough if only one documentation block
Line 1,577: Line 1,577:
say 'the program would be here!'
say 'the program would be here!'
Exit
Exit
here: return sigl /* returns the invocation's line number */</lang>
here: return sigl /* returns the invocation's line number */</syntaxhighlight>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
/*
/*
Multiply two numbers
Multiply two numbers
Line 1,590: Line 1,590:
func mult n1, n2
func mult n1, n2
return n1*n2
return n1*n2
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
Line 1,600: Line 1,600:


Ruby's documentation comments look like Perl's PODs. Translating Java's example:
Ruby's documentation comments look like Perl's PODs. Translating Java's example:
<lang ruby>=begin rdoc
<syntaxhighlight lang="ruby">=begin rdoc
RDoc is documented here[http://www.ruby-doc.org/core/classes/RDoc.html].
RDoc is documented here[http://www.ruby-doc.org/core/classes/RDoc.html].


Line 1,634: Line 1,634:
end
end


# :include:boilerplate.txt</lang>
# :include:boilerplate.txt</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
Line 1,654: Line 1,654:


Here's an example of some heavily documented mock code:
Here's an example of some heavily documented mock code:
<lang rust>//! Documentation for the module
<syntaxhighlight lang="rust">//! Documentation for the module
//!
//!
//! **Lorem ipsum** dolor sit amet, consectetur adipiscing elit. Aenean a
//! **Lorem ipsum** dolor sit amet, consectetur adipiscing elit. Aenean a
Line 1,710: Line 1,710:
let foo = Whatchamabob{ doodad: 1.2, thingamabob: false };
let foo = Whatchamabob{ doodad: 1.2, thingamabob: false };
foo.frob();
foo.frob();
}</lang>
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
Excellent documentation about ScalaDoc is given [https://docs.scala-lang.org/style/scaladoc.html here in the Scala Style Guide.]
Excellent documentation about ScalaDoc is given [https://docs.scala-lang.org/style/scaladoc.html here in the Scala Style Guide.]
<syntaxhighlight lang="scala">/**
<lang Scala>/**
* This is a class documentation comment. This text shows at the top of the page for this class
* This is a class documentation comment. This text shows at the top of the page for this class
*
*
Line 1,735: Line 1,735:
???
???
}
}
}</lang>
}</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
Line 1,741: Line 1,741:
In addition, all support class comments as follows:
In addition, all support class comments as follows:
(Squeak/Pharo/VisualWorks/SmalltalkX)
(Squeak/Pharo/VisualWorks/SmalltalkX)
<lang smalltalk>FooClass comment: 'This is a comment ....'.</lang>
<syntaxhighlight lang="smalltalk">FooClass comment: 'This is a comment ....'.</syntaxhighlight>


=={{header|SQL PL}}==
=={{header|SQL PL}}==
{{works with|Db2 LUW}}
{{works with|Db2 LUW}}
{{libheader|db2doc}}
{{libheader|db2doc}}
<lang sql pl>
<syntaxhighlight lang="sql pl">
CREATE TABLESPACE myTs;
CREATE TABLESPACE myTs;


Line 1,868: Line 1,868:


COMMENT ON ROLE mySeq IS 'Description of the sequence.';
COMMENT ON ROLE mySeq IS 'Description of the sequence.';
</syntaxhighlight>
</lang>


=={{header|Stata}}==
=={{header|Stata}}==
Line 1,875: Line 1,875:
For instance, say we have an ado file '''hello.ado''':
For instance, say we have an ado file '''hello.ado''':


<lang stata>prog def hello
<syntaxhighlight lang="stata">prog def hello
di "Hello, World!"
di "Hello, World!"
end</lang>
end</syntaxhighlight>


The documentation file, '''hello.sthlp''', could be:
The documentation file, '''hello.sthlp''', could be:
Line 1,898: Line 1,898:
=={{header|Swift}}==
=={{header|Swift}}==
Swift uses reStructuredText. [http://nshipster.com/swift-documentation/ This third-party article] has some information.
Swift uses reStructuredText. [http://nshipster.com/swift-documentation/ This third-party article] has some information.
<lang swift>/**
<syntaxhighlight lang="swift">/**
Adds two numbers
Adds two numbers
:param: a an integer.
:param: a an integer.
Line 1,906: Line 1,906:
func add(a: Int, b: Int) -> Int {
func add(a: Int, b: Int) -> Int {
return a + b
return a + b
}</lang>
}</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
Documentation for Tcl code is usually prepared in separate files using a tool like [http://wiki.tcl.tk/3054 doctools], but inline docs (with all their inherent limitations) can be done with the likes of [http://www.xs4all.nl/~rfsber/Robo/index.html Robodoc]. For example:
Documentation for Tcl code is usually prepared in separate files using a tool like [http://wiki.tcl.tk/3054 doctools], but inline docs (with all their inherent limitations) can be done with the likes of [http://www.xs4all.nl/~rfsber/Robo/index.html Robodoc]. For example:
<lang tcl>#****f* RosettaCode/TclDocDemo
<syntaxhighlight lang="tcl">#****f* RosettaCode/TclDocDemo
# FUNCTION
# FUNCTION
# TclDocDemo is a simple illustration of how to do documentation
# TclDocDemo is a simple illustration of how to do documentation
Line 1,927: Line 1,927:
proc TclDocDemo {foo bar} {
proc TclDocDemo {foo bar} {
puts [format "%s -- %s" $foo $bar]
puts [format "%s -- %s" $foo $bar]
}</lang>
}</syntaxhighlight>
Both doctools and robodoc can produce output in multiple formats.
Both doctools and robodoc can produce output in multiple formats.


Line 1,936: Line 1,936:


However, there are currently no special tools for extracting documentation comments that I'm aware of.
However, there are currently no special tools for extracting documentation comments that I'm aware of.
<lang ecmascript>// The meaning of life!
<syntaxhighlight lang="ecmascript">// The meaning of life!
var mol = 42
var mol = 42


Line 1,962: Line 1,962:
System.print("'%(smol)' + 123 = %(add.call(mol, 123))")
System.print("'%(smol)' + 123 = %(add.call(mol, 123))")
System.print("'%(smol)' reversed = %(StrUtil.reverse(smol))")
System.print("'%(smol)' reversed = %(StrUtil.reverse(smol))")
System.print("'%(smol)' capitalized = %(StrUtil.capitalize(smol))")</lang>
System.print("'%(smol)' capitalized = %(StrUtil.capitalize(smol))")</syntaxhighlight>


{{out}}
{{out}}
Line 1,975: Line 1,975:
Inline documentation is limited to comments within the code. However, there is no inbuilt extraction tool, so this would need to be written. The example shows how documentation for a variable and a function could be embedded within the code:
Inline documentation is limited to comments within the code. However, there is no inbuilt extraction tool, so this would need to be written. The example shows how documentation for a variable and a function could be embedded within the code:


<lang zxbasic> 10 LET a=10: REM a is the number of apples
<syntaxhighlight lang="zxbasic"> 10 LET a=10: REM a is the number of apples
1000 DEF FN s(q)=q*q: REM s is a function that takes a single numeric parameter and returns its square</lang>
1000 DEF FN s(q)=q*q: REM s is a function that takes a single numeric parameter and returns its square</syntaxhighlight>


Alternatively, it is possible to embed documentation into LPRINT statements within a subroutine, allowing the language to print its own documentation. In the example below, the command GOSUB 2000 would print the documentation:
Alternatively, it is possible to embed documentation into LPRINT statements within a subroutine, allowing the language to print its own documentation. In the example below, the command GOSUB 2000 would print the documentation:


<lang zxbasic>10 GOSUB 2000: REM call a subroutine to print the documentation
<syntaxhighlight lang="zxbasic">10 GOSUB 2000: REM call a subroutine to print the documentation
1999 STOP
1999 STOP
2000 REM Print the documentation
2000 REM Print the documentation
Line 1,986: Line 1,986:
2020 LPRINT "s is a function that takes a single numeric parameter and returns"
2020 LPRINT "s is a function that takes a single numeric parameter and returns"
2030 LPRINT "its square"
2030 LPRINT "its square"
2040 RETURN</lang>
2040 RETURN</syntaxhighlight>


{{omit from|GUISS}}
{{omit from|GUISS}}