-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZILCourse.lyx
More file actions
3672 lines (2953 loc) · 97.7 KB
/
ZILCourse.lyx
File metadata and controls
3672 lines (2953 loc) · 97.7 KB
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
#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass scrbook
\options openany
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts true
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_title "ZIL"
\pdf_author "Marc S. Blank"
\pdf_subject "ZIL Course"
\pdf_keywords "Infocom ZIL Zork IF IntFiction Interactive Fiction"
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder true
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize a4paper
\use_geometry true
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 2.5cm
\topmargin 2cm
\rightmargin 2cm
\bottommargin 2cm
\headheight 1cm
\headsep 0.5cm
\footskip 1cm
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 2
\paperpagestyle fancy
\listings_params "xleftmargin=25pt"
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Title
ZIL
\end_layout
\begin_layout Author
Marc S.
Blank
\end_layout
\begin_layout Date
October 1982
\end_layout
\begin_layout Publishers
INFOCOM INTERNAL DOCUMENT - NOT FOR DISTRIBUTION
\end_layout
\begin_layout Standard
\begin_inset CommandInset toc
LatexCommand tableofcontents
\end_inset
\end_layout
\begin_layout Chapter
The Z System
\end_layout
\begin_layout Standard
The Z System is composed of the various modules which are used to create
INTERLOGIC games.
At the highest level is Z Implementation Language (ZIL), which is an interprete
d language running under MDL.
Since ZIL is a MDL subsystem, all of the debugging features of MDL itself
can be used in the creation and debugging of INTERLOGIC games.
ZIL code is run through the ZIL Compiler (ZILCH) producing Z Assembly Language
code which is, in turn, assembled by the Z Assembler Program (ZAP) into
machine-independent Z-codes.
These Z-codes can be run on any target machine which sports a Z-machine
emulator (ZIP).
\end_layout
\begin_layout Standard
The author of an INTERLOGIC game need not be familiar with the workings
of the compiler, assembler, or emulators to a great extent.
The compiler does have a few idiosyncrasies, however, which will be noted
as necessary.
The remainder of this manual describes MDL and ZIL, starting with simple
concepts but eventually describing the full power of the system.
\end_layout
\begin_layout Chapter
Writing in ZIL
\end_layout
\begin_layout Standard
MDL (pronounced MUDDLE) is the host language for ZIL and knowledge of MDL
is an advantage in learning the ZIL system.
However, there are a number of important restrictions and simplifications
built into ZIL; it is therefore important that even seasoned MDLers read
this section.
\end_layout
\begin_layout Section
ZIL TYPEs
\end_layout
\begin_layout Standard
The ZIL world contains a relatively small number of classes of objects and
these classes are called TYPEs.
Every operation in ZIL expects to receive objects of specific TYPEs as
arguments.
For simplicity, 'a FOO' will be used as a shorthand for 'an object of TYPE
FOO'.
\end_layout
\begin_layout Subsection
FORM
\end_layout
\begin_layout Standard
FORMs are represented as a collection of other objects (of any type) surrounded
by balanced angle-brackets.
FORMs are used to perform the various operations in the ZIL world.
These operations may be either built-in subroutines or user-defined ROUTINEs.
Here are some FORMs:
\end_layout
\begin_layout Description
\family typewriter
<+
\begin_inset space ~
\end_inset
1
\begin_inset space ~
\end_inset
2>
\family default
This adds the integers 1 and 2.
\end_layout
\begin_layout Description
\family typewriter
<SET
\begin_inset space ~
\end_inset
A
\begin_inset space ~
\end_inset
10>
\family default
This sets the local variable A to the integer 10.
\end_layout
\begin_layout Description
\family typewriter
<G=?
\begin_inset space ~
\end_inset
<+
\begin_inset space ~
\end_inset
4
\begin_inset space ~
\end_inset
1>
\begin_inset space ~
\end_inset
10>
\family default
This returns TRUE if the sum of 4 and 1 is greater-than or equal to 10.
\end_layout
\begin_layout Description
\family typewriter
<SETG
\begin_inset space ~
\end_inset
FOO
\begin_inset space ~
\end_inset
<*
\begin_inset space ~
\end_inset
,COUNTER
\begin_inset space ~
\end_inset
<RANDOM
\begin_inset space ~
\end_inset
4>>>
\family default
This sets the global variable FOO to the product of the value of the global
variable COUNTER and a random number from 1 to 4.
\end_layout
\begin_layout Standard
The first element of a form indicates the operation to be performed and
all other elements are the arguments to that operation.
\end_layout
\begin_layout Subsection
Prefix Notation
\end_layout
\begin_layout Standard
Prefix notation, sometimes referred to as Polish notation, is different
from the infix notation of ordinary arithmetic and reverse-Polish notation
of some calculators.
Below are some examples of equivalent expressions in infix and prefix notation:
\end_layout
\begin_layout Verbatim
4 + 7
\end_layout
\begin_layout Verbatim
<+ 4 7>
\end_layout
\begin_layout Verbatim
\end_layout
\begin_layout Verbatim
8 - 6
\end_layout
\begin_layout Verbatim
<- 8 6>
\end_layout
\begin_layout Verbatim
\end_layout
\begin_layout Verbatim
9 + (4 * 6 - 6 / 3)
\end_layout
\begin_layout Verbatim
<+ 9 <- <* 4 6> </ 6 3>>>
\end_layout
\begin_layout Standard
It may take some time to become accustomed to prefix notation.
One thing to keep in mind is the balancing of brackets.
Notice that with prefix notation an operator can take an arbitrary number
of arguments and that the nesting is never ambiguous (i.e.
\begin_inset space ~
\end_inset
the parentheses of infix notation are not necessary).
In addition, operator precedence can be completely ignored.
\end_layout
\begin_layout Subsection
Nested Expressions
\end_layout
\begin_layout Standard
As can be seen from the previous examples, it is possible to nest expressions.
In fact, there is no limit on the depth of the nesting.
FORMs are evaluated from left to right, top to bottom.
\end_layout
\begin_layout Subsection
FIX (Integer)
\end_layout
\begin_layout Standard
Objects of TYPE FIX represent integers in the range -32767 to 32767 and
are always represented in decimal.
Integers of greater magnitude are illegal.
Floating point numbers are not allowed in ZIL.
\end_layout
\begin_layout Standard
The following operations require two arguments, both FIXes: + (addition),
- (subtraction), * (multiplication), / (division), and MOD (modulus).
Each returns the appropriate FIX.
\end_layout
\begin_layout Standard
In addition, ABS requires one FIX and returns its absolute value, and RANDOM,
given a FIX, returns a FIX between one and that FIX, inclusive.
\end_layout
\begin_layout Standard
There are three predicates which operate on pairs of FIXes: L? (less than),
G? (greater than), and ==? (equal to).
In addition, the predicate 0? (equal to zero?) takes a single FIX.
All predicates return a 'true' value or a 'false' value.
See the section below on conditionals for a full description of truth in
the ZIL sense.
\end_layout
\begin_layout Standard
Here are some examples of the use of FIXes:
\end_layout
\begin_layout Verbatim
<+ 10 20>
\end_layout
\begin_layout Verbatim
<+ </ 10 2> 1>
\end_layout
\begin_layout Subsection
ATOM (Variable)
\end_layout
\begin_layout Standard
ATOMs can be thought of as variables.
Their names can be almost anything, but safest is a combination of capital
letters, numbers, hyphens, question marks, and dollar signs (e.g.
\begin_inset space ~
\end_inset
FOOBAR, V-WALK, V-$VERIFY).
ATOMs can be thought of as coming in two varieties: LOCAL and GLOBAL.
\end_layout
\begin_layout Standard
LOCAL ATOMs are used as temporary variables within ROUTINEs (i.e.
\begin_inset space ~
\end_inset
pieces of code).
A LOCAL ATOM can be used in any number of ROUTINEs and there are NO conflicts
when one routine with LOCAL ATOM X calls another routine with its own LOCAL
ATOM X.
Each LOCAL ATOM must be explicitly created within the ROUTINE in which
it is used.
The mechanism by which this is done is described in a following section.
To set the value of a LOCAL ATOM within a ROUTINE, one says:
\end_layout
\begin_layout Verbatim
<SET atom-name value>
\end_layout
\begin_layout Standard
where 'atom-name' and 'value' correspond to an ATOM and an arbitrary value.
To retrieve the value of a LOCAL ATOM, one says:
\end_layout
\begin_layout Verbatim
.atom-name
\end_layout
\begin_layout Standard
(period followed by 'atom-name') where 'atom-name' is the ATOM whose value
is required.
\end_layout
\begin_layout Standard
GLOBAL ATOMs have values which correspond to: rooms and objects, ROUTINEs,
flags, properties, variables and tables.
The value of a GLOBAL ATOM is accessible to all ROUTINEs at all times.
To set the value of a GLOBAL ATOM, one says:
\end_layout
\begin_layout Verbatim
<SETG atom-name value>
\end_layout
\begin_layout Standard
analogously with SET.
To retrieve the value of a GLOBAL ATOM, one says:
\end_layout
\begin_layout Verbatim
,atom-name
\end_layout
\begin_layout Standard
(comma followed by 'atom-name').
\end_layout
\begin_layout Standard
As will be seen later, OBJECTs, flags, and properties are set up during
OBJECT creation and are not explicitly SETG'ed.
\end_layout
\begin_layout Subsection
STRING
\end_layout
\begin_layout Standard
STRINGs are what would be called 'character strings' in other languages.
They are used exclusively for printed text.
They are represented by a series of characters surrounded by double-quotes.
If a double-quote is necessary in the STRING, it must be preceded by a
backslash.
Here are some strings, followed by their printed representation:
\end_layout
\begin_layout Verbatim
"Hello, there!" --> Hello, there!
\end_layout
\begin_layout Verbatim
\end_layout
\begin_layout Verbatim
"The man says
\backslash
"Foobar!
\backslash
"" --> The man says "Foobar!"
\end_layout
\begin_layout Subsection
LIST
\end_layout
\begin_layout Standard
LISTs are represented as a series of other objects surrounded by matching
parentheses.
These are used within ROUTINEs for purposes of clarity (seeing angle-brackets
everywhere would be downright disorienting).
Their use will be described later.
\end_layout
\begin_layout Subsection
TABLE
\end_layout
\begin_layout Standard
A TABLE is what might be referred to as an array in other languages.
TABLEs are structures containing arbitrary elements (e.g.
\begin_inset space ~
\end_inset
OBJECTs, FIXes, STRINGs, etc.).
They must be created at 'top-level' (i.e.
\begin_inset space ~
\end_inset
NOT within a ROUTINE), as follows:
\end_layout
\begin_layout Verbatim
<TABLE element element element ...>
\end_layout
\begin_layout Standard
A special kind of TABLE whose initial element is the number of other elements
in the TABLE is created as follows:
\end_layout
\begin_layout Verbatim
<LTABLE element element element ...>
\end_layout
\begin_layout Standard
Note that the first element in this declaration is NOT the number of other
elements; that number will be automatically generated.
\end_layout
\begin_layout Standard
In ROUTINEs which need to know the length of a TABLE (e.g.
\begin_inset space ~
\end_inset
a general routine which must search through a TABLE or one which randomly
picks an element from within a TABLE), LTABLE must be used.
For TABLEs of known size, LTABLE is not necessary.
\end_layout
\begin_layout Standard
By convention, the first element of a TABLE is element zero.
To retrieve an element from a TABLE, use:
\end_layout
\begin_layout Verbatim
<GET table element-number>
\end_layout
\begin_layout Standard
To place an element within a TABLE, use:
\end_layout
\begin_layout Verbatim
<PUT table element-number>
\end_layout
\begin_layout Subsection
OBJECTs
\end_layout
\begin_layout Standard
OBJECTs correspond, in the game environment, to objects, rooms, and characters
(including the player).
The creation of OBJECTs is described below, but the operations used for
their manipulation are described here.
\end_layout
\begin_layout Standard
Any OBJECT may have, at most, one container and any number of contents.
An OBJECT's initial container is determined when it is created.
The location of an OBJECT can be returned by:
\end_layout
\begin_layout Verbatim
<LOC object>
\end_layout
\begin_layout Standard
Similarly, one may determine whether or not an OBJECT is in another particular
OBJECT by saying:
\end_layout
\begin_layout Verbatim
<IN? object-1 object-2>
\end_layout
\begin_layout Standard
which checks whether or not object-1 is contained within object-2.
\end_layout
\begin_layout Standard
OBJECTs can be placed inside other OBJECTs using MOVE:
\end_layout
\begin_layout Verbatim
<MOVE object-1 object-2>
\end_layout
\begin_layout Standard
which moves object-1 into object-2.
An OBJECT may be moved into never-never land (i.e.
\begin_inset space ~
\end_inset
it can be made to have no container, equivalent to being nowhere) with REMOVE:
\end_layout
\begin_layout Verbatim
<REMOVE object>
\end_layout
\begin_layout Standard
To find the contents of a given OBJECT is a bit unusual.
The 'first' OBJECT contained in a given OBJECT can be found with:
\end_layout
\begin_layout Verbatim
<FIRST? object>
\end_layout
\begin_layout Standard
Note that FIRST? ends with a question mark, indicating that it is a predicate.
If there is nothing contained in 'object', FIRST? returns 'false'.
\end_layout
\begin_layout Standard
Other OBJECTs within a given OBJECT can be found using NEXT? as follows:
\end_layout
\begin_layout Verbatim
<NEXT? object>
\end_layout
\begin_layout Standard
NEXT? is defined thus: it returns the 'next' OBJECT which is ALSO contained
in the OBJECT's container.
Ain't it confusing? Notice that like FIRST?, NEXT? is a predicate.
If there is no 'next' OBJECT, it returns 'false'.
As an example, let's assume that there is an object X containing objects
Y and Z.
FIRST? of X will be Y.
NEXT? of Y will be Z.
NEXT? of Z will be 'false'.
(NEXT? of X is unknowable from this example.)
\end_layout
\begin_layout Standard
OBJECTs may also have up to 32 condition flags, most of which are designed
into the substrate of the game.
Among these are OPENBIT (whether a door or container is presently open),
TAKEBIT (whether an OBJECT can be taken), DOORBIT (whether an OBJECT is
a door), and ONBIT (whether an OBJECT is a source of light).
The initial state of these flags is determined during OBJECT creation,
and all of the substrate-contained flags are described later.
\end_layout
\begin_layout Standard
To check whether a given flag is 'on', use:
\end_layout
\begin_layout Verbatim
<FSET? object flag>
\end_layout
\begin_layout Standard
To set a flag (i.e.
\begin_inset space ~
\end_inset
turn it on) and clear a flag (i.e.
\begin_inset space ~
\end_inset
turn it off), use:
\end_layout
\begin_layout Verbatim
<FSET object flag>
\end_layout
\begin_layout Verbatim
<FCLEAR object flag>
\end_layout
\begin_layout Standard
As was noted earlier, OBJECTs and flags are GLOBAL ATOMs; therefore, the
following might appear in game code:
\end_layout
\begin_layout Verbatim
<FSET ,AIRLOCK-DOOR ,OPENBIT>
\end_layout
\begin_layout Standard
This would cause the AIRLOCK-DOOR to be considered 'open'.
The ramifications of this particular example would include the ability
to go through the door without obstruction and the ability to look through
the door.
The ramifications of the various flags is discussed below.
\end_layout
\begin_layout Standard
OBJECTs also have up to 31 'properties', whose values are explicitly manipulated
relatively infrequently during game writing.
Among these properties are SIZE (weight of an OBJECT), CAPACITY (total
weight that a container can hold), ACTION (ROUTINE to be called for special
case actions), and LDESC (long description).
These properties are set up during OBJECT definition and are described
completely later on.
It should be noted, however, that new properties cannot be added to an
OBJECT while a game is running.
If a property is needed for a particular OBJECT, it must be initialized
when the OBJECT is defined.
\end_layout
\begin_layout Standard
Retrieving the value of a property for a given OBJECT is done with:
\end_layout
\begin_layout Verbatim
<GETP object property>
\end_layout
\begin_layout Standard
Similarly, setting the value of a property for a given OBJECT is done with:
\end_layout
\begin_layout Verbatim
<PUTP object property value>
\end_layout
\begin_layout Standard
Like condition flags, properties are GLOBAL ATOMs.
In the context of GETP and PUTP, their names must be prefixed by the letter
P and a question-mark.
In other words:
\end_layout
\begin_layout Verbatim
<GETP ,RUSTY-KNIFE ,P?SIZE>
\end_layout
\begin_layout Standard
would retrieve the SIZE property of the RUSTY-KNIFE.
\end_layout
\begin_layout Standard
If, in a call to GETP, the supplied OBJECT does not have the supplied property
defined, the result is 'false'.
This default result can be altered, if it is so desired, by placing a statement
like this in the ZIL 'load file' (see further on):
\end_layout
\begin_layout Verbatim
<PROPDEF property-name default-value>
\end_layout
\begin_layout Standard
where 'property-name' is the name of the property for which a default will
exist, and 'default-value' is the value which GETP will return if the property
is not defined for a given OBJECT.
Here's an example:
\end_layout
\begin_layout Verbatim
<PROPDEF SIZE 5>
\end_layout
\begin_layout Section
Conditional Expressions
\end_layout
\begin_layout Standard
One cannot discuss conditional expressions without explaining the meaning
of 'truth'.
ZIL has a rather simplistic view of truth: anything which is not zero is
true.
For historical reasons, a distinction is made between 'false' and zero
and it is the cause of some confusion.
GLOBAL ATOMs are frequently used to save the state of a global condition
(e.g.
\begin_inset space ~
\end_inset
SUIT-ON? might be 'true' or 'false' depending on whether one is wearing
the spacesuit).
Two special tokens are used to mean 'true' and 'false' in these cases:
T and <> (open followed by closed angle bracket).
In ZIL code, therefore, one should use:
\end_layout
\begin_layout Verbatim
<SETG SUIT-ON? T>
\end_layout
\begin_layout Verbatim
<SETG SUIT-ON? <>>
\end_layout
\begin_layout Standard
rather than:
\end_layout
\begin_layout Verbatim
<SETG SUIT-ON? 1>
\end_layout
\begin_layout Verbatim
<SETG SUIT-ON? 0>
\end_layout
\begin_layout Standard
This distinction makes code more understandable to the casual observer:
in the former example, it is clear that SUIT-ON? is a condition flag.
In the latter, it is unclear whether SUIT-ON? is a condition flag or a
variable whose value is a FIX.
\end_layout
\begin_layout Standard
Some of the most common operations in ZIL are predicates and return one
of two values: true (not zero, usually one) and false (zero).
We have already described some of these: L?, G?, and ==? (for arithmetic)
and IN? and FSET? (for OBJECTs).
\end_layout
\begin_layout Standard
The other operations dealing with conditionals are mentioned here.
\end_layout
\begin_layout Subsection
EQUAL?
\end_layout
\begin_layout Standard
EQUAL? takes from two to four arguments and determines whether the first
is equal to any of the other arguments.
\end_layout
\begin_layout Verbatim
<EQUAL? .OBJ ,LANTERN ,CANDLES>
\end_layout
\begin_layout Standard
The example checks to see whether the value of the LOCAL ATOM OBJ is either
the LANTERN or the CANDLES (presumably these are OBJECTs).
EQUAL? returns T or <> (i.e.
\begin_inset space ~
\end_inset
'true' or 'false').
It can be used with any TYPEs of arguments.
Thus,
\end_layout
\begin_layout Verbatim
<EQUAL? .NUM 1 2 3>
\end_layout
\begin_layout Standard
could be used to check whether or not the LOCAL ATOM NUM was equal to one,
two, or three.
\end_layout
\begin_layout Subsection
NOT
\end_layout
\begin_layout Standard
NOT takes one argument.
If it is not 'false', it returns 'false'.
If it IS 'false', it returns 'true'.
Thus, if the LOCAL ATOM OBJ is 12, then
\end_layout
\begin_layout Verbatim
<NOT .OBJ>
\end_layout
\begin_layout Standard
will return 'false'.
To restate in another way, NOT returns 'true' only if its argument was
'false'.
It returns 'false' in every other case.
\end_layout
\begin_layout Subsection
AND
\end_layout
\begin_layout Standard
AND takes any number of expressions and evaluates them from left to right.
It returns 'true' only if ALL of the expressions are 'true'.
Otherwise it returns 'false'.
For example,
\end_layout
\begin_layout Verbatim
<AND <G? .NUM 10> <L? .NUM 20>>
\end_layout
\begin_layout Standard
returns 'true' if the value of LOCAL ATOM NUM is BOTH greater than 10 and
less than 20.
Otherwise, it returns 'false'.
\end_layout
\begin_layout Subsection
OR
\end_layout
\begin_layout Standard
OR, similar to AND, takes any number of expressions and evaluates them from
left to right.
However, it returns 'true' if ANY of the expressions is 'true'.
Otherwise, it returns 'false'.
For example,
\end_layout
\begin_layout Verbatim
<OR <L? .NUM 11> <G? .NUM 19>>
\end_layout
\begin_layout Standard
returns 'true' if the value of the LOCAL ATOM NUM is EITHER less than 11
OR greater than 19.
Otherwise, it returns 'false'.
(This is the opposite of the example for AND.)
\end_layout
\begin_layout Subsection
COND
\end_layout
\begin_layout Standard
By now, those unfamiliar with MDL have had about enough of conditionals
returning 'true' and 'false' and are probably wondering just who it is
who decides to do something depending on those values.
The answer is COND, probably the most commonly used operation in the language.
The structure of a COND expression is:
\end_layout
\begin_layout Verbatim
<COND (predicate expression expression ...)
\end_layout
\begin_layout Verbatim
(predicate expression expression ...)
\end_layout
\begin_layout Verbatim
...
\end_layout
\begin_layout Verbatim
(predicate expression expression ...)>
\end_layout
\begin_layout Standard
First note that COND, like AND and OR, takes any number of arguments, which
are all LISTs.
Each LIST contains at least two elements: a predicate (i.e.
\begin_inset space ~
\end_inset
conditional expression) and something(s) to do if that predicate returns
'true'.
\end_layout
\begin_layout Standard
COND works like this: starting with the first LIST, it evaluates the predicate.
If it returns 'true', then ALL of the remaining expressions are evaluated
in turn, and the COND itself returns the value of the last of those expressions.
If it returns 'false', then the next LIST is examined in the same way.
If none of the predicates returns 'true', then the COND itself returns
'false'.
Here is a typical example of a COND expression:
\end_layout
\begin_layout Verbatim
<COND (<VERB? TAKE>
\end_layout