comparison website/src/manual.html.luan @ 685:1e4b0bc0202d

update documentation
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 16 Apr 2016 22:37:47 -0600
parents c4216a583de4
children ca169567ce07
comparison
equal deleted inserted replaced
684:41f791e4206d 685:1e4b0bc0202d
470 (If necessary, 470 (If necessary,
471 the metamethod itself can call <a href="#Luan.raw_set"><code>raw_set</code></a> 471 the metamethod itself can call <a href="#Luan.raw_set"><code>raw_set</code></a>
472 to do the assignment.) 472 to do the assignment.)
473 </li> 473 </li>
474 474
475 <li><p><b>"call": </b>
476 The call operation <code>func(args)</code>.
477
478 This event happens when Luan tries to call a table.
479 The metamethod is looked up in <code>func</code>.
480 If present,
481 the metamethod is called with <code>func</code> as its first argument,
482 followed by the arguments of the original call (<code>args</code>).
483 </li>
484
485 </ul> 475 </ul>
486 476
487 477
488 478
489 479
524 514
525 <p> 515 <p>
526 Luan ignores spaces and comments 516 Luan ignores spaces and comments
527 between lexical elements (tokens), 517 between lexical elements (tokens),
528 except as delimiters between names and keywords. 518 except as delimiters between names and keywords.
529 Luan generally considers the end of a line to be the end of a statement. This catches errors and encourages readability. The exception to this is in paranthesis <em>(...)</em> where the end of line is treated as white space. 519 Luan considers the end of a line to be the end of a statement. This catches errors and encourages readability. If you want to continue a statement on another line, you can use a backslash followed by a newline which will be treated as white space.
530 520
531 <p> 521 <p>
532 <em>Names</em> 522 <em>Names</em>
533 (also called <em>identifiers</em>) 523 (also called <em>identifiers</em>)
534 in Luan can be any string of letters, 524 in Luan can be any string of letters,
1491 </pre> 1481 </pre>
1492 1482
1493 <p> 1483 <p>
1494 In a function call, 1484 In a function call,
1495 first prefixexp and args are evaluated. 1485 first prefixexp and args are evaluated.
1496 If the value of prefixexp has type <em>function</em>, 1486 The value of prefixexp must have type <em>function</em>.
1497 then this function is called 1487 This function is called
1498 with the given arguments. 1488 with the given arguments.
1499 Otherwise, the prefixexp "call" metamethod is called,
1500 having as first parameter the value of prefixexp,
1501 followed by the original call arguments
1502 (see <a href="#meta">Metatables and Metamethods</a>).
1503 1489
1504 1490
1505 <p> 1491 <p>
1506 Arguments have the following syntax: 1492 Arguments have the following syntax:
1507 1493
1518 that is, the argument list is a single new table. 1504 that is, the argument list is a single new table.
1519 A call of the form <code>f'<em>string</em>'</code> 1505 A call of the form <code>f'<em>string</em>'</code>
1520 (or <code>f"<em>string</em>"</code> or <code>f[[<em>string</em>]]</code>) 1506 (or <code>f"<em>string</em>"</code> or <code>f[[<em>string</em>]]</code>)
1521 is syntactic sugar for <code>f('<em>string</em>')</code>; 1507 is syntactic sugar for <code>f('<em>string</em>')</code>;
1522 that is, the argument list is a single literal string. 1508 that is, the argument list is a single literal string.
1523
1524
1525 <p>
1526 A call of the form <code>return <em>functioncall</em></code> is called
1527 a <em>tail call</em>.
1528 Luan implements <em>proper tail calls</em>
1529 (or <em>proper tail recursion</em>):
1530 in a tail call,
1531 the called function reuses the stack entry of the calling function.
1532 Therefore, there is no limit on the number of nested tail calls that
1533 a program can execute.
1534 However, a tail call erases any debug information about the
1535 calling function.
1536 Note that a tail call only happens with a particular syntax,
1537 where the <b>return</b> has one single function call as argument;
1538 this syntax makes the calling function return exactly
1539 the returns of the called function.
1540 So, none of the following examples are tail calls:
1541
1542 <pre>
1543 return (f(x)) -- results adjusted to 1
1544 return 2 * f(x)
1545 return x, f(x) -- additional results
1546 f(x); return -- results discarded
1547 return x or f(x) -- results adjusted to 1
1548 </pre>
1549 1509
1550 1510
1551 1511
1552 1512
1553 <h4 heading><a name="fn_def">Function Definitions</a></h4> 1513 <h4 heading><a name="fn_def">Function Definitions</a></h4>