-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplain-manual.html
756 lines (525 loc) · 20.5 KB
/
plain-manual.html
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
<HTML>
<PRE>
JOY - compiled at 16:57:51 on Mar 17 2003 (BDW)
Copyright 2001 by Manfred von Thun
literal
truth value type : -> B
The logical type, or the type of truth values.
It has just two literals: true and false.
character type : -> C
The type of characters. Literals are written with a single quote.
Examples: 'A '7 '; and so on. Unix style escapes are allowed.
integer type : -> I
The type of negative, zero or positive integers.
Literals are written in decimal notation. Examples: -123 0 42.
set type : -> {...}
The type of sets of small non-negative integers.
The maximum is platform dependent, typically the range is 0..31.
Literals are written inside curly braces.
Examples: {} {0} {1 3 5} {19 18 17}.
string type : -> "..."
The type of strings of characters. Literals are written inside double quotes.
Examples: "" "A" "hello world" "123".
Unix style escapes are accepted.
list type : -> [...]
The type of lists of values of any type (including lists),
or the type of quoted programs which may contain operators or combinators.
Literals of this type are written inside square brackets.
Examples: [] [3 512 -7] [john mary] ['A 'C ['B]] [dup *].
float type : -> F
The type of floating-point numbers.
Literals of this type are written with embedded decimal points (like 1.2)
and optional exponent specifiers (like 1.5E2)
file type : -> FILE:
The type of references to open I/O streams,
typically but not necessarily files.
The only literals of this type are stdin, stdout, and stderr.
operand
false : -> false
Pushes the value false.
true : -> true
Pushes the value true.
maxint : -> maxint
Pushes largest integer (platform dependent). Typically it is 32 bits.
setsize : -> setsize
Pushes the maximum number of elements in a set (platform dependent).
Typically it is 32, and set members are in the range 0..31.
stack : .. X Y Z -> .. X Y Z [Z Y X ..]
Pushes the stack as a list.
conts : -> [[P] [Q] ..]
Pushes current continuations. Buggy, do not use.
autoput : -> I
Pushes current value of flag for automatic output, I = 0..2.
undeferror : -> I
Pushes current value of undefined-is-error flag.
undefs : ->
Push a list of all undefined symbols in the current symbol table.
echo : -> I
Pushes value of echo flag, I = 0..3.
clock : -> I
Pushes the integer value of current CPU usage in hundreds of a second.
time : -> I
Pushes the current time (in seconds since the Epoch).
rand : -> I
I is a random integer.
stdin : -> S
Pushes the standard input stream.
stdout : -> S
Pushes the standard output stream.
stderr : -> S
Pushes the standard error stream.
operator
id : ->
Identity function, does nothing.
Any program of the form P id Q is equivalent to just P Q.
dup : X -> X X
Pushes an extra copy of X onto stack.
swap : X Y -> Y X
Interchanges X and Y on top of the stack.
rollup : X Y Z -> Z X Y
Moves X and Y up, moves Z down
rolldown : X Y Z -> Y Z X
Moves Y and Z down, moves X up
rotate : X Y Z -> Z Y X
Interchanges X and Z
popd : Y Z -> Z
As if defined by: popd == [pop] dip
dupd : Y Z -> Y Y Z
As if defined by: dupd == [dup] dip
swapd : X Y Z -> Y X Z
As if defined by: swapd == [swap] dip
rollupd : X Y Z W -> Z X Y W
As if defined by: rollupd == [rollup] dip
rolldownd : X Y Z W -> Y Z X W
As if defined by: rolldownd == [rolldown] dip
rotated : X Y Z W -> Z Y X W
As if defined by: rotated == [rotate] dip
pop : X ->
Removes X from top of the stack.
choice : B T F -> X
If B is true, then X = T else X = F.
or : X Y -> Z
Z is the union of sets X and Y, logical disjunction for truth values.
xor : X Y -> Z
Z is the symmetric difference of sets X and Y,
logical exclusive disjunction for truth values.
and : X Y -> Z
Z is the intersection of sets X and Y, logical conjunction for truth values.
not : X -> Y
Y is the complement of set X, logical negation for truth values.
+ : M I -> N
Numeric N is the result of adding integer I to numeric M.
Also supports float.
- : M I -> N
Numeric N is the result of subtracting integer I from numeric M.
Also supports float.
* : I J -> K
Integer K is the product of integers I and J. Also supports float.
/ : I J -> K
Integer K is the (rounded) ratio of integers I and J. Also supports float.
rem : I J -> K
Integer K is the remainder of dividing I by J. Also supports float.
div : I J -> K L
Integers K and L are the quotient and remainder of dividing I by J.
sign : N1 -> N2
Integer N2 is the sign (-1 or 0 or +1) of integer N1,
or float N2 is the sign (-1.0 or 0.0 or 1.0) of float N1.
neg : I -> J
Integer J is the negative of integer I. Also supports float.
ord : C -> I
Integer I is the Ascii value of character C (or logical or integer).
chr : I -> C
C is the character whose Ascii value is integer I (or logical or character).
abs : N1 -> N2
Integer N2 is the absolute value (0,1,2..) of integer N1,
or float N2 is the absolute value (0.0 ..) of float N1
acos : F -> G
G is the arc cosine of F.
asin : F -> G
G is the arc sine of F.
atan : F -> G
G is the arc tangent of F.
atan2 : F G -> H
H is the arc tangent of F / G.
ceil : F -> G
G is the float ceiling of F.
cos : F -> G
G is the cosine of F.
cosh : F -> G
G is the hyperbolic cosine of F.
exp : F -> G
G is e (2.718281828...) raised to the Fth power.
floor : F -> G
G is the floor of F.
frexp : F -> G I
G is the mantissa and I is the exponent of F.
Unless F = 0, 0.5 <= abs(G) < 1.0.
ldexp : F I -> G
G is F times 2 to the Ith power.
log : F -> G
G is the natural logarithm of F.
log10 : F -> G
G is the common logarithm of F.
modf : F -> G H
G is the fractional part and H is the integer part
(but expressed as a float) of F.
pow : F G -> H
H is F raised to the Gth power.
sin : F -> G
G is the sine of F.
sinh : F -> G
G is the hyperbolic sine of F.
sqrt : F -> G
G is the square root of F.
tan : F -> G
G is the tangent of F.
tanh : F -> G
G is the hyperbolic tangent of F.
trunc : F -> I
I is an integer equal to the float F truncated toward zero.
localtime : I -> T
Converts a time I into a list T representing local time:
[year month day hour minute second isdst yearday weekday].
Month is 1 = January ... 12 = December;
isdst is a Boolean flagging daylight savings/summer time;
weekday is 0 = Monday ... 7 = Sunday.
gmtime : I -> T
Converts a time I into a list T representing universal time:
[year month day hour minute second isdst yearday weekday].
Month is 1 = January ... 12 = December;
isdst is false; weekday is 0 = Monday ... 7 = Sunday.
mktime : T -> I
Converts a list T representing local time into a time I.
T is in the format generated by localtime.
strftime : T S1 -> S2
Formats a list T in the format of localtime or gmtime
using string S1 and pushes the result S2.
strtol : S I -> J
String S is converted to the integer J using base I.
If I = 0, assumes base 10,
but leading "0" means base 8 and leading "0x" means base 16.
strtod : S -> R
String S is converted to the float R.
format : N C I J -> S
S is the formatted version of N in mode C
('d or 'i = decimal, 'o = octal, 'x or
'X = hex with lower or upper case letters)
with maximum width I and minimum width J.
formatf : F C I J -> S
S is the formatted version of F in mode C
('e or 'E = exponential, 'f = fractional,
'g or G = general with lower or upper case letters)
with maximum width I and precision J.
srand : I ->
Sets the random integer seed to integer I.
pred : M -> N
Numeric N is the predecessor of numeric M.
succ : M -> N
Numeric N is the successor of numeric M.
max : N1 N2 -> N
N is the maximum of numeric values N1 and N2. Also supports float.
min : N1 N2 -> N
N is the minimum of numeric values N1 and N2. Also supports float.
fclose : S ->
Stream S is closed and removed from the stack.
feof : S -> S B
B is the end-of-file status of stream S.
ferror : S -> S B
B is the error status of stream S.
fflush : S -> S
Flush stream S, forcing all buffered output to be written.
fgetch : S -> S C
C is the next available character from stream S.
fgets : S -> S L
L is the next available line (as a string) from stream S.
fopen : P M -> S
The file system object with pathname P is opened with mode M (r, w, a, etc.)
and stream object S is pushed; if the open fails, file:NULL is pushed.
fread : S I -> S L
I bytes are read from the current position of stream S
and returned as a list of I integers.
fwrite : S L -> S
A list of integers are written as bytes to the current position of stream S.
fremove : P -> B
The file system object with pathname P is removed from the file system.
is a boolean indicating success or failure.
frename : P1 P2 -> B
The file system object with pathname P1 is renamed to P2.
B is a boolean indicating success or failure.
fput : S X -> S
Writes X to stream S, pops X off stack.
fputch : S C -> S
The character C is written to the current position of stream S.
fputchars : S "abc.." -> S
The string abc.. (no quotes) is written to the current position of stream S.
fputstring : S "abc.." -> S
== fputchars, as a temporary alternative.
fseek : S P W -> S
Stream S is repositioned to position P relative to whence-point W,
where W = 0, 1, 2 for beginning, current position, end respectively.
ftell : S -> S I
I is the current position of stream S.
unstack : [X Y ..] -> ..Y X
The list [X Y ..] becomes the new stack.
cons : X A -> B
Aggregate B is A with a new member X (first member for sequences).
swons : A X -> B
Aggregate B is A with a new member X (first member for sequences).
first : A -> F
F is the first member of the non-empty aggregate A.
rest : A -> R
R is the non-empty aggregate A with its first member removed.
compare : A B -> I
I (=-1,0,+1) is the comparison of aggregates A and B.
The values correspond to the predicates <=, =, >=.
at : A I -> X
X (= A[I]) is the member of A at position I.
of : I A -> X
X (= A[I]) is the I-th member of aggregate A.
size : A -> I
Integer I is the number of elements of aggregate A.
opcase : X [..[X Xs]..] -> [Xs]
Indexing on type of X, returns the list [Xs].
case : X [..[X Y]..] -> Y i
Indexing on the value of X, execute the matching Y.
uncons : A -> F R
F and R are the first and the rest of non-empty aggregate A.
unswons : A -> R F
R and F are the rest and the first of non-empty aggregate A.
drop : A N -> B
Aggregate B is the result of deleting the first N elements of A.
take : A N -> B
Aggregate B is the result of retaining just the first N elements of A.
concat : S T -> U
Sequence U is the concatenation of sequences S and T.
enconcat : X S T -> U
Sequence U is the concatenation of sequences S and T
with X inserted between S and T (== swapd cons concat)
name : sym -> "sym"
For operators and combinators, the string "sym" is the name of item sym,
for literals sym the result string is its type.
intern : "sym" -> sym
Pushes the item whose name is "sym".
body : U -> [P]
Quotation [P] is the body of user-defined symbol U.
predicate
null : X -> B
Tests for empty aggregate X or zero numeric.
small : X -> B
Tests whether aggregate X has 0 or 1 members, or numeric 0 or 1.
>= : X Y -> B
Either both X and Y are numeric or both are strings or symbols.
Tests whether X greater than or equal to Y. Also supports float.
> : X Y -> B
Either both X and Y are numeric or both are strings or symbols.
Tests whether X greater than Y. Also supports float.
<= : X Y -> B
Either both X and Y are numeric or both are strings or symbols.
Tests whether X less than or equal to Y. Also supports float.
< : X Y -> B
Either both X and Y are numeric or both are strings or symbols.
Tests whether X less than Y. Also supports float.
!= : X Y -> B
Either both X and Y are numeric or both are strings or symbols.
Tests whether X not equal to Y. Also supports float.
= : X Y -> B
Either both X and Y are numeric or both are strings or symbols.
Tests whether X equal to Y. Also supports float.
equal : T U -> B
(Recursively) tests whether trees T and U are identical.
has : A X -> B
Tests whether aggregate A has X as a member.
in : X A -> B
Tests whether X is a member of aggregate A.
integer : X -> B
Tests whether X is an integer.
char : X -> B
Tests whether X is a character.
logical : X -> B
Tests whether X is a logical.
set : X -> B
Tests whether X is a set.
string : X -> B
Tests whether X is a string.
list : X -> B
Tests whether X is a list.
leaf : X -> B
Tests whether X is not a list.
user : X -> B
Tests whether X is a user-defined symbol.
float : R -> B
Tests whether R is a float.
file : F -> B
Tests whether F is a file.
combinator
i : [P] -> ...
Executes P. So, [P] i == P.
x : [P]i -> ...
Executes P without popping [P]. So, [P] x == [P] P.
dip : X [P] -> ... X
Saves X, executes P, pushes X back.
app1 : X [P] -> R
Executes P, pushes result R on stack without X.
app11 : X Y [P] -> R
Executes P, pushes result R on stack.
app12 : X Y1 Y2 [P] -> R1 R2
Executes P twice, with Y1 and Y2, returns R1 and R2.
construct : [P] [[P1] [P2] ..] -> R1 R2 ..
Saves state of stack and then executes [P].
Then executes each [Pi] to give Ri pushed onto saved stack.
nullary : [P] -> R
Executes P, which leaves R on top of the stack.
No matter how many parameters this consumes, none are removed from the stack.
unary : X [P] -> R
Executes P, which leaves R on top of the stack.
No matter how many parameters this consumes,
exactly one is removed from the stack.
unary2 : X1 X2 [P] -> R1 R2
Executes P twice, with X1 and X2 on top of the stack.
Returns the two values R1 and R2.
unary3 : X1 X2 X3 [P] -> R1 R2 R3
Executes P three times, with Xi, returns Ri (i = 1..3).
unary4 : X1 X2 X3 X4 [P] -> R1 R2 R3 R4
Executes P four times, with Xi, returns Ri (i = 1..4).
app2 : X1 X2 [P] -> R1 R2
Obsolescent. == unary2
app3 : X1 X2 X3 [P] -> R1 R2 R3
Obsolescent. == unary3
app4 : X1 X2 X3 X4 [P] -> R1 R2 R3 R4
Obsolescent. == unary4
binary : X Y [P] -> R
Executes P, which leaves R on top of the stack.
No matter how many parameters this consumes,
exactly two are removed from the stack.
ternary : X Y Z [P] -> R
Executes P, which leaves R on top of the stack.
No matter how many parameters this consumes,
exactly three are removed from the stack.
cleave : X [P1] [P2] -> R1 R2
Executes P1 and P2, each with X on top, producing two results.
branch : B [T] [F] -> ...
If B is true, then executes T else executes F.
ifte : [B] [T] [F] -> ...
Executes B. If that yields true, then executes T else executes F.
ifinteger : X [T] [E] -> ...
If X is an integer, executes T else executes E.
ifchar : X [T] [E] -> ...
If X is a character, executes T else executes E.
iflogical : X [T] [E] -> ...
If X is a logical or truth value, executes T else executes E.
ifset : X [T] [E] -> ...
If X is a set, executes T else executes E.
ifstring : X [T] [E] -> ...
If X is a string, executes T else executes E.
iflist : X [T] [E] -> ...
If X is a list, executes T else executes E.
iffloat : X [T] [E] -> ...
If X is a float, executes T else executes E.
iffile : X [T] [E] -> ...
If X is a file, executes T else executes E.
cond : [..[[Bi] Ti]..[D]] -> ...
Tries each Bi. If that yields true, then executes Ti and exits.
If no Bi yields true, executes default D.
while : [B] [D] -> ...
While executing B yields true executes D.
linrec : [P] [T] [R1] [R2] -> ...
Executes P. If that yields true, executes T.
Else executes R1, recurses, executes R2.
tailrec : [P] [T] [R1] -> ...
Executes P. If that yields true, executes T.
Else executes R1, recurses.
binrec : [B] [T] [R1] [R2] -> ...
Executes P. If that yields true, executes T.
Else uses R1 to produce two intermediates, recurses on both,
then executes R2 to combines their results.
genrec : [B] [T] [R1] [R2] -> ...
Executes B, if that yields true executes T.
Else executes R1 and then [[B] [T] [R1] [R2] genrec] R2.
condlinrec : [ [C1] [C2] .. [D] ] -> ...
Each [Ci] is of the forms [[B] [T]] or [[B] [R1] [R2]].
Tries each B. If that yields true and there is just a [T], executes T and exit.
If there are [R1] and [R2], executes R1, recurses, executes R2.
Subsequent case are ignored. If no B yields true, then [D] is used.
It is then of the forms [[T]] or [[R1] [R2]]. For the former, executes T.
For the latter executes R1, recurses, executes R2.
step : A [P] -> ...
Sequentially putting members of aggregate A onto stack,
executes P for each member of A.
fold : A V0 [P] -> V
Starting with value V0, sequentially pushes members of aggregate A
and combines with binary operator P to produce value V.
map : A [P] -> B
Executes P on each member of aggregate A,
collects results in sametype aggregate B.
times : N [P] -> ...
N times executes P.
infra : L1 [P] -> L2
Using list L1 as stack, executes P and returns a new list L2.
The first element of L1 is used as the top of stack,
and after execution of P the top of stack becomes the first element of L2.
primrec : X [I] [C] -> R
Executes I to obtain an initial value R0.
For integer X uses increasing positive integers to X, combines by C for new R.
For aggregate X uses successive members and combines by C for new R.
filter : A [B] -> A1
Uses test B to filter aggregate A producing sametype aggregate A1.
split : A [B] -> A1 A2
Uses test B to split aggregate A into sametype aggregates A1 and A2 .
some : A [B] -> X
Applies test B to members of aggregate A, X = true if some pass.
all : A [B] -> X
Applies test B to members of aggregate A, X = true if all pass.
treestep : T [P] -> ...
Recursively traverses leaves of tree T, executes P for each leaf.
treerec : T [O] [C] -> ...
T is a tree. If T is a leaf, executes O. Else executes [[O] [C] treerec] C.
treegenrec : T [O1] [O2] [C] -> ...
T is a tree. If T is a leaf, executes O1.
Else executes O2 and then [[O1] [O2] [C] treegenrec] C.
miscellaneous commands
help : ->
Lists all defined symbols, including those from library files.
Then lists all primitives of raw Joy
(There is a variant: "_help" which lists hidden symbols).
helpdetail : [ S1 S2 .. ]
Gives brief help on each symbol S in the list.
manual : ->
Writes this manual of all Joy primitives to output file.
setautoput : I ->
Sets value of flag for automatic put to I (if I = 0, none;
if I = 1, put; if I = 2, stack.
setundeferror : I ->
Sets flag that controls behavior of undefined functions
(0 = no error, 1 = error).
setecho : I ->
Sets value of echo flag for listing.
I = 0: no echo, 1: echo, 2: with tab, 3: and linenumber.
gc : ->
Initiates garbage collection.
system : "command" ->
Escapes to shell, executes string "command".
The string may cause execution of another program.
When that has finished, the process returns to Joy.
getenv : "variable" -> "value"
Retrieves the value of the environment variable "variable".
argv : -> A
Creates an aggregate A containing the interpreter's command line arguments.
argc : -> I
Pushes the number of command line arguments. This is quivalent to 'argv size'.
get : -> F
Reads a factor from input and pushes it onto stack.
put : X ->
Writes X to output, pops X off stack.
putch : N ->
N : numeric, writes character whose ASCII is N.
putchars : "abc.." ->
Writes abc.. (without quotes)
include : "filnam.ext" ->
Transfers input to file whose name is "filnam.ext".
On end-of-file returns to previous input file.
abort : ->
Aborts execution of current Joy program, returns to Joy main cycle.
quit : ->
Exit from Joy.
</PRE>
</HTML>