Comment (computer programming): Difference between revisions

Content deleted Content added
Scripting: Clarify
Examples: Merge Ada and Haskell into group section
Line 457:
</syntaxhighlight>
 
===By=Double languagedash====
 
A relatively loose collection of languages use <code>--</code> for a single line comment. Notable languages include: [[Ada (programming language)|Ada]] and [[Haskell]]. An example in Ada:
====Ada====
 
[[Ada (programming language)|Ada]] supports line comments delimited with '--'. It does not support block comments. For example:
 
<syntaxhighlight lang="ada">
-- the air traffic controller task takes requests for takeoff and landing
task type Controller (My_Runway: Runway_Access) is
-- task entries for synchronous message passing
entry Request_Takeoff (ID: in Airplane_ID; Takeoff: out Runway_Access);
entry Request_Approach(ID: in Airplane_ID; Approach: out Runway_Access);
end Controller;
</syntaxhighlight>
 
====Block in Haskell====
In Haskell, a block comment is delimited by <code>{-</code> and <code>-}</code>. For example:
 
<syntaxhighlight lang="Haskell">
{- this is a comment
on more lines -}
-- and this is a comment on one line
putStrLn "Wikipedia" -- this is another comment
</syntaxhighlight>
 
Haskell also provides a [[literate programming]] method of commenting known as "Bird Style".<ref>{{cite web |url=http://www.haskell.org/haskellwiki/Literate_programming#Bird_Style |title=Literate programming |website=haskell.org}}</ref> In this all linesLines starting with <code>></code> are interpreted as code, and everything else is considered a comment. One additional requirement is that you always leave a blank line before and after the code block:
 
<syntaxhighlight lang="lHaskell">
In Bird-style you have to leave a blank before the code.
 
> fact :: Integer -> Integer
> fact 0 = 1
> fact (n+1) = (n+1) * fact n
 
And you have to leave a blank line after the code as well.
</syntaxhighlight>
 
Literate programming can also be accomplished via [[LaTeX]]. Example of a definition:
<syntaxhighlight lang="lHaskell">
\usepackage{verbatim}
\newenvironment{code}{\verbatim}{\endverbatim}
</syntaxhighlight>
 
Used as follows:
 
<syntaxhighlight lang="lhaskell">
% the LaTeX source file
The \verb|fact n| function call computes $n!$ if $n\ge 0$, here is a definition:\\
\begin{code}
fact :: Integer -> Integer
fact 0 = 1
fact (n+1) = (n+1) * fact n
\end{code}
Here more explanation using \LaTeX{} markup
</syntaxhighlight>
 
===By language===
 
====APL====
Line 596 ⟶ 637:
print '(A)', 'Hello world' ! Fortran 90 introduced the option for inline comments.
end program
</syntaxhighlight>
 
====Haskell====
Line comments in Haskell start with '--' (two hyphens) until the end of line, and multiple line comments start with '{-' and end with '-}'.
<syntaxhighlight lang="Haskell">
{- this is a comment
on more lines -}
-- and this is a comment on one line
putStrLn "Wikipedia" -- this is another comment
</syntaxhighlight>
 
Haskell also provides a [[literate programming]] method of commenting known as "Bird Style".<ref>{{cite web |url=http://www.haskell.org/haskellwiki/Literate_programming#Bird_Style |title=Literate programming |website=haskell.org}}</ref> In this all lines starting with > are interpreted as code, everything else is considered a comment. One additional requirement is that you always leave a blank line before and after the code block:
 
<syntaxhighlight lang="lHaskell">
In Bird-style you have to leave a blank before the code.
 
> fact :: Integer -> Integer
> fact 0 = 1
> fact (n+1) = (n+1) * fact n
 
And you have to leave a blank line after the code as well.
</syntaxhighlight>
Literate programming can also be done in Haskell, using [[LaTeX]]. The code environment can be used instead of the Richard Bird's style:
In [[LaTeX]] style this is equivalent to the above example, the code environment could be defined in the LaTeX preamble. Here is a simple definition:
<syntaxhighlight lang="lHaskell">
\usepackage{verbatim}
\newenvironment{code}{\verbatim}{\endverbatim}
</syntaxhighlight>
later in
<syntaxhighlight lang="lhaskell">
% the LaTeX source file
The \verb|fact n| function call computes $n!$ if $n\ge 0$, here is a definition:\\
\begin{code}
fact :: Integer -> Integer
fact 0 = 1
fact (n+1) = (n+1) * fact n
\end{code}
Here more explanation using \LaTeX{} markup
</syntaxhighlight>