/usr/share/doc/yacas-doc/html/refchapter27.html is in yacas-doc 1.3.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <html>
<head>
<title>Variables</title>
<link rel="stylesheet" href="yacas.css" TYPE="text/css" MEDIA="screen">
</head>
<body>
<a name="c27">
</a>
(directly go to documentation on : <a href="refchapter27.html#:=" target='Chapters' title="assign a variable or a list; define a function">:=</a>, <a href="refchapter27.html#Set" target='Chapters' title="assignment">Set</a>, <a href="refchapter27.html#Clear" target='Chapters' title="undo an assignment">Clear</a>, <a href="refchapter27.html#Local" target='Chapters' title="declare new local variables">Local</a>, <a href="refchapter27.html#++" target='Chapters' title="increment variable">++</a>, <a href="refchapter27.html#--" target='Chapters' title="decrement variable">--</a>, <a href="refchapter27.html#Object" target='Chapters' title="create an incomplete type">Object</a>, <a href="refchapter27.html#SetGlobalLazyVariable" target='Chapters' title="global variable is to be evaluated lazily">SetGlobalLazyVariable</a>, <a href="refchapter27.html#UniqueConstant" target='Chapters' title="create a unique identifier">UniqueConstant</a>, <a href="refchapter27.html#LocalSymbols" target='Chapters' title="create unique local symbols with given prefix">LocalSymbols</a>.
)<h1>
27. Variables
</h1>
<p> </p>
<center><table>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#:=" target='Chapters' title="assign a variable or a list; define a function">:=</a></td>
<td>assign a variable or a list; define a function</td>
</tr>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#Set" target='Chapters' title="assignment">Set</a></td>
<td>assignment</td>
</tr>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#Clear" target='Chapters' title="undo an assignment">Clear</a></td>
<td>undo an assignment</td>
</tr>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#Local" target='Chapters' title="declare new local variables">Local</a></td>
<td>declare new local variables</td>
</tr>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#++" target='Chapters' title="increment variable">++</a></td>
<td>increment variable</td>
</tr>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#--" target='Chapters' title="decrement variable">--</a></td>
<td>decrement variable</td>
</tr>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#Object" target='Chapters' title="create an incomplete type">Object</a></td>
<td>create an incomplete type</td>
</tr>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#SetGlobalLazyVariable" target='Chapters' title="global variable is to be evaluated lazily">SetGlobalLazyVariable</a></td>
<td>global variable is to be evaluated lazily</td>
</tr>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#UniqueConstant" target='Chapters' title="create a unique identifier">UniqueConstant</a></td>
<td>create a unique identifier</td>
</tr>
<tr BGCOLOR=#E0E0E0>
<td><a href="refchapter27.html#LocalSymbols" target='Chapters' title="create unique local symbols with given prefix">LocalSymbols</a></td>
<td>create unique local symbols with given prefix</td>
</tr>
</table></center>
<a name=":=">
</a>
<a name=":=">
</a>
<h3>
<hr>:= -- assign a variable or a list; define a function
</h3>
<h5 align=right>Standard library</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
var := expr
{var1, var2, ...} := {expr1, expr2, ...}
var[i] := expr
fn(arg1, arg2, ...) := expr
</pre></tr>
</table>
Precedence:
10000
<p>
<h5>
Parameters:
</h5>
<b><tt>var</tt></b> -- atom, variable which should be assigned
<p>
<b><tt>expr</tt></b> -- expression to assign to the variable or body of function
<p>
<b><tt>i</tt></b> -- index (can be integer or string)
<p>
<b><tt>fn</tt></b> -- atom, name of a new function to define
<p>
<b><tt>arg1</tt></b>, <b><tt>arg2</tt></b> -- atoms, names of arguments of the new function <b><tt>fn</tt></b>
<p>
<h5>
Description:
</h5>
The <b><tt>:=</tt></b> operator can be used
in a number of ways. In all cases, some sort of assignment or definition takes
place.
<p>
The first form is the most basic one. It evaluates the expression on
the right-hand side and assigns it to the variable named on the
left-hand side. The left-hand side is not evaluated. The evaluated
expression is also returned.
<p>
The second form is a small extension, which allows one to do multiple
assignments. The first entry in the list on the right-hand side is
assigned to the first variable mentioned in the left-hand side, the
second entry on the right-hand side to the second variable on the
left-hand side, etc. The list on the right-hand side must have at
least as many entries as the list on the left-hand side. Any excess
entries are silently ignored. The result of the expression is the list
of values that have been assigned.
<p>
The third form allows one to change an entry in the list. If the index
"i" is an integer, the "i"-th entry in the list is changed to the
expression on the right-hand side. It is assumed that the length of
the list is at least "i". If the index "i" is a string, then
"var" is considered to be an associative list (sometimes called hash
table), and the key "i" is paired with the value "exp". In both
cases, the right-hand side is evaluated before the assignment and the
result of the assignment is <b><tt>True</tt></b>.
<p>
The last form defines a function. For example, the assignment <b><tt>fn(x) := x^2</tt></b> removes any rules previously associated with <b><tt>fn(x)</tt></b> and defines the rule <b><tt>fn(_x) <-- x^2</tt></b>. Note that the left-hand side may take a different form if
<b><tt>fn</tt></b> is defined to be a prefix, infix or bodied function. This case
is special since the right-hand side is not evaluated
immediately, but only when the function <b><tt>fn</tt></b> is used. If this takes
time, it may be better to force an immediate evaluation with <b><tt>Eval</tt></b> (see the last example). If the expression on the right hand side begins with <b><tt>Eval()</tt></b>, then it <i>will</i> be evaluated before defining the new function.
<p>
A variant of the function definition can be used to make a function accepting a variable number of arguments. The last argument
<p>
<h5>
Examples:
</h5>
A simple assignment:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> a := Sin(x) + 3;
Out> Sin(x)+3;
In> a;
Out> Sin(x)+3;
</pre></tr>
</table>
<p>
Multiple assignments:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> {a,b,c} := {1,2,3};
Out> {1,2,3};
In> a;
Out> 1;
In> b+c;
Out> 5;
</pre></tr>
</table>
<p>
Assignment to a list:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> xs := { 1,2,3,4,5 };
Out> {1,2,3,4,5};
In> xs[3] := 15;
Out> True;
In> xs;
Out> {1,2,15,4,5};
</pre></tr>
</table>
<p>
Building an associative list:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> alist := {};
Out> {};
In> alist["cherry"] := "red";
Out> True;
In> alist["banana"] := "yellow";
Out> True;
In> alist["cherry"];
Out> "red";
In> alist;
Out> {{"banana","yellow"},{"cherry","red"}};
</pre></tr>
</table>
<p>
Defining a function:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> f(x) := x^2;
Out> True;
In> f(3);
Out> 9;
In> f(Sin(a));
Out> Sin(a)^2;
</pre></tr>
</table>
<p>
Defining a function with variable number of arguments:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> f(x, ...) := If(IsList(x),Sum(x),x);
Out> True;
In> f(2);
Out> 2;
In> f(1,2,3);
Out> 6;
</pre></tr>
</table>
<p>
Defining a new infix operator:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> Infix("*&*",10);
Out> True;
In> x1 *&* x2 := x1/x2 + x2/x1;
Out> True;
In> Sin(a) *&* Cos(a);
Out> Tan(1)+Cos(1)/Sin(1);
In> Clear(a);
Out> True;
In> Sin(a) *&* Exp(a);
Out> Sin(a)/Exp(a)+Exp(a)/Sin(a);
</pre></tr>
</table>
<p>
In the following example, it may take some time to compute the Taylor
expansion. This has to be done every time the function <b><tt>f</tt></b> is called.
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> f(a) := Taylor(x,0,25) Sin(x);
Out> True;
In> f(1);
Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880-
x^11/39916800+x^13/6227020800-x^15/
1307674368000+x^17/355687428096000-x^19/
121645100408832000+x^21/51090942171709440000
-x^23/25852016738884976640000+x^25
/15511210043330985984000000;
In> f(2);
Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880-
x^11/39916800+x^13/6227020800-x^15
/1307674368000+x^17/355687428096000-x^19/
121645100408832000+x^21/51090942171709440000
-x^23/25852016738884976640000+x^25/
15511210043330985984000000;
</pre></tr>
</table>
<p>
The remedy is to evaluate the Taylor expansion immediately. Now the
expansion is computed only once.
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> f(a) := Eval(Taylor(x,0,25) Sin(x));
Out> True;
In> f(1);
Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880-
x^11/39916800+x^13/6227020800-x^15/
1307674368000+x^17/355687428096000-x^19/
121645100408832000+x^21/51090942171709440000
-x^23/25852016738884976640000+x^25
/15511210043330985984000000;
In> f(2);
Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880-
x^11/39916800+x^13/6227020800-x^15
/1307674368000+x^17/355687428096000-x^19/
121645100408832000+x^21/51090942171709440000
-x^23/25852016738884976640000+x^25/
15511210043330985984000000;
</pre></tr>
</table>
<p>
<h5>
See also:
</h5>
<a href="ref.html?Set" target="Chapters">
Set
</a>
, <a href="ref.html?Clear" target="Chapters">
Clear
</a>
, <a href="ref.html?[]" target="Chapters">
[]
</a>
, <a href="ref.html?Rule" target="Chapters">
Rule
</a>
, <a href="ref.html?Infix" target="Chapters">
Infix
</a>
, <a href="ref.html?Eval" target="Chapters">
Eval
</a>
, <a href="ref.html?Function" target="Chapters">
Function
</a>
.<a name="Set">
</a>
<a name="set">
</a>
<h3>
<hr>Set -- assignment
</h3>
<h5 align=right>Internal function</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
Set(var, exp)
</pre></tr>
</table>
<p>
<h5>
Parameters:
</h5>
<b><tt>var</tt></b> -- variable which should be assigned
<p>
<b><tt>exp</tt></b> -- expression to assign to the variable
<p>
<h5>
Description:
</h5>
The expression "exp" is evaluated and assigned it to the variable
named "var". The first argument is not evaluated. The value True
is returned.
<p>
The statement <b><tt>Set(var, exp)</tt></b> is equivalent to <b><tt>var := exp</tt></b>, but the <b><tt>:=</tt></b> operator
has more uses, e.g. changing individual entries in a list.
<p>
<h5>
Examples:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> Set(a, Sin(x)+3);
Out> True;
In> a;
Out> Sin(x)+3;
</pre></tr>
</table>
<p>
<h5>
See also:
</h5>
<a href="ref.html?Clear" target="Chapters">
Clear
</a>
, <a href="ref.html?:=" target="Chapters">
:=
</a>
.<a name="Clear">
</a>
<a name="clear">
</a>
<h3>
<hr>Clear -- undo an assignment
</h3>
<h5 align=right>Internal function</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
Clear(var, ...)
</pre></tr>
</table>
<p>
<h5>
Parameters:
</h5>
<b><tt>var</tt></b> -- name of variable to be cleared
<p>
<h5>
Description:
</h5>
All assignments made to the variables listed as arguments are
undone. From now on, all these variables remain unevaluated (until a
subsequent assignment is made). The result of the expression is
True.
<p>
<h5>
Examples:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> a := 5;
Out> 5;
In> a^2;
Out> 25;
In> Clear(a);
Out> True;
In> a^2;
Out> a^2;
</pre></tr>
</table>
<p>
<h5>
See also:
</h5>
<a href="ref.html?Set" target="Chapters">
Set
</a>
, <a href="ref.html?:=" target="Chapters">
:=
</a>
.<a name="Local">
</a>
<a name="local">
</a>
<h3>
<hr>Local -- declare new local variables
</h3>
<h5 align=right>Internal function</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
Local(var, ...)
</pre></tr>
</table>
<p>
<h5>
Parameters:
</h5>
<b><tt>var</tt></b> -- name of variable to be declared as local
<p>
<h5>
Description:
</h5>
All variables in the argument list are declared as local
variables. The arguments are not evaluated. The value True is
returned.
<p>
By default, all variables in Yacas are global. This means that the
variable has the same value everywhere. But sometimes it is useful to
have a private copy of some variable, either to prevent the outside
world from changing it or to prevent accidental changes to the outside
world. This can be achieved by declaring the variable local. Now only
expressions within the <b><tt>Prog</tt></b> block (or its
syntactic equivalent, the <b><tt>[ ]</tt></b> block) can access
and change it. Functions called within this block cannot access the
local copy unless this is specifically allowed with <b><tt>UnFence</tt></b>.
<p>
<h5>
Examples:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> a := 3;
Out> 3;
In> [ a := 4; a; ];
Out> 4;
In> a;
Out> 4;
In> [ Local(a); a := 5; a; ];
Out> 5;
In> a;
Out> 4;
</pre></tr>
</table>
<p>
In the first block, <b><tt>a</tt></b> is not declared local and
hence defaults to be a global variable. Indeed, changing the variable
inside the block also changes the value of <b><tt>a</tt></b>
outside the block. However, in the second block <b><tt>a</tt></b>
is defined to be local and now the value outside the block stays the
same, even though <b><tt>a</tt></b> is assigned the value 5 inside
the block.
<p>
<h5>
See also:
</h5>
<a href="ref.html?LocalSymbols" target="Chapters">
LocalSymbols
</a>
, <a href="ref.html?Prog" target="Chapters">
Prog
</a>
, <a href="ref.html?[]" target="Chapters">
[]
</a>
, <a href="ref.html?UnFence" target="Chapters">
UnFence
</a>
.<a name="++">
</a>
<a name="++">
</a>
<h3>
<hr>++ -- increment variable
</h3>
<h5 align=right>Standard library</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
var++
</pre></tr>
</table>
<p>
<h5>
Parameters:
</h5>
<b><tt>var</tt></b> -- variable to increment
<p>
<h5>
Description:
</h5>
The variable with name "var" is incremented, i.e. the number 1 is
added to it. The expression <b><tt>x++</tt></b> is equivalent to
the assignment <b><tt>x := x + 1</tt></b>, except that the
assignment returns the new value of <b><tt>x</tt></b> while <b><tt>x++</tt></b> always returns true. In this respect, Yacas' <b><tt>++</tt></b> differs from the corresponding operator in the
programming language C.
<p>
<h5>
Examples:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> x := 5;
Out> 5;
In> x++;
Out> True;
In> x;
Out> 6;
</pre></tr>
</table>
<p>
<h5>
See also:
</h5>
<a href="ref.html?--" target="Chapters">
--
</a>
, <a href="ref.html?:=" target="Chapters">
:=
</a>
.<a name="--">
</a>
<a name="--">
</a>
<h3>
<hr>-- -- decrement variable
</h3>
<h5 align=right>Standard library</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
var--
</pre></tr>
</table>
<p>
<h5>
Parameters:
</h5>
<b><tt>var</tt></b> -- variable to decrement
<p>
<h5>
Description:
</h5>
The variable with name "var" is decremented, i.e. the number 1 is
subtracted from it. The expression <b><tt>x--</tt></b> is
equivalent to the assignment <b><tt>x := x - 1</tt></b>, except
that the assignment returns the new value of <b><tt>x</tt></b>
while <b><tt>x--</tt></b> always returns true. In this respect,
Yacas' <b><tt>--</tt></b> differs from the corresponding operator
in the programming language C.
<p>
<h5>
Examples:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> x := 5;
Out> 5;
In> x--;
Out> True;
In> x;
Out> 4;
</pre></tr>
</table>
<p>
<h5>
See also:
</h5>
<a href="ref.html?++" target="Chapters">
++
</a>
, <a href="ref.html?:=" target="Chapters">
:=
</a>
.<a name="Object">
</a>
<a name="object">
</a>
<h3>
<hr>Object -- create an incomplete type
</h3>
<h5 align=right>Standard library</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
Object("pred", exp)
</pre></tr>
</table>
<p>
<h5>
Parameters:
</h5>
<b><tt>pred</tt></b> -- name of the predicate to apply
<p>
<b><tt>exp</tt></b> -- expression on which "pred" should be applied
<p>
<h5>
Description:
</h5>
This function returns "obj" as soon as "pred" returns <b><tt>True</tt></b> when applied on "obj". This is used to declare
so-called incomplete types.
<p>
<h5>
Examples:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> a := Object("IsNumber", x);
Out> Object("IsNumber",x);
In> Eval(a);
Out> Object("IsNumber",x);
In> x := 5;
Out> 5;
In> Eval(a);
Out> 5;
</pre></tr>
</table>
<p>
<h5>
See also:
</h5>
<a href="ref.html?IsNonObject" target="Chapters">
IsNonObject
</a>
.<a name="SetGlobalLazyVariable">
</a>
<a name="setgloballazyvariable">
</a>
<h3>
<hr>SetGlobalLazyVariable -- global variable is to be evaluated lazily
</h3>
<h5 align=right>Internal function</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
SetGlobalLazyVariable(var,value)
</pre></tr>
</table>
<p>
<h5>
Parameters:
</h5>
<b><tt>var</tt></b> -- variable (held argument)
<p>
<b><tt>value</tt></b> -- value to be set to (evaluated before it is assigned)
<p>
<h5>
Description:
</h5>
<b><tt>SetGlobalLazyVariable</tt></b> enforces that a global variable will re-evaluate
when used. This functionality doesn't survive if <b><tt>Clear(var)</tt></b>
is called afterwards.
<p>
Places where this is used include the global variables <b><tt>%</tt></b> and <b><tt>I</tt></b>.
<p>
The use of lazy in the name stems from the concept of lazy evaluation.
The object the global variable is bound to will only be evaluated when
called. The <b><tt>SetGlobalLazyVariable</tt></b> property only holds once: after
that, the result of evaluation is stored in the global variable, and it won't be reevaluated again:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> SetGlobalLazyVariable(a,Hold(Taylor(x,0,30)Sin(x)))
Out> True
</pre></tr>
</table>
<p>
Then the first time you call <b><tt>a</tt></b> it evaluates <b><tt>Taylor(...)</tt></b> and assigns the result to <b><tt>a</tt></b>. The next time
you call <b><tt>a</tt></b> it immediately returns the result.
<b><tt>SetGlobalLazyVariable</tt></b> is called for <b><tt>%</tt></b> each time <b><tt>%</tt></b> changes.
<p>
The following example demonstrates the sequence of execution:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> SetGlobalLazyVariable(test,Hold(Write("hello")))
Out> True
</pre></tr>
</table>
<p>
The text "hello" is not written out to screen yet. However, evaluating
the variable <b><tt>test</tt></b> forces the expression to be evaluated:
<p>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> test
"hello"Out> True
</pre></tr>
</table>
<p>
<h5>
Examples:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> Set(a,Hold(2+3))
Out> True
In> a
Out> 2+3
In> SetGlobalLazyVariable(a,Hold(2+3))
Out> True
In> a
Out> 5
</pre></tr>
</table>
<p>
<h5>
See also:
</h5>
<a href="ref.html?Set" target="Chapters">
Set
</a>
, <a href="ref.html?Clear" target="Chapters">
Clear
</a>
, <a href="ref.html?Local" target="Chapters">
Local
</a>
, <a href="ref.html?%" target="Chapters">
%
</a>
, <a href="ref.html?I" target="Chapters">
I
</a>
.<a name="UniqueConstant">
</a>
<a name="uniqueconstant">
</a>
<h3>
<hr>UniqueConstant -- create a unique identifier
</h3>
<h5 align=right>Standard library</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
UniqueConstant()
</pre></tr>
</table>
<p>
<h5>
Description:
</h5>
This function returns a unique constant atom each time you call
it. The atom starts with a C character, and a unique number is
appended to it.
<p>
<h5>
Examples:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> UniqueConstant()
Out> C9
In> UniqueConstant()
Out> C10
</pre></tr>
</table>
<p>
<h5>
See also:
</h5>
<a href="ref.html?LocalSymbols" target="Chapters">
LocalSymbols
</a>
.<a name="LocalSymbols">
</a>
<a name="localsymbols">
</a>
<h3>
<hr>LocalSymbols -- create unique local symbols with given prefix
</h3>
<h5 align=right>Standard library</h5><h5>
Calling format:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
LocalSymbols(var1, var2, ...) body
</pre></tr>
</table>
<p>
<h5>
Parameters:
</h5>
<b><tt>var1</tt></b>, <b><tt>var2</tt></b>, ... -- atoms, symbols to be made local
<p>
<b><tt>body</tt></b> -- expression to execute
<p>
<h5>
Description:
</h5>
Given the symbols passed as the first arguments to LocalSymbols a set of local
symbols will be created, and creates unique ones for them, typically of the
form <b><tt>$<symbol><number></tt></b>, where <b><tt>symbol</tt></b> was the symbol entered by the user,
and <b><tt>number</tt></b> is a unique number. This scheme was used to ensure that a generated
symbol can not accidentally be entered by a user.
<p>
This is useful in cases where a guaranteed free variable is needed,
for example, in the macro-like functions (<b><tt>For</tt></b>, <b><tt>While</tt></b>, etc.).
<p>
<h5>
Examples:
</h5>
<table cellpadding="0" width="100%">
<tr><td width=100% bgcolor="#DDDDEE"><pre>
In> LocalSymbols(a,b)a+b
Out> $a6+ $b6;
</pre></tr>
</table>
<p>
<h5>
See also:
</h5>
<a href="ref.html?UniqueConstant" target="Chapters">
UniqueConstant
</a>
.
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2425144-1";
urchinTracker();
</script>
</body>
</html>
|