authorgravatar for scottschwarz77@hotmail.comScott Schwarz <scottschwarz77@hotmail.com> 2024-01-08 00:32:26-06:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-08 01:32:26-05:00
logf5978181e41e272b5c272440b9c543ead0357e2e
treea9562720a32c9b4fc23a765130a8bded96d968d1
parent3176fdc0b921b36ee7d8346ef302d0817b980cfa
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

langref: reword Hello World section (#18458)

closes #14347

1 files changed, 23 insertions(+), 26 deletions(-)

doc/langref.html.in+23-26
......@@ -432,18 +432,17 @@ pub fn main() !void {
432432 </p>
433433 <p>
434434 Next, a {#link|public function|Functions#}, {#syntax#}pub fn{#endsyntax#}, named {#syntax#}main{#endsyntax#}
435 is declared. The {#syntax#}main{#endsyntax#} function is necessary because it tells the Zig compiler where the start of
436 the program exists. Programs designed to be executed will need a {#syntax#}pub fn main{#endsyntax#} function.
435 is declared. The {#syntax#}main{#endsyntax#} function is necessary because it tells the Zig compiler where the program starts. Programs
436 designed to be executed will need a {#syntax#}pub fn main{#endsyntax#} function.
437437 </p>
438438 <aside role="note" aria-label="Note about main function">
439439 <p>
440 For more advanced use cases, Zig offers other features to inform the compiler where the start of
441 the program exists. Also, libraries do not need a {#syntax#}pub fn main{#endsyntax#} function because
442 library code is called by other programs or libraries.
440 For more advanced use cases, Zig offers other features to inform the compiler where the program starts. Also, libraries do not need a
441 {#syntax#}pub fn main{#endsyntax#} function because library code is called by other programs or libraries.
443442 </p>
444443 </aside>
445444 <p>
446 A function is a block of any number of statements and expressions that, as a whole, perform a task.
445 A function is a block of any number of statements and expressions, that as a whole, perform a task.
447446 Functions may or may not return data after they are done performing their task. If a function
448447 cannot perform its task, it might return an error. Zig makes all of this explicit.
449448 </p>
......@@ -469,32 +468,30 @@ pub fn main() !void {
469468 </aside>
470469 <p>
471470 In Zig, a function's block of statements and expressions are surrounded by an open curly-brace <code>{</code> and
472 close curly-brace <code>}</code>. Inside of the {#syntax#}main{#endsyntax#} function are expressions that perform
473 the task of outputting <samp>Hello, world!</samp> to standard output.
471 close curly-brace <code>}</code>. In <code class="file">hello.zig</code>, the {#syntax#}main{#endsyntax#} function
472 contains two statements.
474473 </p>
475474 <p>
476 First, a constant identifier, {#syntax#}stdout{#endsyntax#}, is initialized to represent standard output's
477 writer. Then, the program tries to print the <samp>Hello, world!</samp>
478 message to standard output.
475 In the first statement, a constant identifier, {#syntax#}stdout{#endsyntax#}, is initialized to represent standard output's
476 writer. In the second statement, the program tries to print the <samp>Hello, world!</samp> message to standard output.
479477 </p>
480478 <p>
481 Functions sometimes need information to perform their task. In Zig, information is passed
482 to functions between an open parenthesis {#syntax#}({#endsyntax#} and a close parenthesis {#syntax#}){#endsyntax#} placed after
483 the function's name. This information is also known as arguments. When there are
484 multiple arguments passed to a function, they are separated by commas {#syntax#},{#endsyntax#}.
479 Functions sometimes need inputs to perform their task. Inputs are passed, in between parentheses, to functions. These
480 inputs are also known as arguments. When multiple arguments are passed to a function, they are separated by commas.
485481 </p>
486482 <p>
487 The two arguments passed to the {#syntax#}stdout.print(){#endsyntax#} function, {#syntax#}"Hello, {s}!\n"{#endsyntax#}
488 and {#syntax#}.{"world"}{#endsyntax#}, are evaluated at {#link|compile-time|comptime#}. The code sample is
489 purposely written to show how to perform {#link|string|String Literals and Unicode Code Point Literals#}
490 substitution in the {#syntax#}print{#endsyntax#} function. The curly-braces inside of the first argument
491 are substituted with the compile-time known value inside of the second argument
492 (known as a {#link|tuple|Tuples#}). The <code>\n</code>
493 inside of the double-quotes of the first argument is the {#link|escape sequence|Escape Sequences#} for the
494 newline character. The {#link|try#} expression evaluates the result of {#syntax#}stdout.print{#endsyntax#}.
495 If the result is an error, then the {#syntax#}try{#endsyntax#} expression will return from
496 {#syntax#}main{#endsyntax#} with the error. Otherwise, the program will continue. In this case, there are no
497 more statements or expressions left to execute in the {#syntax#}main{#endsyntax#} function, so the program exits.
483 Two arguments are passed to the {#syntax#}stdout.print(){#endsyntax#} function: {#syntax#}"Hello, {s}!\n"{#endsyntax#}
484 and {#syntax#}.{"world"}{#endsyntax#}. The first argument is called a format string, which is a string containing one or
485 more placeholders. {#syntax#}"Hello, {s}!\n"{#endsyntax#} contains the placeholder {#syntax#}{s}{#endsyntax#}, which is
486 replaced with {#syntax#}"world"{#endsyntax#} from the second argument. The file <code class="file">string_literals.zig</code> in
487 {#link|String Literals and Unicode Code Point Literals|String Literals and Unicode Code Point Literals#} contains examples of format
488 strings that can be used with the {#syntax#}stdout.print(){#endsyntax#} function. The <code>\n</code> inside of
489 {#syntax#}"Hello, {s}!\n"{#endsyntax#} is the {#link|escape sequence|Escape Sequences#} for the newline character.
490 </p>
491 <p>
492 The {#link|try#} expression evaluates the result of {#syntax#}stdout.print{#endsyntax#}. If the result is an error, then the
493 {#syntax#}try{#endsyntax#} expression will return from {#syntax#}main{#endsyntax#} with the error. Otherwise, the program will continue.
494 In this case, there are no more statements or expressions left to execute in the {#syntax#}main{#endsyntax#} function, so the program exits.
498495 </p>
499496 <p>
500497 In Zig, the standard output writer's {#syntax#}print{#endsyntax#} function is allowed to fail because