1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML
><HEAD
><TITLE
>Functions</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.59"><LINK
REL="HOME"
TITLE="Gambit"
HREF="gambit.html"><LINK
REL="UP"
TITLE="The Gambit Command Language"
HREF="c524.html"><LINK
REL="PREVIOUS"
TITLE="Expressions"
HREF="x799.html"><LINK
REL="NEXT"
TITLE="Getting and suppressing console output"
HREF="x1198.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Gambit: Software Tools for Game Theory</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x799.html"
><<< Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>The Gambit Command Language</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x1198.html"
>Next >>></A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="AEN809"
>Functions</A
></H1
><P
>Functions in the GCL are rules for taking objects of specified data
types, and using them to construct and return an object of a (possibly
different) specified data type. All statements in the GCL are built
up out of function calls. In this section, we desribe the rules for
using functions in the GCL.</P
><P
>A function call consists of the name of a function followed (if the
function has parameters) by a list of parameters to the function,
enclosed in brackets. Functions return a value, which may in turn
be used as a parameter to another function call, allowing more complex
computations to be expressed.</P
><P
>Functions in the GCL can be either built-in or user defined. Also
functions can either require arguments or not. This leads to four
combinations. We label these as follows
<DIV
CLASS="TABLE"
><A
NAME="AEN814"
></A
><P
><B
>Table 3. Function types</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
CELLSPACING="0"
CELLPADDING="4"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Description</TH
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Built-in</TH
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Parameters</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Constant</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Yes</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>No</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Built-in Function</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Yes</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Yes</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Variable</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>No</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>No</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
>User-defined Function</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>No</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Yes</TD
></TR
></TBODY
></TABLE
></DIV
></P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN839"
>Constants</A
></H2
><P
>The simplest type of a function in the GCL is a constant. A constant
is a built-in function that has no arguments, and returns the same
value whenever it is called. How to construct constants for the basic
data types is described in the section on data types. Some examples
of constants follow:
<DIV
CLASS="TABLE"
><A
NAME="AEN842"
></A
><P
><B
>Table 4. Constants</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
CELLSPACING="0"
CELLPADDING="4"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Data type</TH
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Constant</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><SPAN
CLASS="TYPE"
>BOOLEAN</SPAN
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>True, False</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><SPAN
CLASS="TYPE"
>NUMBER</SPAN
> (rational precision)</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>1, -1234567/563</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><SPAN
CLASS="TYPE"
>NUMBER</SPAN
> (float precision)</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>1., -1.234567</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><SPAN
CLASS="TYPE"
>TEXT</SPAN
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>"Hello, world!"</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><SPAN
CLASS="TYPE"
>OUTPUT</SPAN
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>StdOut, NullOut</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><SPAN
CLASS="TYPE"
>INPUT</SPAN
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>StdIn</TD
></TR
></TBODY
></TABLE
></DIV
></P
><P
>You typically don't think of a constant as a function, but it is. It
is a function with no arguments, whose name is the constant itself.
You can ``execute'' a constant by simply typing its name. When you do
so, it returns a value, corresponding to the object that the constant
represents. </P
><P
>You are now ready to write your first GCL program:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>GCL1:= << "Hello, world!"
"Hello, world!"</PRE
></TD
></TR
></TABLE
></P
><P
>It is important to note that like all functions in the GCL, constants
have a data type, which is determined by the function name. If
you try and use a <SPAN
CLASS="TYPE"
>NUMBER</SPAN
> constant, say <TT
CLASS="LITERAL"
>123</TT
>, where a
<SPAN
CLASS="TYPE"
>TEXT</SPAN
> or other data type is expected, you will get an error.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN881"
>Variables</A
></H2
><P
>A variable is like a constant in that it has no arguments. It stores
one object of a particular data type, and returns it when called. The
difference between a constant and a variable is that a variable must
be created before it can be used, and once it is created, it can be
deleted or redefined if you want. To create a new variable, or to
redefine an existing variable, one can use the built-in function,
<TT
CLASS="FUNCTION"
>Assign</TT
>, which has the prototype:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Assign[name->TEXT, value<->T] =: T</PRE
></TD
></TR
></TABLE
>
for any type <SPAN
CLASS="TYPE"
>T</SPAN
>. (How to read a function's prototype is
described in more detail in the section of function calls. For now,
suffice it to say that <TT
CLASS="FUNCTION"
>Assign</TT
> takes two parameters, the first of
which is the name of the variable, and the second of which is the
value to be assigned to the variable.) The variable name can be any
string of alphanumeric characters (<TT
CLASS="LITERAL"
>a-z</TT
>, <TT
CLASS="LITERAL"
>A-Z</TT
>, or
<TT
CLASS="LITERAL"
>0-9</TT
>) beginning with a letter. So, to create a variable with
name <TT
CLASS="LITERAL"
>x</TT
> which returns the <SPAN
CLASS="TYPE"
>NUMBER</SPAN
> <TT
CLASS="LITERAL"
>1</TT
>, we can use
<TT
CLASS="FUNCTION"
>Assign</TT
> as follows:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>GCL1:= << Assign["x",1]
1</PRE
></TD
></TR
></TABLE
>
The <TT
CLASS="FUNCTION"
>Assign</TT
> function also has an infix operator form, written
<TT
CLASS="LITERAL"
>:=</TT
>. In this form, the quotes are not needed around the variable
name, and the function is not ``listable'' (see the section on Lists,
later in this chapter). So, equivalently, and more compactly,
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>GCL1:= << x := 1
1</PRE
></TD
></TR
></TABLE
></P
><P
>The <TT
CLASS="FUNCTION"
>Assign</TT
> function can be used to either create a new variable or
modify an existing one. However, it cannot be used to change the type
of a variable. Consider the sequence
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>y:=2
y:=3
y:="3"</PRE
></TD
></TR
></TABLE
>
The first call creates a new variable <TT
CLASS="LITERAL"
>y</TT
> of type
<SPAN
CLASS="TYPE"
>NUMBER</SPAN
>, with value of <TT
CLASS="LITERAL"
>2</TT
>.
The second modifies \verb+y+ to
have value <TT
CLASS="LITERAL"
>3</TT
>. Since the new assignment does not change the
type of \verb+y+, this command is fine. The third statement attempts
to change the data type of \verb+y+. This statement will result in an
error, since <TT
CLASS="FUNCTION"
>Assign</TT
> cannot be used to change the type of a
variable. To change the data type of a variable, it must first be
deleted, and then reassigned. </P
><P
>An existing variable may be deleted by the use of the
<TT
CLASS="FUNCTION"
>UnAssign</TT
>
function, with the following prototype:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>UnAssign[name->TEXT] =: BOOLEAN</PRE
></TD
></TR
></TABLE
>
After <TT
CLASS="FUNCTION"
>UnAssign</TT
> is called on a variable, the variable
is no longer defined. A subsequent call of <TT
CLASS="FUNCTION"
>Assign</TT
>
may redefine
the variable to be of any type. <TT
CLASS="FUNCTION"
>UnAssign</TT
> has a short form of
<TT
CLASS="LITERAL"
>:=</TT
> followed immediately by a linefeed or semicolon. Hence, if
\verb+y+ is a variable of type <SPAN
CLASS="TYPE"
>BOOLEAN</SPAN
> you can change it to
<SPAN
CLASS="TYPE"
>NUMBER</SPAN
> with value <TT
CLASS="LITERAL"
>3.0</TT
> in two steps as follows:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>y:=
y:= 3.0</PRE
></TD
></TR
></TABLE
></P
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN918"
>Global and static variables</A
></H3
><P
>Variables in the GCL are by default only visible in the the part of
the program in which they are defined. In otherwords, a variable
defined outside of a function will not be visible inside a GCL
function (unless it is passed by reference), and a variable defined in
a function will not be visible from outside the function. Secondly,
variables defined inside a function are deallocated when control
leaves the function. Thus, when a function is called a second time,
variables defined within that function will not ``remember'' the
values they were assigned in the last call to the function. </P
><P
>To modify the default scope and visibility of variables, the GCL uses
the prefix <TT
CLASS="LITERAL"
>$</TT
> in a variable name to represent a ``static''
variable and the prefix <TT
CLASS="LITERAL"
>$$</TT
> to represent
a global variable. A static variable
is only visible in the function in which it is defined, but remains
allocated after program control leaves the function, and retains its
last value when the function is called again. A global variable
remains allocated and visible when control passes to any function. The
following example illustrates the use of static variables:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>NewFunction[Foo[x->NUMBER]=:NUMBER,If[!IsDefined[$y],$y:=x];$y;];
GCL2:= << Foo[3]
3
GCL3:= << Foo[2]
3</PRE
></TD
></TR
></TABLE
>
and the following illustrates the use of global variables:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>$$x:=5
NewFunction[Foo[],$$x;];
GCL1:= << Foo[]
5</PRE
></TD
></TR
></TABLE
></P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN926"
>Built-in functions</A
></H2
><P
>Built-in functions in the GCL are just like the mathematical notion of
a function. They are rules which associate with each point in the
domain, a point in the range. In the case of the GCL functions, each
function has a list of arguments. Each argument must be of a specific
data type. A point in the domain is specified by specifying a value
of the correct data type for each argument of the function. </P
><P
>To execute a GCL function you write the function name, followed
(if the function is not a constant) by a comma separated list of the
arguments, enclosed in square brackets. </P
><P
>All of the built-in functions in the GCL are listed in the Function
Reference section of the manual. For each function, the function
prototype is listed. The function prototype is a template that is
used to remind you of the correct syntax for each function. </P
><P
>A function call consists of the name of a function, and a list of
parameters upon which the function is to operate. Functions return a
value, which may in turn be used as a parameter to another function
call, allowing more complex computations to be expressed.</P
><P
>A simple example of a function call is
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Plus[x->1, y->2]</PRE
></TD
></TR
></TABLE
>
This calls the function named <TT
CLASS="FUNCTION"
>Plus</TT
>,
with parameter \verb+x+ set
to the value 1 and \verb+y+ set to the value 2. Since <TT
CLASS="FUNCTION"
>Plus</TT
> is
the function for addition of two integers, the value returned would
be, as you might expect, 3.</P
><P
>In the addition example above, we called a function which is listed in
the function reference as
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Plus[x->NUMBER, y->NUMBER] =: NUMBER</PRE
></TD
></TR
></TABLE
>
This listing of a function is called its {\it prototype}.
It contains the function's name, its list of parameters, and its return
value. In this case, the function <TT
CLASS="FUNCTION"
>Plus</TT
> takes two
parameters, the
first named \verb+x+ and taking a value of type <SPAN
CLASS="TYPE"
>NUMBER</SPAN
> and the
second named \verb+y+ and taking a value of type <SPAN
CLASS="TYPE"
>NUMBER</SPAN
>, and
returns a value of type <SPAN
CLASS="TYPE"
>NUMBER</SPAN
>.</P
><P
>Because the parameters have explicit names, it is possible to rearrange
the order in which parameters are listed when a function is called.
Thus, we could write out sample call equivalently as
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Plus[y->2, x->1]</PRE
></TD
></TR
></TABLE
>
and achieve the same effect.</P
><P
>Explicitly specifying the formal names for parameters all the time
will prove tedious and can hinder readability. For these reasons, it is
also legal to specify parameters without their associated formal names.
These are called passing {\it anonymous} parameters. Our addition
example could thus also be written
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Plus[1, 2]</PRE
></TD
></TR
></TABLE
></P
><P
>When used without specifying the formal names, however, function
calls are restricted to specifying parameters in exactly the same
order as listed in the function prototype. In our example, the GCL
interpreter would have no way of distinguishing whether we meant 1 to
be the value of \verb+x+ or the value of \verb+y+, and vice versa.
While in the case of addition we may flip the values of the parameters
without having an effect on the result, in general this is not the
case.</P
><P
>It is permitted to mix the two styles of parameter specification,
subject to the following rules:
\begin{itemize}
\item All anonymous parameters must be specified before any named
parameters
\item No parameters may be omitted in the anonymous parameter list.
If $k$ parameters are specified anonymously, they must match
one-for-one the first $k$ parameters in the function's prototype.
\item Once a named parameter has been specified, all succeeding
parameters must be named, even if the first named parameter appeared
in the same place in the parameter list as it does in the prototype.
\end{itemize}
\noindent Therefore, it would be legal to write
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Plus[1, y->2]</PRE
></TD
></TR
></TABLE
>
but
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Plus[x->1, 2]</PRE
></TD
></TR
></TABLE
>
is illegal since it violates the third condition.</P
><P
>To be more precise, the function <TT
CLASS="FUNCTION"
>Plus</TT
> comes in several different
variations listed in the function reference:
\begin{verbatim}
Plus[x->NUMBER, y->NUMBER] =: NUMBER
Plus[x->TEXT, y->TEXT] =: TEXT
Plus[x->MIXED, y->MIXED] =: MIXED
Plus[x->BEHAV, y->BEHAV] =: BEHAV
\end{verbatim}
This is an example of function {\it overloading}. This
means that one function name may have several possible parameter
lists, sometimes called {\it signatures}. The GCL interpreter is
capable of determining which version of the function to use by
analyzing the names and types of the parameters used.</P
><P
>Since a function may have multiple signatures, it is conceivable that
a function call might be ambiguous, in the sense that its parameters
match more than one signature for that function. However, no function
call that is complete may be ambiguous from the way that signatures
have been chosen for the predefined functions. Any function call
flagged by the interpreter as ambiguous must be missing at least one
parameter.</P
><P
>Some functions have parameters which are optional, in the sense that
they need not be specified in order to call the function. These
parameters are indicated in the function's prototype by being
surrounded by curly braces. (Note that these braces should not be
included in the function call when specifying an optional parameter.)
If an optional parameter is left unspecified in a function call, a
default value is assumed, as given in the function's documentation.</P
><P
>For a function, all required parameters always precede any optional
parameters. Optional parameters may also be specified anonymously,
subject to the above rules on parameter specification.</P
><P
>All parameters so far have been passed by {\it value}, that is, a copy
of the value of the parameter is given to the function to which it is
passed. These parameters may not be modified by the function. It is
also possible to have parameters to a function passed by {\it
reference}. This means that the function does not receive a copy of
the value, but rather the memory location of the value itself. Thus,
the function may modify the value of a parameter passed by reference.</P
><P
>The symbol for passing a parameter by reference, both in a function's
prototype and in a function call, is <TT
CLASS="LITERAL"
><-></TT
>. Constants may not be
passed by reference. Reference parameters may be specified
anonymously just like a value parameter, subject to the usual rules.
It is a run-time error to attempt to pass a value to a reference
parameter, or vice versa.</P
><P
>In the case where functions have parameters which are subtypes,
it is preferred to match to the subtype over the parent type. For example,
suppose the following two signatures have been defined:
\begin{verbatim}
Foo[x->INTEGER] =: INTEGER
Foo[x->NUMBER] =: NUMBER
\end{verbatim}
Then, a call of <TT
CLASS="LITERAL"
>Foo[3]</TT
> resolves to the first signature (since the
value passed is an integer), and <TT
CLASS="LITERAL"
>Foo[3.5]</TT
>
resolves to the second
(since it is a number, but not specifically an integer).</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN961"
>User-defined functions</A
></H2
><P
>As GCL programs become more and more complex, frequently there are
complicated operations which must be performed repeatedly. The
command language therefore supports user-defined functions, which
allow for defining sections of code which may be called later.</P
><P
>A new function can be created using the function <TT
CLASS="FUNCTION"
>NewFunction</TT
>.
For example, one might define a function to compute the absolute value
of an <SPAN
CLASS="TYPE"
>NUMBER</SPAN
>
as such:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>NewFunction[Abs[n->NUMBER],
If[n > 0, n, If[n < 0, -n, 0]];
];</PRE
></TD
></TR
></TABLE
>
After defining the <TT
CLASS="FUNCTION"
>Abs</TT
> function, it may be called in
exactly the same way a system-supplied predefined function may. The
return value of the function is the value of the last statement
executed.</P
><P
>Parameter type matching rules apply to user defined functions in
exactly the same way as to predefined functions. From the function's
point of view, the parameter list is a list of variables on which
assignments are automatically done at the beginning of the function
execution. So, taking the <TT
CLASS="FUNCTION"
>Abs</TT
> example above, in executing the
call
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Abs[42]</PRE
></TD
></TR
></TABLE
>
\noindent an assignment \verb+n := 42+ is implicitly performed before
the body of the function is executed.</P
><P
>It is also possible to pass variables by ``reference'' to a
user-defined function in the same way as a predefined function. In
this case, the function's ``local'' variable is stored in the same
physical location in the computer, and modifying the value locally
also takes effect on the variable passed to the function. For
example, it might be useful instead to define \verb+Abs+ as:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>NewFunction[Abs[n<->NUMBER],
If[n > 0, n, If[n < 0, n := -n, 0]]]</PRE
></TD
></TR
></TABLE
>
in which case the function would still return the absolute
value of \verb+n+, but also modify the variable passed to \verb+n+ to
be the absolute value of the input \verb+n+. So,
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>q := -37;
Abs[q]</PRE
></TD
></TR
></TABLE
>
would result in the variable \verb+q+ containing the value
37 at the conclusion of execution.</P
><P
>Each function has its own ``scope'', or set of variables. Within a
function body, the only variables which are visible are those which
are declared in the parameter list of the function (this is \verb+n+
in the <TT
CLASS="FUNCTION"
>Abs</TT
> example above), and those which are created during
the function's execution. That is, no ``global'' or outside variables
may be accessed directly by the function. For example, if the user
typed in the following:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>i := 4;
NewFunction[FooFunc[x->NUMBER], x * i]</PRE
></TD
></TR
></TABLE
>
later execution of the <TT
CLASS="FUNCTION"
>FooFunc</TT
> would yield an
``undefined variable i'' error message, since \verb+i+ is never
defined within the function. If instead <TT
CLASS="FUNCTION"
>FooFunc</TT
> had been
defined as follows:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>NewFunction[FooFunc[x->NUMBER], i := 13, x * i]</PRE
></TD
></TR
></TABLE
>
<TT
CLASS="FUNCTION"
>FooFunc</TT
> would always return 13 times the value of the
parameter \verb+x+, since the value of \verb+i+ inside <TT
CLASS="FUNCTION"
>FooFunc</TT
> is always 13, regardless of the value of \verb+i+ outside of the
function.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN983"
>Aliases for function calls</A
></H2
><P
>There are several functions which are so commonly used that special
``short forms'' are defined for them. We already saw one example with
the function <TT
CLASS="FUNCTION"
>Assign</TT
>, which has the short form
<TT
CLASS="LITERAL"
>:=</TT
>. Most
functions with short forms are the standard arithmetic and logic
operators, for which the usual binary infix or unary prefix notations
are supported. The example of addition used in a previous section may
more familiarly be written
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>1 + 2</PRE
></TD
></TR
></TABLE
>
which expression is converted to the ``long form'' function
call by the interpreter. Note that formal names may not be specified
in a ``short form'' call, and the order of parameters is therefore
significant.</P
><P
>Here is a list of the functions thus abbreviated, and their ``short
form'' equivalents:
<DIV
CLASS="TABLE"
><A
NAME="AEN990"
></A
><P
><B
>Table 5. Operators in GCL</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
CELLSPACING="0"
CELLPADDING="4"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Function</TH
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Operator(s)</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>And[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x && y</TT
>, <TT
CLASS="LITERAL"
>x AND y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Assign[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x := y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Concat[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x & y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Divide[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x / y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Dot[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x . y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Equal[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x = y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Greater[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x > y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>GreaterEqual[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x >= y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>IntegerDivide[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x DIV y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Less[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x < y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>LessEqual[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x <= y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Minus[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x - y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Modulus[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x & y</TT
>, <TT
CLASS="LITERAL"
>x MOD y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Not[x]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>NOT x</TT
>, <TT
CLASS="LITERAL"
>!x</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>NotEqual[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x != y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>NthChar[text,n]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>text[[n]]</TT
>, <TT
CLASS="LITERAL"
>text_n</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>NthChild[node,n]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>node#n</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>NthElement[list,n]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>list[[n]]</TT
>, <TT
CLASS="LITERAL"
>list_n</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Or[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x || y</TT
>, <TT
CLASS="LITERAL"
>x OR y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Parentheses[x]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>(x)</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Plus[x]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x + y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Power[x]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x ^ y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Print[x]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
><< x</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Read[in,x]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>in >> x</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Times[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x * y</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>UnAssign[x,y]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>x :=</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="FUNCTION"
>Write[out,x]</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>out << x</TT
></TD
></TR
></TBODY
></TABLE
></DIV
></P
><P
>When functions are written in their canonical forms, no ambiguity
arises in the order of evaluation: In order to evaluate a function,
all arguments must be evaluated first. Arguments are evaluated from
left-to-right as specified in the function call. This leads to a
recursive structure of evaluation, which stops only when an argument
being evaluated is a constant function (i. e., a function with no
arguments).</P
><P
>When short form forms are used, then ambiguity can arise in the
intended order of evaluation. For example, the statement \verb & a + b * c& ,
could be meant as \verb+Plus[a,Times[b,c]]+ or as
\verb+Times[Plus[a,b],c]+. In order to resolve such ambiguities, all
functions that have a short form representation are given an order of
precedence. When a statement is parsed by the GCL, it is first
scanned from left to right, replacing each short form expression at
the top level of precedence with its canonical form. Then it is
scanned again replacing each short form expression at the second level
of precedence with its canonical form, and so on, until all short form
expressions have been eliminated.</P
><P
>The order of precedence for built-in functions is as follows:
<DIV
CLASS="TABLE"
><A
NAME="AEN1142"
></A
><P
><B
>Table 6. Order of precedence</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
CELLSPACING="0"
CELLPADDING="4"
CLASS="CALSTABLE"
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>()</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>:=</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>>></TT
> <TT
CLASS="LITERAL"
><<</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>||</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>&&</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>NOT</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>=</TT
> <TT
CLASS="LITERAL"
>!=</TT
>
<TT
CLASS="LITERAL"
><</TT
> <TT
CLASS="LITERAL"
><=</TT
>
<TT
CLASS="LITERAL"
>></TT
> <TT
CLASS="LITERAL"
>>=</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>+</TT
> <TT
CLASS="LITERAL"
>-</TT
> <TT
CLASS="LITERAL"
>&</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>*</TT
> <TT
CLASS="LITERAL"
>.</TT
>
<TT
CLASS="LITERAL"
>/</TT
> <TT
CLASS="LITERAL"
>DIV</TT
>
<TT
CLASS="LITERAL"
>MOD</TT
> <TT
CLASS="LITERAL"
>^</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
>(unary) <TT
CLASS="LITERAL"
>+</TT
> <TT
CLASS="LITERAL"
>-</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>[[ ]]</TT
> <TT
CLASS="LITERAL"
>_</TT
></TD
></TR
></TBODY
></TABLE
></DIV
>
Thus, the statement \verb & a + b * c& would become
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Plus[a,b*c]
Plus[a,Times[b,c]]</PRE
></TD
></TR
></TABLE
>
On the other hand, the statement \verb&( a + b ) * c& would become
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Parentheses[a+b]*c
Parentheses[Plus[a,b]]*c
Times[Parentheses[Plus[a,b]],c]</PRE
></TD
></TR
></TABLE
>
which, since <TT
CLASS="FUNCTION"
>Parentheses</TT
> is just the identity mapping, is
equivalent to
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>Times[Plus[a,b],c]</PRE
></TD
></TR
></TABLE
></P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x799.html"
><<< Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="gambit.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x1198.html"
>Next >>></A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Expressions</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c524.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Getting and suppressing console output</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
|