-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrgcomm.sl
2313 lines (2094 loc) · 73.4 KB
/
grgcomm.sl
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
%==========================================================================%
% GRGcomm.sl Main Commands %
%==========================================================================%
% GRG 3.2 Standard Lisp Source Code (C) 1988-97 Vadim V. Zhytnikov %
%==========================================================================%
% This file is distributed without any warranty. You may modify it but you %
% are not allowed to remove author's name and/or distribute modified file. %
%==========================================================================%
%---------- Some General Aux Functions -----------------------------------
% Data name -> Internal variables list ...
(de dgood!> (lst)
(prog (w wa wss)
(setq w lst)
(cond ((eqs!> lst '(all)) (return(alldata!>)))) % word!!!
(setq wss lst)
(setq lst (assocf!> lst ![datl!]))
(cond ((and (null lst) w (null(cdr w)) (idp(car w)))
(progn (setq wa (incomiv!>(explode(car w))))
(cond ((flagp wa '!+ivar) (setq lst (ncons wa)))))))
(cond ((null lst) (progn (setq ![er!] 6030)
(doubl!> wss)
(return !!er!!))))
(setq lst (car lst))
(cond ((atom lst) (setq lst (ncons lst))))
(setq w (constrpl!> lst))
(cond ((eq w !!er!!) (return !!er!!)))
(return lst)))
% Same but for Write Macro Tensors are alowed ...
(de dgoodw!> (lst)
(prog (w wa wss)
(setq w lst)
(cond ((eqs!> lst '(all)) (return(alldata!>)))) % word!!!
(setq wss lst)
(setq lst (assocf!> lst ![datl!]))
(cond ((and (null lst) w (null(cdr w)) (idp(car w)))
(progn (setq wa (incomiv!>(explode(car w))))
(cond ((or (flagp wa '!+ivar) (flagp wa '!+macros2))
(setq lst (ncons wa)))))))
(cond ((null lst) (progn (setq ![er!] 6030)
(doubl!> wss)
(return !!er!!))))
(setq lst (car lst))
(cond ((atom lst) (setq lst (ncons lst))))
(setq w (constrpl!> lst))
(cond ((eq w !!er!!) (return !!er!!)))
(return lst)))
% All existing data variables ...
(de alldata!> nil
(proc (w lst)
(setq lst ![datl!])
(while!> lst
(cond ((and (atom(cadar lst)) (eval(cadar lst)))
(setq w (cons (cadar lst) w))))
(setq lst (cdr lst)))
(setq lst ![abbr!])
(while!> lst
(cond ((eval(car lst)) (setq w (cons (car lst) w))))
(setq lst (cdr lst)))
(return(reversip w))))
% Data variables list modification in correspondence with flags ..
(de altdata!> (w)
(cond ((null w) nil)
((atom (car w)) (consmem!> (car w) (altdata!>(cdr w))))
((eval(caar w)) (appmem!> (cdar w) (altdata!>(cdr w))))
(t (altdata!>(cdr w)))))
%----- Commands in `grg.cfg' file ---------------------------------------
% Package ...
(dm package!> (w) (list 'package0!> (list 'quote (cdr w))))
(de package0!> (w)
(prog (ww)
(setq ![lower!] (islowercase!>))
lab
(cond ((null w) (return nil)))
(setq ww (loadpack!> (ncons(car w)) nil))
(cond ((eq ww !!er!!) (prog2 (erm!> ![er!]) (return !!er!!))))
(setq w (cdr w))
(go lab)
))
% On ...
(dm on!> (w) (list 'on0!> (list 'quote (cdr w))))
(de on0!> (w)
(prog (ww)
(setq ![lower!] (islowercase!>))
lab
(cond((null w)(return nil)))
(setq ww (onoff!> (ncons(car w)) t))
(cond((eq ww !!er!!) (prog2 (erm!> ![er!])(return !!er!!))))
(setq w (cdr w))
(go lab)
))
% Off ...
(dm off!> (w) (list 'off0!> (list 'quote (cdr w))))
(de off0!> (w)
(prog (ww)
(setq ![lower!] (islowercase!>))
lab
(cond((null w)(return nil)))
(setq ww (onoff!> (ncons(car w)) nil))
(cond((eq ww !!er!!) (prog2 (erm!> ![er!])(return !!er!!))))
(setq w (cdr w))
(go lab)
))
% Signature ...
(dm signature!> (w) (list 'signature0!> (list 'quote (cdr w))))
(de signature0!> (w)
(proc (wr ww)
(setq ww w)
(while!> ww
(cond ((equal (car ww) '!+) (setq wr (cons 1 wr)))
((equal (car ww) '!-) (setq wr (cons -1 wr)))
(t (erm!> 9002) (bye)))
(setq ww (cdr ww)))
(setq ![sgn!] (reverse wr))
(setq ![dim!] (length ![sgn!]))
(cond ((lessp ![dim!] 2) (erm!> 9002) (bye)))
(tunedim!>) ))
%----- On ...; and Off ...; commands 20.02.94 -----------------------
(de onoff!> (lst bool)
(proc (w wc wo ww)
(cond ((null lst) (return nil)))
(setq w (memlist!> '!, lst))
(cond ((eq w !!er!!) (prog2 (setq ![er!] 1100) (return !!er!!))))
(while!> w
(setq wc (car w))
(cond
((or (cdr wc) (not(idp(car wc)))) % bad parameter ...
(prog2 (setq ![er!] 1100) (return !!er!!))) )
(setq wc (idtostcase!> (car wc)))
(cond
((flagp wc 'switch) % reduce switch ...
(progn
(setq ww (makeswvar!> wc))
(setq wo (eval ww))
(cond((not(equal wo bool))(prog2
(cond
((iscsl!>)
(cond (bool (eval(list 'on (list 'quote (ncons wc)))))
(t (eval(list 'off (list 'quote (ncons wc)))))))
(t (cond (bool (eval(list '!~on (list 'quote (ncons wc)))))
(t (eval(list '!~off (list 'quote (ncons wc))))))))
(onoff1!> wc bool) ))))) % maybe extra grg tuning ...
((flagp wc '!+switch) % grg switch ...
(progn
(setq ww (makeswvar!> wc))
(setq wo (eval ww))
(cond((not(equal wo bool))
(onoff1!> wc bool) )) ))
(t(progn % none of above ...
(doub!> wc)(setq ![er!] 6402)(return !!er!!))))
(cond((not(equal wo bool))
(setq ![flaghis!] (cons (cons wc wo) ![flaghis!]))))
(setq w (cdr w)))))
% On/Off GRG switch with tuning ...
(de onoff1!> (w bool)
(progn
(set (makeswvar!> w) bool)
(setq w (get w '!=tuning)) % tuning required ...
(cond(w (apply w (list bool))))))
% On/Off GRG switch without tuning ...
(de onoff2!> (w bool)
(set (makeswvar!> w) bool))
% On/Off GRG switch without tuning but with history ...
(de onoff3!> (w bool)
(prog (ww wo)
(setq ww (makeswvar!> w))
(setq wo (eval ww))
(set ww bool)
(setq ![flaghis!] (cons (cons w wo) ![flaghis!]))))
% Makes *SWITCH from SWITCH ...
(de makeswvar!> (w)
(incom!>(cons '!* (explode2 w))))
% Tuning for TORSION ...
(de tunetorsion!> (bool)
(cond ((and bool (null !*nonmetr)) % Result is Q but N=0
(put '!#!R!I!C '!=sidxl nil)
(put '!#!G!T '!=sidxl nil)
(put '!#!T!D!I '!=sidxl nil)
(put '!#!T!S!F!L '!=sidxl nil)
)
((and bool !*nonmetr) % Result is Q and N
(put '!#!R!I!C '!=sidxl nil)
(put '!#!G!T '!=sidxl nil)
(put '!#!T!D!I '!=sidxl nil)
(put '!#!T!S!F!L '!=sidxl nil)
)
((null !*nonmetr) % Result is Q=0 and N=0
(put '!#!R!I!C '!=sidxl '((s 1 2)))
(put '!#!G!T '!=sidxl '((s 1 2)))
(put '!#!T!D!I '!=sidxl '((s 1 2)))
(put '!#!T!S!F!L '!=sidxl '((s 1 2)))
)
((null !*nonmetr) % Result is Q=0 but N
(put '!#!R!I!C '!=sidxl nil)
(put '!#!G!T '!=sidxl nil)
(put '!#!T!D!I '!=sidxl '((s 1 2)))
(put '!#!T!S!F!L '!=sidxl '((s 1 2)))
)
))
% Tuning for NONMETR ...
(de tunenonmetr!> (bool)
(cond (bool % Result is N with arbitrary Q
(put '!#!R!I!C '!=sidxl nil)
(put '!#!G!T '!=sidxl nil)
)
(!*torsion % Result is N=0 but Q
(put '!#!R!I!C '!=sidxl nil)
(put '!#!G!T '!=sidxl nil)
)
((null !*torsion) % Result N=0 and Q=0
(put '!#!R!I!C '!=sidxl '((s 1 2)))
(put '!#!G!T '!=sidxl '((s 1 2)))
)
))
%----- Stop; command ----------------------------------------------------
(de stop!> nil !!stop!! )
%----- Next; command ----------------------------------------------------
(de next!> nil !!next!! )
%----- Pause; command ---------------------------------------------------
(de pause!> nil
(proc(w)
(cond (![pause!] (return t))
(t (prin2 "Pausing ...") (terpri)
(setq ![pause!] t)))
(loop!> (setq w (runcom!> nil))
(exitif (or (eq w !!stop!!) (eq w !!next!!))))
(setq ![pause!] nil)
(return w)))
%----- Inverse ; command ------------------------------------------------
(de invi!> (lst)
(prog (wa wb)
(cond((null lst)(return nil)))
(setq lst (memlist!> '!, lst))
(cond((or (eq lst !!er!!) (not(eqn(length lst)2)) )
(prog2(setq ![er!] 1100)(return !!er!!))))
(setq wa (car lst))
(setq wb (cadr lst))
(cond((or (cdr wa) (cdr wb) (not(idp(car wa))) (not(idp(car wb))) )
(prog2(setq ![er!] 1100)(return !!er!!))))
(setq wa (car wa))
(setq wb (car wb))
(cond((or (and (not(flagp wa '!+fun)) (not(redgood!> wa)) )
(and (not(flagp wb '!+fun)) (not(redgood!> wb)) ) )
(prog2(setq ![er!] 1100)(return !!er!!))))
(put wa 'inverse wb)
(put wb 'inverse wa)
(return t)))
%----- Order, Factor, RemFac commands -----------------------------------
(de orfare!> (lst wt)
(proc nil
(cond((null lst)(return nil)))
(setq lst(memlist!> '!, lst))
(cond((eq lst !!er!!)
(prog2 (setq ![er!] 2202) (return !!er!!))))
(setq lst (mapcar lst 'translata!>))
(cond((memq !!er!! lst) (return !!er!!)))
(apply wt (list lst))))
%----- Substitutions calls -----------------------------------------------
(de smatch!> nil 'match)
(de famatch!> nil
(cond ((getd 'match00) 'match00)
(t 'match ) ))
(de slet!> nil
(cond ((and (getd '!~let) (not(iscsl!>))) '!~let)
(t 'let ) ))
(de falet!> nil
(cond ((getd 'let00) 'let00)
((and (getd '!~let) (not(iscsl!>))) '!~let)
(t 'let ) ))
(de sclear!> nil
(cond ((and (getd '!~clear) (not(iscsl!>))) '!~clear)
(t 'clear ) ))
(de faclear!> nil
(cond ((and (getd '!~clear) (not(iscsl!>))) '!~clear)
(t 'clear ) ))
%----- Clear ; command --------------------------------------------------
(de cleri!> (lst wt) % wt=t clear wt=nil for all clear
(proc (w wa wss)
(cond ((null lst) (return nil)))
(setq lst (memlist!> '!, lst))
(cond ((eq lst !!er!!)
(prog2 (setq ![er!] 2202) (return !!er!!))))
(while!> lst
(setq wa (translata!>(car lst)))
(cond((eq wa !!er!!) (return !!er!!))
((null wa)(prog2(setq ![er!] 8710)(return !!er!!))) )
(setq w (cons wa w))
(setq lst (cdr lst)))
(setq w (reverse w))
(cond ((null wt) % this is for all case returning (clear w)
(return (list (faclear!>) (list 'quote w)))))
(eval (list (sclear!>) (list 'quote w))) % making (clear w)
(while!> w % remembering
(setq wss (list (sclear!>) (ncons(car w))))
(setq ![sublist!] (delete wss ![sublist!]))
(setq w (cdr w)))
(return t)))
%----- Let ; and Match ; commands ---------------------------------------
(de leti!> (lst wt) (letmatchi!> lst wt t))
(de matchi!> (lst wt) (letmatchi!> lst wt nil))
% WW=T - Let, WW=NIL - Match
% WT=T - Execute (Let/Match command), WT=NIL - Form (For All command)
(de letmatchi!> (lst wt ww)
(proc (w wa wl wr wss)
(cond ((null lst) (return nil)))
(setq lst (memlist!> '!, lst))
(cond((eq lst !!er!!)
(prog2 (setq ![er!] 2202) (return !!er!!))))
(while!> lst
(setq wa (seek1!> (car lst) '!=))
(cond
((null wa)(progn
(cond((not(eq (caar lst) '!S!o!l))
(prog2(setq ![er!] 8709)(return !!er!!))))
(setq wa (soltra!>(car lst)))
(cond((eq wa !!er!!)(return !!er!!)))
(setq w (cons wa w))))
((or(null(car wa))(null(cdr wa)))
(prog2(setq ![er!] 8709)(return !!er!!)))
(t(progn
(setq wl (translata!>(reverse(car wa))))
(setq wr (translate!>(cdr wa)))
(cond((or(eq wl !!er!!)(eq wr !!er!!)) (return !!er!!))
((null wl) (prog2(setq ![er!] 8710)(return !!er!!)))
((and wr(not(zerop(car wr))))
(prog2(setq ![er!] 8711)(return !!er!!))))
(setq w (cons (list 'equal wl (cond(wr(cdr wr))(t 0))) w)))))
(setq lst (cdr lst)))
(setq w (reverse w))
(cond((null wt) % for all case - returning
(return (list (cond (ww (falet!>)) (t (famatch!>)))
(list 'quote w)))))
% let/match case - executing
(cond (ww (eval (list (slet!>) (list 'quote w))))
(t (eval (list (smatch!>) (list 'quote w)))))
(while!> w % remembering
(setq wss (list (sclear!>) (ncons(cadar w))))
(setq ![sublist!] (cons wss (delete wss ![sublist!])))
(setq w (cdr w)))
(return t)))
% Solution Translation ...
(de soltra!> (w)
(cond((or (null(setq w (cdr w))) (cdr w)
(atom(setq w (car w)))
(not(numberp(setq w (car w)))) )
(progn (doub!> '!S!o!l) (setq ![er!] 2020) !!er!!))
(t(soltra1!> w))))
(de soltra1!> (wn)
(cond((null ![sol!]) (prog2 (setq ![er!] 2113) !!er!!))
(t(proc (w wnn)
(setq wnn wn)
(setq w ![sol!])
(while!> (and w (not(zerop wn)))
(setq w (cdr w))
(setq wn (sub1 wn)))
(cond
((or(null w)(not(zerop wn)))
(progn(doub!> wnn)(setq ![er!] 2114)(return !!er!!)))
((null(car w))
(progn(setq ![er!] 2115)(return !!er!!))))
(return(mapcar (car w) 'nz!>))))))
%----- For ...; commands ------------------------------------------------
(de forinstrs!> (lst)
(cond
((null lst) nil)
((eqs!> (car lst) 'all) (foralli!> (cdr lst))) % word!!! for all ...
((memqs!> 'print lst) (proc (w) % word!!! for...print...
(while!> (not(eqs!> (car lst) 'print)) % word!!!
(setq w (cons(car lst)w))(setq lst(cdr lst)))
(cond((null(cdr lst))
(prog2(setq ![er!] 6042)(return !!er!!))))
(return(printi!>(append (cdr lst)
(cons 'for % word!!!
(reverse w)))))))
(t(prog2(setq ![er!] 6042) !!er!!))))
%----- For All...; command ----------------------------------------------
(de foralli!> (lst)
(proc (w wt wa wss w1 w2 w3)
(cond((null lst)(return nil))
((memqs!> 'let lst)(setq wt 'let)) % word!!!
((memqs!> 'match lst)(setq wt 'match)) % word!!!
((memqs!> 'clear lst)(setq wt 'clear)) % word!!!
(t(prog2(setq ![er!] 8712)(return !!er!!))))
(while!> lst
(exitif (eqs!> wt (car lst)))
(setq wa(cons(car lst)wa))
(setq lst(cdr lst)))
(cond((or(null lst)(null(cdr lst))(null wa))
(prog2(setq ![er!] 8713)(return !!er!!))))
(setq lst (cdr lst))
(cond((memqs!> 'such wa)(progn % word!!!
(setq wa (reverse wa))
(setq w3 (seek1q!> wa 'such)) % word!!!
(cond((or (null(car w3)) (null(cdr w3)) (null(cddr w3))
(not(eqs!> (cadr w3) 'that))) % word!!!
(prog2(setq ![er!] 8712)(return !!er!!))))
(setq wa (car w3))
(setq w3 (cddr w3)) )))
(setq wa(memlist!> '!, wa))
(cond((eq wa !!er!!)
(prog2 (setq ![er!] 2202) (return !!er!!))))
(while!> wa
(cond((or(cdar wa)(not(idp(caar wa))))
(prog2 (setq ![er!] 8714) (return !!er!!))))
(setq w (cons(caar wa)w))
(setq wa (cdr wa)))
(setq w1 w)
(while!> w1
(cond((not(flagp (car w1) '!+grgvar))
(setq w2 (cons(car w1)w2))))
(setq w1 (cdr w1)))
(flag w '!+grgvar)
(cond((null w3)(setq w3 t))
(t(progn
(setq w3 (booltra!> w3))
(cond((eq w3 !!er!!)(return !!er!!))))))
(setq wa
(cond((eq wt 'let) (leti!> lst nil)) % not words
((eq wt 'match) (matchi!> lst nil)) % not words
(t (cleri!> lst nil))))
(cond((eq wa !!er!!)
(prog2(remflag w2 '!+grgvar)(return !!er!!))))
(errorset (list 'forall (list 'quote (list w w3 wa)))
![erst1!] ![erst2!] )
(remflag w2 '!+grgvar)
(setq wa (cadadr wa))
(cond((not(eqs!> wt 'clear)) (setq wa (mapcar wa 'cadr)))) % not word
(while!> wa
(setq wss (list 'forall
(list w w3
(list (faclear!>)
(list 'quote (ncons(car wa)))))))
(setq ![sublist!] (delete wss ![sublist!]))
(cond((not(eq wt 'clear)) % not word
(setq ![sublist!] (cons wss ![sublist!]))))
(setq wa (cdr wa)))
(return t)))
%----- Print...; command ------------------------------------------------
(de printi!> (lst)
(prog (wi)
(cond ((null lst) (return nil)))
(setq ![modp!] ![umod!])
(cond ((not(and (fancyon!>) (not !*latex))) (terpri)))
(cond ((memqs!> 'for lst) (progn % word!!!
(setq lst (seek1q!> lst 'for)) % word!!!
(setq wi (cdr lst))
(setq lst (reverse(car lst))))))
(cond ((null lst) (return nil)))
(cond(wi(setq wi (memlist!> '!, wi))))
(cond((eq wi !!er!!)(prog2(setq ![er!] 2202)(return wi))))
(cond(wi(setq wi (itercon!> wi))))
(cond((eq wi !!er!!)(prog2(setq ![er!] 21031)(return wi))))
(setq ![allzero!] t)
(setq ![extvar!] (mapcar wi 'caar))
% This with prohibited unknown vars -> for
% (setq lst (pretrans!> lst)) % Pre Translation ...
% This with allowed unknown vars -> for
(setq lst (pretransext!> lst)) % pre translation ...
(cond ((and ![extvara!] !*nofreevars)
(mapcar ![extvara!] 'doub!>)
(setq ![er!] 2018)
(setq ![extvara!] nil)
(return !!er!!))
((and ![extvara!]
(not(and (eqn (length ![extvara!]) 1)
(equal (list 'dummyvar!> (car ![extvara!])) lst))))
(setq wi (mapcar ![extvara!] 'ncons))
(setq wi (mapcar wi 'ncons))
(setq ![extvar!] ![extvara!])
(setq ![extvara!] nil) ))
(cond ((eq lst !!er!!) (return !!er!!)))
(setq lst (printico!> wi nil lst nil))
(cond((eq lst !!er!!)(return !!er!!)))
(cond
(![allzero!]
(progn (alpri!> nil)
(grgend!>)
(grgterpri!>) (terpri)))
((and (not !*latex) (fancyon!>)) (terpri)))
(return t)))
(de appendn!> (wa wd)
(cond((null wa) wd)
(t(cons(ncons(car wa))(appendn!>(cdr wa)wd)))))
(de printico!> (wi wt lst wp)
(cond
((null wi) (progn
(setq lst (fintrans!> lst)) % final translation
(cond((eq lst !!er!!) !!er!!)
((null lst) nil)
(t(progn (setq ![allzero!] nil)
(cond(wt(prinvarl!>(reverse wt))))
(cond(!*math(gprin!> "(")))
(cond
((zerop(car lst)) (alpri!> (cdr lst))) % algexpr
(t (dfpri!> (cdr lst) (car lst)))) % form
(cond(!*math(gprin!> ")")))
(cond((ifmodo!>)(ooend!>)))
(grgterpri!>)
(cond((not(and (fancyon!>) (not !*latex))) (terpri)))
)))))
(t(proc (wa we)
(setq wa (errorset!> (list3 'itertr!> (list2 'quote (car wi))
(list2 'quote wp) )
![erst1!] ![erst2!]))
(cond((atom wa)(prog2(setq ![er!] wa)(return !!er!!)))
(t(setq wa(reverse(car wa)))))
(while!> wa
(put (caar wa) '!=subind (cdar wa))
(setq we (printico!> (cdr wi) (cons(cdar wa)wt) lst (cdar wa)))
(remprop (caar wa) '!=subind)
(cond((eq we !!er!!)(return we)))
(setq wa (cdr wa)))))))
(de prinvarl!> (w)
(proc (wr we)
(cond (!*math (setq wr '( !(!* )))
(!*macsyma (setq wr '( !/!* )))
(!*maple (setq wr '( !#! )))
((or !*grg !*reduce) (setq wr '( !% ))))
(setq we ![extvar!])
(while!> w
(setq wr (cons(car w)(cons '!= (cons(car we)wr))))
(setq w (cdr w))
(cond((and w (fancyon!>)) (setq wr (cons '!, wr))))
(setq we (cdr we)))
(setq wr (cons
(cond (!*math '!*!) )
(!*macsyma '!*!/ )
(!*grg '!;! )
((fancyon!>) '!: )
% ((fancyon!>) '!:!\! )
(t '!:! )) wr))
(setq wr (reverse wr))
(cond((ifmodo!>) (prog2(gprinwb!> wr)(gterpri!>)))
(t (algprinwb!> wr)))
(cond ((fancyon!>) (algpri!> " ")))
))
(de itercon!> (lst)
(proc (w wc)
(while!> lst
(setq wc (car lst))
(setq lst (cdr lst))
(cond((or(memq '!< wc)(memq '!> wc)(memq '!<!= wc)(memq '!>!= wc))
(progn (setq wc (itercon1!> wc))
(cond((eq wc !!er!!)(return !!er!!)))
(setq w (append wc w)) ))
(t(setq w (cons(ncons wc)w)))))
(return(reversip w))))
(de itercon1!> (lst)
(proc (w wc wa)
(while!> lst
(cond
((memq (car lst) '(!< !> !<!= !>!=))
(cond((or(null(cdr lst))(null wa))(return !!er!!))
(t(progn (setq w (cons (cons(reverse wa)wc) w))
(setq wa nil)
(setq wc (itcty!>(car lst)))
(setq lst (cdr lst)) ))))
(t(prog2(setq wa (cons(car lst)wa))
(setq lst (cdr lst))))))
(setq w (cons (cons(reverse wa)wc) w))
(return w)))
(de itcty!> (w)
(cond
((eq w '!<) 1)
((eq w '!>) 2)
((eq w '!<!=) 3)
((eq w '!>!=) 4)))
%----- Comment ... command -----------------------------------------------
(de comment!> (lst)
(cond (![unl!] (progn
(wrs ![unl!])
(print '(cout!>)) (terpri)
(print (list 'comin!> (list 'quote lst))) (terpri)
(wrs ![wri!]) ))
(t nil)))
%----- Zero/Nullify command ----------------------------------------------
(de zero!> (lst) % 05.96
(proc (w wc)
(cond ((null lst) (return nil))
((eqs!> lst '(time)) (progn % word!!!
(setq ![time!] (time))
(setq ![gctime!] (gctime))
(return nil))))
(cond ((eq (setq w (dgood!> lst)) !!er!!) (return !!er!!)))
(setq w (altdata!> w))
(while!> w
(setq wc (car w))
(cond ((not (memq wc '(![cord!] ![const!] ![fun!] ![sol!] ![apar!] )))
(cond
((eq wc '!#!G) (setq ![mtype!] 3) (setq ![dtype!] 1) )
((eq wc '!#!G!I) (setq ![mitype!] 3) (setq ![ditype!] 1) )
((eq wc '!#!T) (setq ![ftype!] 3) )
((eq wc '!#!D) (setq ![fitype!] 3) ) )
(set wc (mkbox!> wc))))
(setq w (cdr w)))))
%----- Forget ; command --------------------------------------------------
(de forget!> (lst)
(proc (w)
(cond ((null lst) (return nil))
((eq (setq w (dgood!> lst)) !!er!!) (return !!er!!)))
(setq w (altdata!> w))
(while!> w
(cond ((flagp (car w) '!+abbr) (forget1!>(car w)))
(t (msg!> 8701)))
(setq w (cdr w)))))
(de forget1!> (w)
(prog (wa wb wl)
(cond
((flagp w '!+abbr) (prog2
(setq wb ![abbr!])
(setq ![abbr!]
(loop!>
(cond ((eq w (car wb)) (return (app!> wa (cdr wb))))
(t(prog2 (setq wa (cons (car wb) wa))
(setq wb (cdr wb))))))))))
% (setplist w nil) % AMI: removes ALL properties and flags
(remprop w 'vartype) % PSL: removes GLOBAL/FLUID
(setq wl (ncons w))
(set w nil)
(foreach!> x in ![allflags!] do (remflag wl x))
(foreach!> x in ![allprops!] do (remprop w x))
))
%-------- Hold/Relese; ---------------------------------------------------
(de hold!> (lst wt)
(prog (w)
(cond ((null lst) (return nil))
((eq (setq w (dgood!> lst)) !!er!!) (return !!er!!)))
(setq w (altdata!> w))
(cond (wt (flag w '!+hold))
(t (remflag w '!+hold)))
(return t)))
%---------- Erase/Delete; -----------------------------------------------
(de erase!> (lst) % 5.96
(proc (w wc)
(cond ((null lst) (return nil))
((eq (setq w (dgood!> lst)) !!er!!) (return !!er!!)))
(setq w (altdata!> w))
(while!> w
(setq wc (car w))
(cond ((and ![umod!] (memq wc '(!#!b !#!e))) (msg!> 7012))
((eq wc '![cord!])
(rempf!> ![rpflcr!] nil) (setq ![cord!] nil))
((eq wc '![const!])
(rempf!> ![rpflcn!] nil) (setq ![const!] nil))
((eq wc '![apar!])
(rempf!> ![rpflap!] '(2)) (setq ![apar!] nil))
((eq wc '![fun!])
(rempf!> ![rpflfu!] '(1)) (setq ![fun!] nil)
(setq ![gfun!] nil) )
(t (set wc nil)))
(cond
((eq wc '!#!G) (setq ![mtype!] nil) (setq ![dtype!] nil) )
((eq wc '!#!G!I) (setq ![mitype!] nil) (setq ![ditype!] nil) )
((eq wc '!#!T) (setq ![ftype!] nil) )
((eq wc '!#!D) (setq ![fitype!] nil) ) )
(setq w (cdr w)) )
(return t)))
%----- New Commands Driver -----------------------------------------------
(de newcommands!> (w)
(cond ((null w) nil)
((eqs!> (car w) 'coordinates) (chcoord!> (cdr w))) % word!!!
((eqs!> (car w) 'object) (obdec!> (cdr w) 0)) % word!!!
((eqs!> (car w) 'equation) (obdec!> (cdr w) 1)) % word!!!
((eqs!> (car w) 'connection) (obdec!> (cdr w) 2)) % word!!!
(t (obdec!> w 0))))
%----- Show Commands Driver ----------------------------------------------
(de shcommands!> (w)
(cond ((null w) nil)
((eqs!> w '(time)) (timei!>)) % word!!!
((eqs!> w '(status)) (shstatus!>)) % word!!!
((eqs!> w '(all)) (shall!>)) % word!!!
((eqs!> w '(gc time)) (gctime!>)) % word!!!
((eqs!> (car w) 'switch) (sflag!> (cdr w))) % word!!!
((eqs!> (car w) 'file) (showfil!> (cdr w))) % word!!!
((memq '!* w) (shallbuilt!> w))
((stringp (car w)) (showfil!> w))
((and (null(cdr w)) (idp(car w))
(or (flagp (idtostcase!> (car w)) 'switch)
(flagp (idtostcase!> (car w)) '!+switch)))
(sflag!> w))
(t (showobj!> w))))
%----- Show Object -------------------------------------------------------
(de showobj!> (lst)
(proc (w)
(cond ((null lst) (return nil))
((eq (setq w (dgoodw!> lst)) !!er!!) (return !!er!!)))
(setq w (altdata!> w))
(cond ((null w) (return nil)))
(while!> w
(cond ((memq (car w) '(![cord!] ![const!] ![fun!] ![sol!] ![apar!]))
nil )
(t (shobj1!> (car w))))
(setq w (cdr w)) )
(terpri)
(return t)))
(de shobj1!> (w)
(prog (wi wt wy ww wc wd wx)
(terpri)
(setq wi (get w '!=idxl))
(setq wt (gettype!> w))
(setq wy (get w '!=sidxl))
(setq ww (get w '!=way))
(setq wd (get w '!=dens))
(gprinreset!>)
(setq ![gptab!] 2)
% Name ...
(cond ((not(or (flagp w '!+abbr) (flagp w '!+macros2))) (thepn!> w)))
% ID ...
(gprin!> (incom!>(cdr(explode2 w))))
% Indices ...
(while!> wi
(setq wc (car wi))
% Position ...
(cond
((and (upperp!> wc) (holp!> wc)) (gprin!> "^"))
((upperp!> wc) (gprin!> "'"))
((holp!> wc) (gprin!> "_"))
(t (gprin!> ".")))
% Type ...
(cond
((holp!> wc) (gprin!>(car ![wh!])) (setq ![wh!] (cdr ![wh!])))
((tetrp!> wc) (gprin!>(car ![wf!])) (setq ![wf!] (cdr ![wf!])))
((enump!> wc) (gprin!>(car ![wi!])) (setq ![wi!] (cdr ![wi!]))
(cond ((cdr wc) (gprin!> (cdr wc)))
(t (gprin!> "dim"))))
((spinp!> wc) (for!> x (1 1 (cdr wc)) do (progn
(gprin!>(car ![ws!]))
(setq ![ws!] (cdr ![ws!]))))))
(cond ((dotp!> wc) (gprin!> "~")))
(setq wi (cdr wi)))
(gpris!>)
% Type ...
(gprin!> (cond((flagp w '!+pl) "are")(t "is")))
(gpris!>)
(cond ((eqn wt -1) (gprin!> "Vector"))
((eqn wt 0) (gprin!> "Scalar"))
(t (gprin!> wt) (gprin!> "-form")))
(cond ((flagp w '!+equ) (gpris!>) (gprin!> "Equation"))
((flagp w '!+fconn) (gpris!>)
(gprils0!> '("Frame" "Connection")))
((flagp w '!+hconn) (gpris!>)
(gprils0!> '("Holonomic" "Connection")))
((flagp w '!+uconn) (gpris!>)
(gprils0!> '("Spinor" "Connection")))
((flagp w '!+dconn) (gpris!>)
(gprils0!> '("Conjugate" "Spinor" "Connection")))
((flagp w '!+macros2) (gpris!>)
(gprils0!> '("Macro" "Object")))
(wd (gpris!>)
(gprin!> "Density")
(gpris!>)
(cond ((car wd) (gprin!> "sgnD") (setq wx t)))
(cond ((cadr wd) (cond (wx (gprin!> "*")))
(setq wx t)
(gprin!> "D")
(cond ((not(eqn (cadr wd) 1))
(gprin!> "^")
(cond ((lessp (cadr wd) 0) (gprin!> "(")))
(gprin!> (cadr wd))
(cond ((lessp (cadr wd) 0) (gprin!> ")")))
))))
(cond ((caddr wd) (cond (wx (gprin!> "*")))
(setq wx t)
(gprin!> "sgnL")))
(cond ((cadddr wd) (cond (wx (gprin!> "*")))
(gprin!> "L")
(cond ((not(eqn (cadddr wd) 1))
(gprin!> "^")
(cond ((lessp (cadddr wd) 0) (gprin!> "(")))
(gprin!> (cadddr wd))
(cond ((lessp (cadddr wd) 0) (gprin!> ")")))
))))
))
(gterpri!>)
% Value ...
(cond ((flagp w '!+macros2) nil)
((eval w) (gprin!> "Value: known") (gterpri!>))
(t (gprin!> "Value: unknown") (gterpri!>)))
% Symmetries ...
(cond((null wy) (go lab1)))
(gprinreset!>) (gprin!> " ")
(setq ![gptab!] 4)
(gprin!> "Symmetries:")
(gpris!>)
(while!> wy
(shsy!>(car wy))
(cond((cdr wy) (prog2 (gprin!> ",") (gpris!>))))
(setq wy (cdr wy)))
(gterpri!>)
lab1
% Ways of calculation ...
(setq ww (allways!> ww))
(cond ((null ww) (go lab2)))
(gprinreset!>) (gprin!> " ")
(setq ![gptab!] 4)
(gprin!> "Ways of calculation:")
(gterpri!>)
(while!> ww
(gprinreset!>)
(setq ![gptab!] 6)
(gprin!> " ")
(setq wc (car ww))
(gprils!> (lowertxt!>(car wc)))
(setq wc (cdr wc))
(gprin!> "(")
(while!> wc
(gprin!> (incom!> (cdr (explode2
(cond ((pairp(car wc)) (cadar wc)) (t (car wc))) ))))
(cond((pairp(car wc)) (gprin!> "*")))
(cond ((cdr wc) (gprin!> ",")))
(setq wc (cdr wc)))
(gprin!> ")")
(gterpri!>)
(setq ww (cdr ww)))
lab2
(gprinreset!>)))
(de shsy!> (w)
(cond ((numberp w) (gprin!> w))
((idp w) (gprin!> (tolc!> w)))
((idp(car w)) (prog2 (shsy!>(car w)) (shsy!>(cdr w))))
(t(proc nil
(gprin!> "(")
(while!> w
(shsy!> (car w))
(cond((cdr w) (gprin!> ",")))
(setq w (cdr w)))
(gprin!> ")") ))))
(de allways!> (ww)
(proc (wr w)
(while!> ww
(cond((not(eval(cadar ww))) (setq wr (cons (car ww) wr))))
(setq ww (cdr ww)))
(setq ww nil)
(while!> wr
(setq w (needdata!>(cdddar wr)))
(setq w
(cons (cond((null(caar wr)) '( "Standard way" )) (t(caar wr))) w))
(setq ww (cons w ww))
(setq wr (cdr wr)))
(return ww)))
(de needdata!> (w)
(cond ((null w) nil)
((atom (car w)) (cons (car w) (needdata!> (cdr w))))
((eq (caar w) t) (cons (car w) (needdata!> (cdr w))))
((eval (caar w)) (append (cdar w) (needdata!> (cdr w))))
(t (needdata!> (cdr w)))))
%----- Time; and GC Time; commands ---------------------------------------
(de timei!> nil
(prog (wt wgt)
(setq wt (difference (time) ![time!]))
(setq wgt (difference (gctime) ![gctime!]))
(cond ((iscsl!>) (setq wt (plus wt wgt))))
(cond ((not(eqn wt 0)) (setq wgt (quotient (times 100 wgt) wt)))
(t (setq wgt 0)))
(prin2 "Time: ")
(prtime!> wt)
(cond ((zerop wt) (prog2 (terpri) (return nil))))
(prin2 " (")
(prin2 wgt)
(prin2 "%GC)")
(terpri)))
(de gptime!> nil
(prog (wt wgt)
(setq wt (difference (time) ![time!]))
(cond ((iscsl!>) (setq wgt (difference (gctime) ![gctime!]))
(setq wt (plus wt wgt))))
(gprtime!> wt)
(gterpri!>)))
(de gctime!> nil
(progn (prin2 "Garbage collections time: ")
(prtime!> (difference (gctime) ![gctime!])) (terpri)))
(de prtime!> (w)
(prog (wa wb)
(setq wb (quotient (remainder w 1000) 10))
(setq wa (quotient w 1000))
(prin2 wa)(prin2 ".")
(cond((lessp wb 10)(prin2 "0")))
(prin2 wb)
(prin2 " sec")))
(de gprtime!> (w)
(prog (wa wb wt)
(setq wb (quotient (remainder w 1000) 10))
(setq wa (quotient w 1000))
% (gprin!> wa)(gprin!> ".")
% (cond((lessp wb 10)(gprin!> "0")))
% (gprin!> wb)
% (gprin!> " sec")
(setq wt '(! !s !e !c !"))
(setq wt (append (explode2 wb) wt))
(cond((lessp wb 10) (setq wt (cons '!0 wt))))
(setq wt (cons '!. wt))
(setq wt (append (explode2 wa) wt))
(setq wt (cons '!" wt))
(gprin!>(compress wt))
))
%----- Find/Calculate ; command ------------------------------------------
(de find!> (lst)
(proc (w wa wss)
(cond ((null lst) (return nil)))
(setq w (byfrom!> lst))
(cond ((eq w !!er!!) (return !!er!!)))
(setq wss w)