-
Notifications
You must be signed in to change notification settings - Fork 149
/
language.html
1278 lines (1029 loc) · 50.2 KB
/
language.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
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
<!DOCTYPE html>
<title>Logo Language Guide</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<script src="https://cdn.rawgit.com/inexorabletash/polyfill/v0.1.29/polyfill.min.js"></script>
<style>
h1, h2, h3, h4, p { margin-bottom: 6pt; margin-top: 6pt; }
body, p, h1, h2, h3 { font-family: sans-serif; }
dl { margin-top: 6pt; }
p, dt, dd, ol, li { font-size: 10pt; }
code { font-family: monospace; font-weight: bold; }
body
{
color: black;
background-color: transparent;
}
dd.example:before {
content: 'Example:';
margin-right: 0.5em;
font-family: sans-serif;
font-style: italic;
color: gray;
}
dd.example {
font-family: monospace;
white-space: pre-wrap;
margin-top: 2px;
margin-bottom: 2px;
color: gray;
cursor: pointer;
}
</style>
<div>
<p>The section numbers are per the <a target="_blank" href="https://www.cs.berkeley.edu/~bh/v2ch14/manual.html">Berkeley Logo Reference Manual</a> in Brian Harvey's <cite>Computer Science Logo Style volume 2: Advanced Techniques</cite> for ease
of comparison.</p>
<ol>
<li><a href="#types">Data Types and Syntax</a>
<li><a href="#sec2">Data Structure Primitives</a>
<li><a href="#sec3">Communication</a>
<li><a href="#sec4">Arithmetic</a>
<li><a href="#sec5">Logical Operations</a>
<li><a href="#sec6">Graphics</a>
<li><a href="#sec7">Workspace Management</a>
<li><a href="#sec8">Control Structures</a>
</ol>
<h3 id="types">Data Types and Syntax</h3>
<dl>
<dt><code>"<var>word</var></code>
<dt><code>'<var>word</var></code>
<dt><code><var>number</var></code>
<dd>Word. (Quoted words are terminated by [](){} or whitespace, \ to escape.)
<dd class=example>show "hello</dd>
<dd class=example>show "hello\ logo</dd>
<dd class=example>show 12.34</dd>
<dt><code>:<var>variable</var></code>
<dd>Input definition/variable reference
<dd class=example>show :name</dd>
<dt><code>[ <var>word ...</var> ]</code>
<dd>List of words or lists, whitespace separated
<dd class=example>show [1 2 3]</dd>
<dt><code>{ <var>word ...</var> }</code>
<dt><code>{ <var>word ...</var> }@<var>origin</var></code>
<dd>Array of words, whitespace separated
<dd class=example>show {1 2 3}</dd>
<dt><code> ( <var>expression</var> )</code>
<dd>Parenthesis can be used to group expressions
<dd class=example>show ( 1 + 2 ) * 3</dd>
<dt><code><var>procedure</var> <var>input</var> ...</code>
<dd>Call procedure with default number of inputs
<dd class=example>show "hello</dd>
<dt><code> ( <var>procedure</var> <var>input</var> ... )</code>
<dd>Call procedure with an arbitrary number of inputs
<dd class=example>(show "hello :name)</dd>
</dl>
<h3 id="sec2">2. Data Structure Primitives</h3>
<h4>2.1 Constructors</h4>
<dl>
<dt><code>word <var>expr</var> <var>expr</var></code>
<dt><code>(word <var>expr</var> <var>...</var>)</code>
<dd>Concatenate two (or more) words into one word
<dd class=example>show (word "a "b "c)</dd>
<dt><code>list <var>thing1</var> <var>thing2</var></code>
<dt><code>(list <var>thing1</var> <var>thing2</var> ...)</code>
<dd>Create a new list from the inputs
<dd class=example>show (list 1+2 2+3 3+4)</dd>
<dt><code>sentence thing1 thing2</code>
<dt><code>(sentence thing1 thing2 ...)</code>
<dt><code>se thing1 thing2</code>
<dt><code>(se thing1 thing2 ...)</code>
<dd>Create a new list from the inputs (if non-lists) or members of the inputs (if lists)
<dd class=example>show sentence [1 2 3] [and so on]</dd>
<dt><code>fput <var>thing</var> <var>list</var></code>
<dt><code>lput <var>thing</var> <var>list</var></code>
<dd>Outputs list, but with thing added as a new first/last item; if list is a word, concatenates
<dd class=example>show fput 0 [ 1 2 3 ]</dd>
<dd class=example>show fput "a "bcd</dd>
<dd class=example>show lput 4 [ 1 2 3 ]</dd>
<dd class=example>show lput "e "bcd</dd>
<dt><code>array <var>size</var></code>
<dt><code>(array <var>size</var> <var>origin</var>)</code>
<dd>Create a new array. The default origin is 1.
<dd class=example>show array 10</dd>
<dt><code>mdarray [<var>dimensions</var> ...]</code>
<dt><code>(mdarray [<var>dimensions</var> ...] <var>origin</var>)</code>
<dd>Create a new multi-dimensional array. The default origin is 1.
<dd class=example>show mdarray [2 2]</dd>
<dt><code>listtoarray <var>list</var></code>
<dt><code>(listtoarray <var>list</var> <var>origin</var>)</code>
<dd>Create a new array populated by members of a list
<dd class=example>show listtoarray [ 1 3 5 7 ]</dd>
<dt><code>arraytolist <var>array</var></code>
<dd>Create a new list populated by members of a array
<dd class=example>show arraytolist { 2 4 6 8 }</dd>
<dt><code>combine thing1 thing2</code>
<dd>If thing2 is a word, like <code>word</code>; otherwise, like <code>fput</code>
<dd class=example>show combine "a [b c]</dd>
<dt><code>reverse <var>list</var></code>
<dd>Outputs a list with the items in reverse order; if input is a word, reverses characters
<dd class=example>show reverse [ 1 2 3 ]</dd>
<dd class=example>show reverse "abc</dd>
<dt><code>gensym</code>
<dd>Outputs a unique string, e.g. <samp>G1</samp>, <samp>G2</samp>, etc.
<dd class=example>show gensym</dd>
</dl>
<h4>2.2 Data Selectors</h4>
<dl>
<dt><code>first <var>list</var></code>
<dt><code>last <var>list</var></code>
<dd>Outputs the first or last item (or character) from the list (or word), respectively
<dd class=example>show first [ 1 2 3 ]</dd>
<dd class=example>show first "abc</dd>
<dd class=example>show last [ 1 2 3 ]</dd>
<dd class=example>show last "abc</dd>
<dt><code>firsts <var>listoflists</var></code>
<dd>Outputs a list of the first item (or character) of each sublist (or word)
<dd class=example>show firsts [ [1 2 3] [a b c] ]</dd>
<dd class=example>show firsts [ abc def ]</dd>
<dt><code>butfirst <var>list</var></code>
<dt><code>bf <var>list</var></code>
<dt><code>butlast <var>list</var></code>
<dt><code>bl <var>list</var></code>
<dd>Outputs the list (or word), except for the first/last item (or character)
<dd class=example>show butfirst [ 1 2 3 ]</dd>
<dd class=example>show butfirst "abc</dd>
<dd class=example>show butlast [ 1 2 3 ]</dd>
<dd class=example>show butlast "abc</dd>
<dt><code>butfirsts <var>listoflists</var></code>
<dt><code>bfs <var>listoflists</var></code>
<dd>Outputs a list of sublists (or words) without the first item (or characters)
<dd class=example>show butfirsts [ [ 1 2 3 ] [ a b c ] ]</dd>
<dd class=example>show butfirsts [ abc def ]</dd>
<dt><code>item <var>index</var> <var>thing</var></code>
<dd>Outputs the indexth item of the list or array or word
<dd class=example>show item 2 [ 1 2 3 ]</dd>
<dd class=example>show item 2 "abc</dd>
<dt><code>mditem [<var>index</var> ...] <var>thing</var></code>
<dd>Outputs an item from a multi-dimensional array
<dd class=example>show mditem [2 1] {{a b} {c d}}</dd>
<dt><code>pick <var>list</var></code>
<dd>Outputs one item from a list (or word), at random
<dd class=example>show pick [ 1 2 3 ]</dd>
<dd class=example>show pick "abc</dd>
<dt><code>remove <var>thing</var> <var>list</var></code>
<dd>Outputs the list (or word) with any occurences of thing removed
<dd class=example>show remove "b [ a b c ]</dd>
<dd class=example>show remove "a "banana</dd>
<dt><code>remdup <var>list</var></code>
<dd>Outputs the list (or word) with duplicates removed
<dd class=example>show remdup [ 1 2 3 2 3 4 3 4 5 ]</dd>
<dd class=example>show remdup "banana</dd>
<dt><code>quoted <var>thing</var></code>
<dd>Outputs thing with " prepended if a word, or just thing otherwise.
<dd class=example>show quoted "abc</dd>
<dt><code>split <var>thing</var> <var>list</var></code>
<dd>Outputs the list split into a list of lists (or list of words) wherever thing appears.
<dd class=example>show split "a "banana</dd>
<dd class=example>show split 3 [1 2 3 4 1 2 3 4]</dd>
</dl>
<h4>2.3 Data Mutators</h4>
<dl>
<dt><code>setitem <var>index</var> <var>array</var> <var>value</var></code>
<dd>Sets the indexth item of the array to value (circular arrays prevented)
<dd class=example>make "a { 1 2 3 } setitem 2 :a "x show :a</dd>
<dt><code>mdsetitem [<var>index</var>...] <var>array</var> <var>value</var></code>
<dd>Sets an item in a multi-dimensional array to value (circular arrays prevented)
<dd class=example>make "a {{1 2} {3 4}} mdsetitem [2 1] :a "x show :a</dd>
<dt><code>.setfirst <var>list</var> <var>value</var></code>
<dd>Sets the first item of the list to value
<dd class=example>make "a [ 1 2 3 ] .setfirst :a "7 show :a</dd>
<dt><code>.setbf <var>list</var> <var>value</var></code>
<dd>Sets the 'butfirst' of the list to the items in value (a list)
<dd class=example>make "a [ 1 2 3 ] .setbf :a [ 4 9 ] show :a</dd>
<dt><code>.setitem <var>index</var> <var>array</var> <var>value</var></code>
<dd>Sets the indexth item of the array to value (circular arrays allowed)
<dd class=example>make "a { 1 2 3 } setitem 2 :a "x show :a</dd>
<dt><code>push <var>stackname</var> <var>thing</var></code>
<dt><code>pop <var>stackname</var></code>
<dd>Push to/pop from a stack i.e. list variable. Stacks grow from the front. Works on words.
<dd class=example>make "s [ 2 1 ] push "s 3 show :s show pop "s</dd>
<dd class=example>make "s "ba push "s "c show :s show pop "s</dd>
<dt><code>queue <var>stackname</var> <var>thing</var></code>
<dt><code>dequeue <var>stackname</var></code>
<dd>Add/remove from a queue i.e. list variable, Queues grow from the end. Works on words.
<dd class=example>make "q [ 1 2 ] queue "q 3 show :q show dequeue "q</dd>
<dd class=example>make "q "ab queue "q "c show :q show dequeue "q</dd>
</dl>
<h4>2.4 Predicates</h4>
<p>Predicates return 1 (true) or 0 (false) </p>
<dl>
<dt><code>wordp <var>thing</var></code>
<dt><code>word? <var>thing</var></code>
<dt><code>listp <var>thing</var></code>
<dt><code>list? <var>thing</var></code>
<dt><code>arrayp <var>thing</var></code>
<dt><code>array? <var>thing</var></code>
<dt><code>numberp <var>thing</var></code>
<dt><code>number? <var>thing</var></code>
<dd>Test if thing is a word, list, array, or number respectively.
<dt><code>emptyp <var>expr</var></code>
<dt><code>empty? <var>expr</var></code>
<dd>Test if thing is an empty list or empty string.
<dt><code>equalp <var>expr</var> <var>expr</var></code>
<dt><code>equal? <var>expr</var> <var>expr</var></code>
<dt><code><var>expr</var> = <var>expr</var></code>
<dt><code>notequalp <var>expr</var> <var>expr</var></code>
<dt><code>notequal? <var>expr</var> <var>expr</var></code>
<dt><code><var>expr</var> <> <var>expr</var></code>
<dd>Equality/inequality tests. Compares strings, numbers, or lists (equal if length and all members are equal).
<dt><code>beforep <var>thing1</var> <var>thing2</var></code>
<dt><code>before? <var>thing1</var> <var>thing2</var></code>
<dd>Test string collation order.
<dt><code>.eq <var>thing1</var> <var>thing2</var></code>
<dd>Test if things have the same identity.
<dt><code>memberp <var>thing</var> <var>list</var></code>
<dt><code>member? <var>thing</var> <var>list</var></code>
<dd>Test if thing is equal to any member of list.
<dt><code>substringp <var>thing1</var> <var>thing2</var></code>
<dt><code>substring? <var>thing1</var> <var>thing2</var></code>
<dd>Test if thing1 is a substring of thing2.
</dl>
<h4>2.5 Queries</h4>
<dl>
<dt><code>count <var>thing</var></code>
<dd>Outputs length of a list or number of characters in a string
<dd class=example>show count [ 1 2 3 ]</dd>
<dd class=example>show count "hello</dd>
<dt><code>ascii <var>expr</var></code>
<dd>Outputs ASCII (actually, Unicode) code point for first character of string
<dd class=example>show ascii "abc</dd>
<dt><code>char <var>expr</var></code>
<dd>Outputs Unicode character at specified code point
<dd class=example>show char 97</dd>
<dt><code>member <var>thing</var> <var>list</var></code>
<dd>Outputs the list (or word) from the first occurence of thing to the end, or empty list (or word)
<dd class=example>show member "a "banana</dd>
<dd class=example>show member 2 [1 2 3 4]</dd>
<dt><code>uppercase <var>expr</var></code>
<dt><code>lowercase <var>expr</var></code>
<dd>Outputs string converted to upper/lowercase
<dd class=example>show uppercase "abc</dd>
<dd class=example>show lowercase "ABC</dd>
<dt><code>standout <var>expr</var></code>
<dd>Outputs string with alphanumeric characters in bold
<dd class=example>show standout "ABCabc123</dd>
<dt><code>parse <var>word</var></code>
<dd>Outputs word parsed as a list.
<dd class=example>show parse "1+2</dd>
<dt><code>runparse <var>word</var></code>
<dd>Outputs word parsed as instructions.
<dd class=example>show runparse "1+2</dd>
</dl>
<h3 id="sec3">3. Communication</h3>
<h4>3.1 Transmitters</h4>
<dl>
<dt><code>print <var>thing</var></code>
<dt><code>pr <var>thing</var></code>
<dt>(<code>print <var>thing1</var> <var>thing2</var> ...)</code>
<dt>(<code>pr <var>thing1</var> <var>thing2</var> ...)</code>
<dd>Print inputs to the text screen, separated by spaces, and followed by a newline.
Square brackets are only put around sublists.
<dd class=example>print "hello</dd>
<dt><code>type <var>thing</var></code>
<dt>(<code>type <var>thing1</var> <var>thing2</var> ...)</code>
<dd>Like <code>print</code> but with no trailing newline.
<dd class=example>type "hel type "lo</dd>
<dt><code>show <var>thing</var></code>
<dt>(<code>show <var>thing1</var> <var>thing2</var> ...)</code>
<dd>Like <code>print</code> but with square brackets around list inputs.
<dd class=example>show "hello</dd>
</dl>
<h4>3.2 Receivers</h4>
<dl>
<dt><code>readlist</code>
<dt><code>(readlist <var>promptstr</var>)</code>
<dd>Prompt the user for a line of input. The result is a list of words.
<dd class=example>show readlist</dd>
<dd class=example>make "colors (readlist [Type some colors:]) show :colors</dd>
<dt><code>readword</code>
<dt><code>(readword <var>promptstr</var>)</code>
<dd>Prompt the user for a line of input. The result (including spaces) is the single word output.
<dd class=example>show readword</dd>
<dd class=example>make "name (readword [What is your name?]) show :name</dd>
</dl>
<!--
<h4>3.3 File Access</h4>
<dl>
</dl>
-->
<h4>3.4 Terminal Access</h4>
<dl>
<dt><code>cleartext</code>
<dt><code>ct</code>
<dd>Clear the text screen.
<dt><code>settextcolor <var>color</var></code>
<dd>Change the text color.
<dt><code>textcolor</code>
<dd>Output the current text color.
<dt><code>increasefont</code>
<dt><code>decreasefont</code>
<dd>Increase/decrease the text size.
<dt><code>settextsize <var>height</var></code>
<dd>Change the text size (in pixels).
<dt><code>textsize</code>
<dd>Output the current text size (in pixels).
<dt><code>setfont <var>name</var></code>
<dd>Change the text font.
<dt><code>font</code>
<dd>Output the current text font.
</dl>
<h3 id="sec4">4. Arithmetic</h3>
<h4>4.1 Numeric Operations</h4>
<p>Inputs are numbers or numeric expressions, output is a number.</p>
<dl>
<dt><code>sum <var>expr</var> <var>expr</var></code>
<dt><code>(sum <var>expr</var> <var>...</var>)</code>
<dt><code><var>expr</var> + <var>expr</var></code>
<dt><code>difference <var>expr</var> <var>expr</var></code>
<dt><code><var>expr</var> - <var>expr</var></code>
<dt><code>product <var>expr</var> <var>expr</var></code>
<dt><code>(product <var>expr</var> <var>...</var>)</code>
<dt><code><var>expr</var> * <var>expr</var></code>
<dt><code>quotient <var>expr</var> <var>expr</var></code>
<dt><code>(quotient <var>expr</var>)</code>
<dt><code><var>expr</var> / <var>expr</var></code>
<dt><code>power <var>expr</var> <var>expr</var></code>
<dt><code><var>expr</var> ^ <var>expr</var></code>
<dd>
Add, subtract, multiply, divide, and raise-to-the-power-of respectively.
A single input to quotient returns the reciprocal.
<dt><code>remainder <var>expr</var> <var>expr</var></code>
<dt><code><var>expr</var> % <var>expr</var></code>
<dt><code>modulo <var>expr</var> <var>expr</var></code>
<dd>
Outputs the remainder (modulus). For <code>remainder</code> and <code>%</code>
the result has the same sign as the first input; for <code>modulo</code> the
result has the same sign as a the second input.
<dt><code>minus <var>expr</var></code>
<dt><code>- <var>expr</var></code>
<dd>
Unary minus sign must begin a top-level expression, follow an infix
operator, or have a leading space and no trailing space.
<dt><code>abs <var>num</var></code>
<dd>Absolute value
<dt><code>int <var>num</var></code>
<dt><code>round <var>num</var></code>
<dd>Truncate or round a number, respectively.
<dt><code>sqrt <var>expr</var></code>
<dt><code>exp <var>expr</var></code>
<dt><code>log10 <var>expr</var></code>
<dt><code>ln <var>expr</var></code>
<dd>Square root, <i>e</i> to the power of, common logarithm, and natural logarithm, respectively.
<dt><code>arctan <var>expr</var></code>
<dt><code>(arctan <var>x</var> <var>y</var>)</code>
<dt><code>sin <var>expr</var></code>
<dt><code>cos <var>expr</var></code>
<dt><code>tan <var>expr</var></code>
<dd>The usual trig functions. Angles are in degrees.
<dt><code>radarctan <var>expr</var></code>
<dt><code>(radarctan <var>x</var> <var>y</var>)</code>
<dt><code>radsin <var>expr</var></code>
<dt><code>radcos <var>expr</var></code>
<dt><code>radtan <var>expr</var></code>
<dd>The usual trig functions. Angles are in radians.
<dt><code>iseq <var>first</var> <var>last</var></code>
<dd>Outputs a list with integers from <var>first</var> to <var>last</var>, inclusive
<dd class=example>show iseq 1 10</dd>
<dt><code>rseq <var>first</var> <var>last</var> <var>count</var></code>
<dd>Outputs a list of <var>count</var> numbers from <var>first</var> to <var>last</var>, inclusive
<dd class=example>show rseq 1 9 5</dd>
</dl>
<h4>4.2 Numeric Predicates</h4>
<dl>
<dt><code>lessp <var>expr</var> <var>expr</var></code>
<dt><code>less? <var>expr</var> <var>expr</var></code>
<dt><code><var>expr</var> < <var>expr</var></code>
<dt><code>greaterp <var>expr</var> <var>expr</var></code>
<dt><code>greater? <var>expr</var> <var>expr</var></code>
<dt><code><var>expr</var> > <var>expr</var></code>
<dt><code>lessequalp <var>expr</var> <var>expr</var></code>
<dt><code>lessequal? <var>expr</var> <var>expr</var></code>
<dt><code><var>expr</var> <= <var>expr</var></code>
<dt><code>greaterequalp <var>expr</var> <var>expr</var></code>
<dt><code>greaterequal? <var>expr</var> <var>expr</var></code>
<dt><code><var>expr</var> >= <var>expr</var></code>
<dd>Less than, greater than, less than or equal to, greater than or equal to,
respectively. Inputs are numbers or numeric expressions, output is 1 (true) or 0 (false).
</dl>
<h4>4.3 Random Numbers</h4>
<dl>
<dt><code>random <var>expr</var></code>
<dt><code>(random <var>start</var> <var>end</var>)</code>
<dd>Outputs a random number from 0 through one less than <var>expr</var>, or from start to end inclusive.
<dd class=example>show random 10</dd>
<dd class=example>show (random 1 6)</dd>
<dt><code>rerandom</code>
<dt>(<code>rerandom <var>expr</var>)</code>
<dd>Reseeds the random number generator, either to a fixed value or the specified seed.
</dl>
<h4>4.4 Print Formatting</h4>
<dl>
<dt><code>form <var>expr</var> <var>width</var> <var>precision</var></code>
<dd>Outputs a formatted string with the result of a numeric expression with <var>precision</var> decimal places and
padded on the left with spaces (if necessary) to be at least <var>width</width> characters long.
<dd class=example>show form 1/3 10 3</dd>
</dl>
<h4>4.5 Bitwise Operations</h4>
<dl>
<dt><code>bitand <var>expr</var> <var>expr</var></code>
<dt><code>(bitand <var>expr</var> ...)</code>
<dt><code>bitor <var>expr</var> <var>expr</var></code>
<dt><code>(bitor <var>expr</var> ...)</code>
<dt><code>bitxor <var>expr</var> <var>expr</var></code>
<dt><code>(bitxor <var>expr</var> ...)</code>
<dt><code>bitnot <var>expr</var></code>
<dd>Bitwise and, or, exclusive-or, and not, respectively.
<dt><code>ashift <var>expr</var> <var>bitcount</var></code>
<dd>Arithmetic bit shift. If bitcount is negative, shifts to the right, preserving sign.
<dt><code>lshift <var>expr</var> <var>bitcount</var></code>
<dd>Logical bit shift. If bitcount is negative, shifts to the right, zero-filling.
</dl>
<h3 id="sec5">5. Logical Operations</h3>
<dl>
<dt><code>true</code>
<dd>Outputs 1
<dt><code>false</code>
<dd>Outputs 0
<dt><code>and <var>expr</var> <var>expr</var></code>
<dt><code>(and <var>expr</var> <var>...</var>)</code>
<dt><code>or <var>expr</var> <var>expr</var></code>
<dt><code>(or <var>expr</var> <var>...</var>)</code>
<dt><code>xor <var>expr</var> <var>expr</var></code>
<dt><code>(xor <var>expr</var> <var>...</var>)</code>
<dt><code>not <var>expr</var></code>
<dd>Logical "and", "or", "exclusive-or", and "not", respectively.
Inputs are numbers or numeric expressions, output is 1 (true) or 0 (false).
</dl>
<h3 id="sec6">6. Graphics</h3>
<p>An introduction to <a target="_blank" href="https://www.cs.berkeley.edu/~bh/v1ch10/turtle.html">Turtle Geometry</a>.</p>
<h4>6.1 Turtle Motion</h4>
<dl>
<dt><code>forward <var>expr</var></code>
<dt><code>fd <var>expr</var></code>
<dd>Move turtle forward <var>expr</var> pixels
<dd class=example>fd 100</dd>
<dt><code>back <var>expr</var></code>
<dt><code>bk <var>expr</var></code>
<dd>Move turtle backward <var>expr</var> pixels
<dd class=example>bk 100</dd>
<dt><code>left <var>expr</var></code>
<dt><code>lt <var>expr</var></code>
<dd>Rotate <var>expr</var> degrees counterclockwise
<dd class=example>lt 90</dd>
<dt><code>right <var>expr</var></code>
<dt><code>rt <var>expr</var></code>
<dd>Rotate <var>expr</var> degrees clockwise
<dd class=example>rt 90</dd>
<dt><code>setpos [ <var>expr</var> <var>expr</var> ]</code>
<dt><code>setxy <var>expr</var> <var>expr</var></code>
<dt><code>setx <var>expr</var></code>
<dt><code>sety <var>expr</var></code>
<dd>Move turtle to the specified location
<dd class=example>setpos [ 100 -100 ]</dd>
<dd class=example>setxy -100 100</dd>
<dt><code>setheading <var>expr</var></code>
<dt><code>seth <var>expr</var></code>
<dd>Rotate the turtle to the specified heading
<dd class=example>setheading 45</dd>
<dt><code>home</code>
<dd>Moves the turtle to center, pointing upwards
<dt><code>arc <var>angle</var> <var>radius</var></code>
<dd>Without moving the turtle, draws an arc centered on the turtle, starting at the turtle's heading.
<dd class=example>arc 180 100</dd>
</dl>
<h4>6.2 Turtle Motion Queries</h4>
<dl>
<dt><code>pos</code>
<dt><code>xcor</code>
<dt><code>ycor</code>
<dd>Outputs the current turtle position as [ x y ], x or y respectively
<dd class=example>show pos</dd>
<dt><code>heading</code>
<dd>Outputs the current turtle heading
<dd class=example>show heading</dd>
<dt><code>towards [ <var>expr</var> <var>expr</var> ]</code>
<dd>Outputs the heading towards the specified [ x y ] coordinates
<dd class=example>show towards [ 0 0 ]</dd>
<dt><code>scrunch</code>
<dd>Outputs the current graphics scaling factors
<dd class=example>show scrunch</dd>
<dt><code>bounds</code>
<dd>Outputs the current graphics screen bounds [ xmin xmax ymin ymax ]
<dd class=example>show bounds</dd>
</dl>
<h4>6.3 Turtle and Window Control</h4>
<dl>
<dt><code>showturtle</code>
<dt><code>st</code>
<dd>Show the turtle
<dt><code>hideturtle</code>
<dt><code>ht</code>
<dd>Hide the turtle
<dt><code>clean</code>
<dd>Clear the drawing area
<dt><code>clearscreen</code>
<dt><code>cs</code>
<dd>Same as clean and home together
<dt><code>wrap</code>
<dd>If the turtle moves off the edge of the screen it will continue on the other side.
(default)
<dt><code>window</code>
<dd>The turtle can move past the edges of the screen, unbounded.
<dt><code>fence</code>
<dd>If the turtle attempts to move past the edge of the screen it will stop.
<dt><code>fill</code>
<dd>Does a paint bucket flood fill at the turtle's position.
<dd class=example>arc 360 100 fill</dd>
<dt><code>filled <var>fillcolor</var> [ <var>statements ...</var> ]</code>
<dd>Execute <var>statements</var> without drawing but keeping track of turtle movements.
When complete, fill the region traced by the turtle with <var>fillcolor</var>
and outline the region with the current pen style.
<dd class=example>filled "red [ repeat 5 [ fd 100 rt 144 ] ]</dd>
<dt><code>label <var>expr</var></code>
<dd>Draw a word (same logic as <code>print</code>) on the graphics display at the turtle location
<dd class=example>repeat 8 [ label "Logo rt 45 ]</dd>
<dt><code>setlabelheight <var>expr</var></code>
<dd>Set the height for text drawn by <code>label</code>, in pixels
<dd class=example>setlabelheight 100 label "Logo</dd>
<dt><code>setlabelfont <var>expr</var></code>
<dd>Set the font for text drawn by <code>label</code>
<dd class=example>setlabelfont "Times\ New\ Roman label "Logo</dd>
<dt><code>setscrunch <var>sx</var> <var>sy</var></code>
<dd>Set the graphics scaling factors
<dd class=example>setscrunch 1 2 arc 360 100</dd>
<dt><code>setturtle <var>index</var></code>
<dd>Switch to the turtle numbered <var>index</var> (starting from 1 for the default turtle present at start).
If the turtle has not been used yet, it will be created at the center, facing upwards, visible, with the pen down.
<dd class=example>setturtle 2 rt 90 fd 100</dd>
<dt><code>ask <var>turtleindex</var> [ <var>statements ...</var> ]</code>
<dd>Execute <var>statements</var> as turtle number <var>turtleindex</var>.
<dd class=example>ask 2 [ rt 90 fd 100 ]</dd>
<dt><code>clearturtles</code>
<dd>Remove all turtles, keeping the current one as index 1.
<dd class=example>fd 50 setturtle 2 rt 90 fd 100 clearturtles </dd>
</dl>
<h4>6.4 Turtle and Window Queries</h4>
<dl>
<dt><code>shownp</code>
<dt><code>shown?</code>
<dd>Outputs 1 if the turtle is shown, 0 if the turtle is hidden
<dt><code>turtlemode</code>
<dd>Outputs <code>WRAP</code>, <code>WINDOW</code> or <code>FENCE</code>
<dt><code>labelsize</code>
<dd>Outputs the height of text drawn by <code>label</code>, in pixels
<dt><code>labelfont</code>
<dd>Outputs the name of the font drawn by <code>label</code>
<dt><code>turtle</code>
<dd>Outputs the index of the currently-active turtle
<dt><code>turtles</code>
<dd>Outputs the largest index that has been passed to <code>setturtle</code>
</dl>
<h4>6.5 Pen and Background Control</h4>
<dl>
<dt><code>pendown</code>
<dt><code>pd</code>
<dd>Turtle resumes leaving a trail
<dt><code>penup</code>
<dt><code>pu</code>
<dd>Turtle stops leaving a trail
<dt><code>penpaint</code>
<dt><code>ppt</code>
<dt><code>penerase</code>
<dt><code>pe</code>
<dt><code>penreverse</code>
<dt><code>px</code>
<dd>Change the turtle drawing mode -
<em>paint</em> (the default) leaves a colored trail,
<em>erase</em> restores the background,
<em>reverse</em> inverts the background.
<dd class=example>setpw 10 px repeat 5 [ fd 100 rt 144 ]</dd>
<dt><code>setpencolor <var>logocolor</var></code>
<dt><code>setpencolor <var>csscolor</var></code>
<dt><code>setpencolor [<var>r</var> <var>g</var> <var>b</var>]</code>
<dd>Set pen/text color. Color can be a standard Logo color number (0-15), CSS color string (<a target="_blank" href="https://www.w3.org/TR/css3-color/">CSS color names or #rrggbb</a>), or in the list version, r/g/b values in 0...99.
<dd>The standard Logo colors are:
<style>
#colortable td { width: 25%; padding-left: 4px; padding-right: 4px; text-align: center; }
</style>
<table id="colortable">
<tr>
<td style="background-color: black; color: white;">0<br>black
<td style="background-color: blue;">1<br>blue
<td style="background-color: lime;">2<br>green
<td style="background-color: cyan;">3<br>cyan
<tr>
<td style="background-color: red;">4<br>red
<td style="background-color: magenta;">5<br>magenta
<td style="background-color: yellow;">6<br>yellow
<td style="background-color: white;">7<br>white
<tr>
<td style="background-color: brown;">8<br>brown
<td style="background-color: tan;">9<br>tan
<td style="background-color: green;">10<br>green
<td style="background-color: aquamarine;">11<br>aqua
<tr>
<td style="background-color: salmon;">12<br>salmon
<td style="background-color: purple;">13<br>purple
<td style="background-color: orange;">14<br>orange
<td style="background-color: gray;">15<br>gray
</table>
<dd class=example>setpencolor 4</dd>
<dd class=example>setpencolor "red</dd>
<dd class=example>setpencolor "#ff0000</dd>
<dd class=example>setpencolor [ 99 0 0 ]</dd>
<dt><code>setpalette <var>colornumber</var> <var>csscolor</var></code>
<dt><code>setpalette <var>colornumber</var> [<var>r</var> <var>g</var> <var>b</var>]</code>
<dd>Change one of the standard color entries (8 or above) to the given color.</dd>
<dd class=example>setpalette 8 "pink setbg 8</dd>
<dd class=example>setpalette 8 "#ff4f00 setbg 8</dd>
<dd class=example>setpalette 8 [ 99 31 0 ] setbg 8</dd>
<dt><code>setpensize <var>expr</var></code>
<dd>Set pen width in pixels. If <var>expr</var> is a list, the first member is used.
<dt><code>setbackground <var>color</var></code>
<dt><code>setscreencolor <var>color</var></code>
<dt><code>setsc <var>color</var></code>
<dd>Set the background color; same options as <code>setpencolor</code>
<dd class=example>setbackground "red</dd>
</dl>
<h4>6.6 Pen Queries</h4>
<dl>
<dt><code>pendownp</code>
<dt><code>pendown?</code>
<dd>Outputs 1 if the pen is down, 0 otherwise
<dd class=example>show pendown?</dd>
<dt><code>penmode</code>
<dd>Outputs <code>PAINT</code>, <code>ERASE</code> or <code>REVERSE</code>
<dd class=example>show penmode</dd>
<dt><code>pencolor</code>
<dt><code>pc</code>
<dd>Outputs the current pen color. This will be a CSS color string, not necessarily the value passed in.
<dd class=example>show pencolor</dd>
<dt><code>palette <var>colornumber</var></code>
<dd>Outputs the a palette entry. This will be a CSS color string, not necessarily the value passed in.</dd>
<dd class=example>show palette 8</dd>
<dt><code>pensize</code>
<dd>Outputs a two element list with the pen width and height (usually the same).
<dd class=example>show pensize</dd>
<dt><code>background</code>
<dt><code>bg</code>
<dt><code>getscreencolor</code>
<dt><code>getsc</code>
<dd>Outputs the background color. This will be a CSS color string, not necessarily the value passed in.
<dd class=example>show background</dd>
</dl>
<!--
<h4>6.7 Saving and Loading Pictures</h4>
-->
<h4>6.7 Bitmap Operations</h4>
<dl>
<dt><code>bitcut <var>width</var> <var>height</var></code>
<dd>Copy a bitmap, from the turtle's position <var>width</var> by <var>height</var> pixels.
<dt><code>bitpaste</code>
<dd>Paste the previously copied bitmap at the current turtle position.
<dd class=example>repeat 4 [ rt 90 fd 40 ] bitcut 50 50 pu fd 100 bitpaste</dd>
</dl>
<h4>6.8 Mouse/Touch Queries</h4>
<dl>
<dt><code>mousepos</code></dt>
<dd>Outputs a list of the x, y coordinates of the last mouse position</dd>
<dd class=example>forever [setpos mousepos]</dd>
<dt><code>clickpos</code></dt>
<dd>Outputs a list of the x, y coordinates of the last mouse press</dd>
<dd class=example>forever [setpos clickpos]</dd>
<dt><code>buttonp</code></dt>
<dt><code>button?</code></dt>
<dd>Outputs 1 if any mouse button is down, 0 otherwise.</dd>
<dd class=example>forever [ifelse button? [pd] [pu] setpos mousepos]</dd>
<dt><code>button</code></dt>
<dd>Outputs a number indicating the pressed mouse buttons
(<code>1</code> = left, 2 = right, etc) or 0 for none.
<dt><code>touches</code></dt>
<dd>Outputs a list of current touch coordinates</dd>
<dd class=example>forever [ifelse count touches [setpos first touches pendown] [penup]]</dd>
</dl>
<h3 id="sec7">7. Workspace Management</h3>
<h4>7.1 Procedure Definition</h4>
<dl>
<dt><code>to <var>procname</var> <var>inputs ...</var> <var>statements ...</var> end</code>
<dd>Define a new named procedure. Inputs can be:
<ul>
<li>Required: <code>:a :b</code></li>
<li>Optional (with default values): <code>[:c 5] [:d 7]</code></li>
<li>Rest (remaining inputs as a list): <code>[:r]</code></li>
<li>Default number of inputs: <code>3</code>
</ul>
<dd class=example>to star :n repeat 5 [ fd :n rt 144 ] end</dd>
<dt><code>define <var>procname</var> [[<var>inputs</var> ...][<var>statements</var> ...]]</code>
<dd>Define a new named procedure with optional inputs
<dd class=example>define "star [[n][repeat 5 [fd :n rt 144]]]</dd>
<dt><code>def <var>procname</var></code>
<dd>Outputs the definition of a named procedure as a string
<dd class=example>show def "star</dd>
<dt><code>text <var>procname</var></code>
<dd>Outputs the definition of a named procedure as a list, suitable for use with <code>DEFINE</code>
<dd class=example>show text "star</dd>
<dt><code>copydef <var>newname</var> <var>oldname</var></code>
<dd>Copy a procedure. If a procedure <var>newname</var> already existed it will
be overridden. Primitive procedures can't be overridden unless <code>REDEFP</code> is <code>TRUE</code>.
<dd class=example>copydef "new "old</dd>
</dl>
<h4>7.2 Variable Definition</h4>
<dl>
<dt><code>make <var>varname</var> <var>expr</var></code>
<dd>Update a variable or define a new global variable. The variable name must
be quoted
<dd class=example>make "myvar 5</dd>
<dt><code>name <var>expr</var> <var>varname</var></code>
<dd>Like <code>make</code> but with the inputs reversed
<dd class=example>name 5 "myvar</dd>
<dt><code>local <var>varname</var></code>
<dt><code>(local <var>varname</var> ...)</code>
<dd>A subsequent <code>make</code> will create the variable(s) in the local scope instead of the global scope
<dd class=example>local "myvar</dd>
<dt><code>localmake <var>varname</var> <var>expr</var></code>
<dd>Define a variable in the local scope (shortcut for <code>local</code> then <code>make</code>
<dd class=example>localmake "myvar 5</dd>
<dt><code>thing <var>varname</var></code>
<dd>Outputs the value of variable. <code>:foo</code> is a shortcut for <code>thing "foo</code>
<dd class=example>show thing "myvar</dd>
<dt><code>global <var>varname</var></code>
<dd>Reserve the variable at the global scope. This doesn't do anything useful.
<dd class=example>global "myvar</dd>
</dl>
<h4>7.3 Property Lists</h4>
<dl>
<dt><code>pprop <var>plistname</var> <var>propname</var> <var>value</var></code>
<dd>Set the property <var>propname</var> in the property list <var>plistname</var> to value <var>value</value>.
<dt><code>gprop <var>plistname</var> <var>propname</var></code>
<dd>Get the value of the property <var>propname</var> in the property list <var>plistname</var>, or the empty list if no such property.
<dt><code>remprop <var>plistname</var> <var>propname</var></code>
<dd>Remove the property <var>propname</var> in the property list <var>plistname</var>.
<dt><code>plist <var>plistname</var></code>
<dd>Return a list of properties in the property list <var>plistname</var>, alternating property name, property value.
</dl>
<h4>7.4 Workspace Predicates</h4>
<p>Predicates return 1 (true) or 0 (false) </p>
<dl>
<dt><code>procedurep <var>name</var></code>
<dt><code>procedure? <var>name</var></code>
<dd>Test if there is a procedure with the given name.
<dt><code>primitivep <var>name</var></code>
<dt><code>primitive? <var>name</var></code>
<dd>Test if there is a built-in procedure with the given name.
<dt><code>definedp <var>name</var></code>
<dt><code>defined? <var>name</var></code>
<dd>Test if there is a user-defined procedure with the given name.
<dt><code>namep <var>name</var></code>
<dt><code>name? <var>name</var></code>
<dd>Test if there is a variable with the given name.
<dt><code>plistp <var>name</var></code>
<dt><code>plist? <var>name</var></code>
<dd>Test if there is a property list with the given name.
</dl>
<h4>7.5 Workspace Queries</h4>
<dl>
<dt><code>contents</code>
<dd>Outputs a list with three members. The first is a list of user-defined procedure names.
The second is a list of defined variables. The third is a list of non-empty property list names.
Only non-buried procedures, variables, and property lists are included.
<dt><code>buried</code>
<dd>Outputs a list with three members. The first is a list of user-defined procedure names
The second is a list of defined variables. The third is a list of non-empty property list names.
Only buried procedures, variables, and property lists are included.
<dt><code>procedures</code>
<dd>Outputs a list of user-defined non-buried procedure names.
<dt><code>primitives</code>
<dd>Outputs a list of primitive non-buried procedure names.
<dt><code>globals</code>
<dd>Outputs a list of defined non-buried global variables.
<dt><code>names</code>
<dd>Outputs a list with two members. The first is an empty list.
The second is a list of defined non-buried variables.
<dt><code>plists</code>
<dd>Outputs a list with three members. The first is an empty list.
The second is an empty list. The third is a list of non-empty non-buried property list names.
<dt><code>namelist <var>name</var></code>
<dt><code>namelist <var>namelist</var></code>
<dd>Return a <code>contents</code>-style list with the given variable names.
<dt><code>pllist <var>plname</var></code>
<dt><code>pllist <var>plnamelist</var></code>