-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfun.src
More file actions
3837 lines (3508 loc) · 98.7 KB
/
fun.src
File metadata and controls
3837 lines (3508 loc) · 98.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 20aug25 Software Lab. Alexander Burger
# Ersatz PicoLisp Functions
############ main ############
# (env ['lst] | ['sym 'val] ..) -> lst
env (i x y)
y = Nil;
if (!((ex = ex.Cdr) instanceof Cell)) {
for (Bind p = Env.Bind; p != null; p = p.Link) {
for (i = p.Cnt; --i > 0; --i) {
for (x = y; ; x = x.Cdr) {
if (!(x instanceof Cell)) {
y = new Cell(new Cell(p.Data[i], p.Data[i].Car), y);
break;
}
if (x.Car.Car == p.Data[i])
break;
}
}
}
}
else {
do {
if ((x = ex.Car.eval()) instanceof Cell) {
do
y = new Cell(x.Car instanceof Cell? new Cell(x.Car.Car, x.Car.Cdr) : new Cell(x.Car, x.Car.Car), y);
while ((x = x.Cdr) instanceof Cell);
}
else if (x != Nil) {
ex = ex.Cdr;
y = new Cell(new Cell(x, ex.Car.eval()), y);
}
}
while ((ex = ex.Cdr) instanceof Cell);
}
return y;
# (up [cnt] sym ['val]) -> any
up (i j k x)
if (!((x = (ex = ex.Cdr).Car) instanceof Number))
k = 1;
else {
k = ((Number)x).Cnt;
ex = ex.Cdr;
x = ex.Car;
}
j = 0;
Bind q = null;
if (x == Nil) {
for (Bind p = Env.Bind; p != null; p = p.Link)
if (p.Exe != null && --k <= 0)
return p.Exe;
return Nil;
}
for (Bind p = Env.Bind; p != null; p = p.Link) {
for (i = 0; i < p.Cnt; i += 2) {
if (p.Data[i+1] == x) {
if (--k == 0) {
if ((ex = ex.Cdr) instanceof Cell)
return p.Data[i] = ex.Car.eval();
return p.Data[i];
}
q = p;
}
}
}
if ((ex = ex.Cdr) instanceof Cell)
if (q == null)
x.Car = ex.Car.eval();
else
q.Data[j] = ex.Car.eval();
return q == null? x.Car : q.Data[j];
# (sys 'any) -> sym
sys ()
return mkStr(System.getenv(evString(ex.Cdr)));
# (quit ['any ['any]])
quit (str)
str = evString(ex = ex.Cdr);
return err(null, (ex = ex.Cdr) instanceof Cell? ex.Car.eval() : null, str);
# (java 'cls 'T ['any ..]) -> obj
# (java 'cls 'msg ['any ..]) -> obj
# (java 'obj 'msg ['any ..]) -> obj
# (java 'obj ['cnt]) -> any
java (num i j k x y z s v o)
y = (x = ex.Cdr).Car.eval();
if ((z = (x = x.Cdr).Car.eval()) == Nil || z instanceof Number) {
if ((s = (Symbol)y).Obj instanceof Boolean)
return ((Boolean)s.Obj).booleanValue()? T : Nil;
if (s.Obj instanceof Byte)
return new Number(((Byte)s.Obj).byteValue());
if (s.Obj instanceof Character)
return new Number(((Character)s.Obj).charValue());
if (s.Obj instanceof Integer)
return new Number(((Integer)s.Obj).intValue());
if (s.Obj instanceof Long)
return new Number(((Long)s.Obj).longValue());
if (s.Obj instanceof Float)
return strToNum(Float.toString(((Float)s.Obj).floatValue()), xInt(z));
if (s.Obj instanceof Double)
return strToNum(Double.toString(((Double)s.Obj).doubleValue()), xInt(z));
if (s.Obj instanceof BigInteger)
return new Number((BigInteger)s.Obj);
if (s.Obj instanceof String)
return mkStr((String)s.Obj);
x = Nil;
if (s.Obj instanceof byte[]) {
byte[] a = (byte[])s.Obj;
for (i = a.length; --i >= 0;)
x = new Cell(new Number(a[i]), x);
}
else if (s.Obj instanceof char[]) {
char[] a = (char[])s.Obj;
for (i = a.length; --i >= 0;)
x = new Cell(new Number(a[i]), x);
}
else if (s.Obj instanceof int[]) {
int[] a = (int[])s.Obj;
for (i = a.length; --i >= 0;)
x = new Cell(new Number(a[i]), x);
}
else if (s.Obj instanceof long[]) {
long[] a = (long[])s.Obj;
for (i = a.length; --i >= 0;)
x = new Cell(new Number(a[i]), x);
}
else if (s.Obj instanceof float[]) {
float[] a = (float[])s.Obj;
j = xInt(z);
for (i = a.length; --i >= 0;)
x = new Cell(strToNum(Float.toString(a[i]), i), x);
}
else if (s.Obj instanceof double[]) {
double[] a = (double[])s.Obj;
j = xInt(z);
for (i = a.length; --i >= 0;)
x = new Cell(strToNum(Double.toString(a[i]), i), x);
}
return x;
}
for (v = new Any[6], i = 0; (x = x.Cdr) instanceof Cell;)
v = append(v, i++, x.Car.eval());
Object[] arg = new Object[i];
Class[] par = new Class[i];
while (--i >= 0) {
if (v[i] == Nil || v[i] == T) {
arg[i] = v[i] == T;
par[i] = Boolean.TYPE;
}
else if (v[i] instanceof Number) {
if ((num = (Number)v[i]).Big != null)
cntError(ex, num);
arg[i] = Integer.valueOf(num.Cnt);
par[i] = Integer.TYPE;
}
else if (v[i] instanceof Cell) {
k = (int)v[i].length();
if (v[i].Car instanceof Number) {
arg[i] = new int[k];
for (j = 0; j < k; ++j, v[i] = v[i].Cdr)
Array.setInt(arg[i], j, ((Number)v[i].Car).Cnt);
}
else if (v[i].Car instanceof Cell)
argError(ex, v[i]);
else if ((s = (Symbol)v[i].Car).Obj == null) {
arg[i] = Array.newInstance(s.Name.getClass(), k);
for (j = 0; j < k; ++j, v[i] = v[i].Cdr)
Array.set(arg[i], j, ((Symbol)v[i].Car).Name);
}
else {
if (s.Obj instanceof Byte)
arg[i] = Array.newInstance(Byte.TYPE, k);
else if (s.Obj instanceof Character)
arg[i] = Array.newInstance(Character.TYPE, k);
else if (s.Obj instanceof Integer)
arg[i] = Array.newInstance(Integer.TYPE, k);
else if (s.Obj instanceof Long)
arg[i] = Array.newInstance(Long.TYPE, k);
else if (s.Obj instanceof Float)
arg[i] = Array.newInstance(Float.TYPE, k);
else if (s.Obj instanceof Double)
arg[i] = Array.newInstance(Double.TYPE, k);
else
arg[i] = Array.newInstance(s.Obj.getClass(), k);
for (j = 0; j < k; ++j, v[i] = v[i].Cdr)
Array.set(arg[i], j, ((Symbol)v[i].Car).Obj);
}
par[i] = arg[i].getClass();
}
else if ((s = (Symbol)v[i]).Obj == null)
par[i] = (arg[i] = s.Name).getClass();
else {
arg[i] = s.Obj;
if (s.Obj instanceof Byte)
par[i] = Byte.TYPE;
else if (s.Obj instanceof Character)
par[i] = Character.TYPE;
else if (s.Obj instanceof Integer)
par[i] = Integer.TYPE;
else if (s.Obj instanceof Long)
par[i] = Long.TYPE;
else if (s.Obj instanceof Float)
par[i] = Float.TYPE;
else if (s.Obj instanceof Double)
par[i] = Double.TYPE;
else
par[i] = s.Obj.getClass();
}
}
try {
if (z == T)
return new Symbol(javaConstructor(java.lang.Class.forName(y.name()), par).newInstance(arg));
Method m = javaMethod((s = (Symbol)y).Obj == null? java.lang.Class.forName(s.Name) : s.Obj.getClass(), z.name(), par);
o = m.invoke(s.Obj, arg);
if (m.getReturnType() == Void.TYPE)
return Nil;
return o == null? Nil : new Symbol(o);
}
catch (Exception e) {return err(ex, null, e.toString());}
# (public 'obj 'any ['any ..]) -> obj
# (public 'cls 'any ['any ..]) -> obj
public (x y z s o)
y = (x = ex.Cdr).Car.eval();
z = (x = x.Cdr).Car.eval();
try {
if ((s = (Symbol)y).Obj != null)
o = s.Obj.getClass().getField(z.name()).get(s.Obj);
else {
java.lang.Class cls = java.lang.Class.forName(s.Name);
o = cls.getField(z.name()).get(cls);
}
while ((x = x.Cdr) instanceof Cell)
o = o.getClass().getField(x.Car.eval().name()).get(o);
return new Symbol(o);
}
catch (Exception e) {return err(ex, null, e.toString());}
# (interface 'cls|lst 'sym 'fun ..) -> obj
interface (i x y)
y = (x = ex.Cdr).Car.eval();
Class[] c = new Class[y instanceof Cell? (int)y.length() : 1];
try {
if (y instanceof Cell)
for (i = 0; i < c.length; ++i, y = y.Cdr)
c[i] = java.lang.Class.forName(y.Car.name());
else
c[0] = java.lang.Class.forName(y.name());
}
catch (Exception e) {err(ex, null, e.toString());}
final HashMap<String,Any> act = new HashMap<String,Any>();
while ((x = x.Cdr) instanceof Cell) {
y = x.Car.eval();
act.put(y.name(), (x = x.Cdr).Car.eval());
}
InvocationHandler h = new InvocationHandler() {
public Object invoke(Object o, Method m, Object[] arg) {
Any w;
if ((w = act.get(m.getName())) == null)
err(null, mkStr(m.getName()), "Can't invoke");
if (arg == null)
return w.apply(null, false, null, 0);
else {
Any[] v = new Any[arg.length];
v[0] = new Symbol(o);
for (int i = 0; i < arg.length; ++i)
v[i] = new Symbol(arg[i]);
return w.apply(null, false, v, v.length);
}
}
};
return new Symbol(java.lang.reflect.Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), c, h));
# (byte: 'num|sym) -> obj
byte: (x)
x = ex.Cdr.Car.eval();
return new Symbol(Byte.valueOf(x instanceof Number? (byte)((Number)x).Cnt : (byte)x.name().charAt(0)));
# (char: 'num|sym) -> obj
char: (x)
x = ex.Cdr.Car.eval();
return new Symbol(Character.valueOf(x instanceof Number? (char)((Number)x).Cnt : x.name().charAt(0)));
# (int: 'num) -> obj
int: ()
return new Symbol(Integer.valueOf(evInt(ex.Cdr)));
# (long: 'num) -> obj
long: ()
return new Symbol(Long.valueOf(evLong(ex.Cdr)));
# (float: 'str 'cnt) -> obj
# (float: 'num 'cnt) -> obj
float: (x)
if ((x = (ex = ex.Cdr).Car.eval()) instanceof Number)
return new Symbol(Float.valueOf(((Number)x).toString(evInt(ex.Cdr), '.', '\0')));
return new Symbol(Float.valueOf(x.name()));
# (double: 'str 'cnt) -> obj
# (double: 'num 'cnt) -> obj
double: (x)
if ((x = (ex = ex.Cdr).Car.eval()) instanceof Number)
return new Symbol(Double.valueOf(((Number)x).toString(evInt(ex.Cdr), '.', '\0')));
return new Symbol(Double.valueOf(x.name()));
# (big: 'num) -> obj
big: (num)
num = (Number)(ex.Cdr.Car.eval());
return new Symbol(num.Big == null? big(num.Cnt) : num.Big);
# (args) -> flg
args T
return Env.Next < Env.ArgC? T : Nil;
# (next) -> any
next ()
return Env.Next < Env.ArgC? (Env.Arg = Env.Args[Env.Next++]) : Nil;
# (arg ['cnt]) -> any
arg (i)
if (ex.Cdr instanceof Cell)
return (i = evInt(ex.Cdr)+Env.Next-1) >= 0 && i < Env.ArgC? Env.Args[i] : Nil;
return Env.Arg;
# (rest) -> lst
rest (i x)
for (x = Nil, i = Env.ArgC; --i >= Env.Next;)
x = new Cell(Env.Args[i], x);
return x;
# (date ['T]) -> dat
# (date 'dat) -> (y m d)
# (date 'y 'm 'd) -> dat | NIL
# (date '(y m d)) -> dat | NIL
date (i j x z)
if (!((x = ex.Cdr) instanceof Cell)) {
Cal = new GregorianCalendar();
return date(Cal.get(Calendar.YEAR), Cal.get(Calendar.MONTH)+1, Cal.get(Calendar.DATE));
}
if ((z = x.Car.eval()) == T) {
Cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
return date(Cal.get(Calendar.YEAR), Cal.get(Calendar.MONTH)+1, Cal.get(Calendar.DATE));
}
if (z == Nil)
return Nil;
if (z instanceof Cell)
return date(xInt(z.Car), xInt(z.Cdr.Car), xInt(z.Cdr.Cdr.Car));
if ((i = xInt(z)) < 0)
return Nil;
if (!((x = x.Cdr) instanceof Cell))
return date(i);
j = evInt(x);
return date(i, j, evInt(x.Cdr));
# (time ['T]) -> tim
# (time 'tim) -> (h m s)
# (time 'h 'm ['s]) -> tim | NIL
# (time '(h m [s])) -> tim | NIL
time (i j x z)
if (!((x = ex.Cdr) instanceof Cell))
return time(new GregorianCalendar());
if ((z = x.Car.eval()) == T)
return time(Cal);
if (z == Nil)
return Nil;
if (z instanceof Cell)
return time(xInt(z.Car), xInt(z.Cdr.Car), z.Cdr.Cdr instanceof Cell? xInt(z.Cdr.Cdr.Car) : 0);
if ((i = xInt(z)) < 0)
return Nil;
if (!((x = x.Cdr) instanceof Cell))
return new Cell(new Number(i / 3600), new Cell(new Number(i / 60 % 60), new Cell(new Number(i % 60), Nil)));
j = evInt(x);
return time(i, j, x.Cdr instanceof Cell? evInt(x.Cdr) : 0);
# (usec ['flg]) -> num
usec ()
return new Number(ex.Cdr.Car.eval() == Nil?
System.nanoTime()/1000 - USec :
Cal.get(Calendar.MILLISECOND) * 1000 );
# (pwd) -> sym
pwd T
return mkStr(System.getProperty("user.dir"));
# (info 'any) -> (cnt|flg dat . tim)
info ()
File f = new File(path(evString(ex.Cdr)));
if (!f.exists())
return Nil;
Calendar c = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
c.setTimeInMillis(f.lastModified());
return
new Cell(
f.isDirectory()? T : !f.isFile()? Nil : new Number(f.length()),
new Cell(
date(c.get(Calendar.YEAR), c.get(Calendar.MONTH)+1, c.get(Calendar.DATE)),
time(c) ) );
# (file) -> (sym1 sym2 . num) | NIL
file (i x)
if (InFile.Name == null)
return Nil;
x = new Number(InFile.Src);
if ((i = InFile.Name.lastIndexOf('/')) >= 0)
return new Cell(mkStr(InFile.Name.substring(0, i+1)), new Cell(mkStr(InFile.Name.substring(i+1)), x));
return new Cell(Nil, new Cell(mkStr(InFile.Name), x));
# (dir ['any] ['flg]) -> lst
dir (i x y str)
String[] lst = new File((str = evString(x = ex.Cdr)).length() == 0? "." : path(str)).list();
x = x.Cdr.Car.eval();
if (lst == null)
return Nil;
for (y = Nil, i = lst.length; --i >= 0;)
if (x != Nil || lst[i].charAt(0) != '.')
y = new Cell(mkStr(lst[i]), y);
return y;
# (argv [var ..] [. sym]) -> lst|sym
argv (i j x y)
i = Argv.length > 0 && Argv[0].equals("-")? 1 : 0;
if ((x = ex.Cdr) == Nil) {
if (i == Argv.length)
return Nil;
for (j = Argv.length; --j >= i;)
x = new Cell(mkStr(Argv[j]), x);
return x;
}
do {
if (!(x instanceof Cell)) {
if (i == Argv.length)
return x.Car = Nil;
for (y = Nil, j = Argv.length; --j >= i;)
y = new Cell(mkStr(Argv[j]), y);
return x.Car = y;
}
(y = x.Car).Car = i == Argv.length? Nil : mkStr(Argv[i++]);
} while ((x = x.Cdr) != Nil);
return y.Car;
# (opt) -> sym
opt (str)
return (str = opt()) == null? Nil : mkStr(str);
# (version ['flg]) -> lst
version (i x)
if (ex.Cdr.Car.eval() == Nil) {
for (i = 0; i < 3; ++i)
OutFile.Wr.print(Version[i] + (i == 2? " " : "."));
OutFile.Wr.println("JVM");
OutFile.Wr.flush();
}
for (x = Nil, i = 3; --i >= 0;)
x = new Cell(new Number(Version[i]), x);
return x;
############ gc ############
# (gc) -> NIL
gc T
At.Car = At2.Car = Nil;
System.gc();
return Nil;
############ apply ############
# (apply 'fun 'lst ['any ..]) -> any
apply (i w x y v)
w = (x = ex.Cdr).Car.eval();
y = (x = x.Cdr).Car.eval();
for (v = new Any[6], i = 0; (x = x.Cdr) instanceof Cell;)
v = append(v, i++, x.Car.eval());
while (y instanceof Cell) {
v = append(v, i++, y.Car);
y = y.Cdr;
}
return w.apply(ex, false, v, i);
# (pass 'fun ['any ..]) -> any
pass (i j w x v)
w = (x = ex.Cdr).Car.eval();
for (v = new Any[6], i = 0; (x = x.Cdr) instanceof Cell;)
v = append(v, i++, x.Car.eval());
for (j = Env.Next; j < Env.ArgC; ++j)
v = append(v, i++, Env.Args[j]);
return w.apply(ex, false, v, i);
# (maps 'fun 'sym ['lst ..]) -> any
maps (i j k w x y s v)
w = (x = ex.Cdr).Car.eval();
if ((y = (x = x.Cdr).Car.eval()) == Nil || (s = (Symbol)y).Prop == null)
return Nil;
v = new Any[6];
i = 1;
append(v, 0, null);
while ((x = x.Cdr) instanceof Cell)
v = append(v, i++, x.Car.eval());
k = s.Prop.length;
do
if ((x = s.Prop[--k]) != null) {
v[0] = new Cell(x,Nil);
x = w.apply(ex, true, v, i);
for (j = i; --j > 0;)
v[j] = v[j].Cdr;
}
while (k != 0);
return x;
# (map 'fun 'lst ..) -> lst
map (i j w x v)
w = (x = ex.Cdr).Car.eval();
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
x = w.apply(ex, false, v, i);
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
return x;
# (mapc 'fun 'lst ..) -> any
mapc (i j w x v)
w = (x = ex.Cdr).Car.eval();
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
x = w.apply(ex, true, v, i);
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
return x;
# (maplist 'fun 'lst ..) -> lst
maplist (i j w x z v)
w = (x = ex.Cdr).Car.eval();
z = Nil;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
if (!(v[0] instanceof Cell))
return z;
z = x = new Cell(w.apply(ex, false, v, i), Nil);
while (v[0].Cdr instanceof Cell) {
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
x = x.Cdr = new Cell(w.apply(ex, false, v, i), Nil);
}
}
return z;
# (mapcar 'fun 'lst ..) -> lst
mapcar (i j w x z v)
w = (x = ex.Cdr).Car.eval();
z = Nil;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
if (!(v[0] instanceof Cell))
return z;
z = x = new Cell(w.apply(ex, true, v, i), Nil);
while (v[0].Cdr instanceof Cell) {
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
x = x.Cdr = new Cell(w.apply(ex, true, v, i), Nil);
}
}
return z;
# (mapcon 'fun 'lst ..) -> lst
mapcon (i j w x z v)
w = (x = ex.Cdr).Car.eval();
z = Nil;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
if (!(v[0] instanceof Cell))
return z;
while (!((x = w.apply(ex, false, v, i)) instanceof Cell)) {
if (!(v[0].Cdr instanceof Cell))
return z;
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
z = x;
while (v[0].Cdr instanceof Cell) {
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
while (x.Cdr instanceof Cell)
x = x.Cdr;
x.Cdr = w.apply(ex, false, v, i);
}
}
return z;
# (mapcan 'fun 'lst ..) -> lst
mapcan (i j w x z v)
w = (x = ex.Cdr).Car.eval();
z = Nil;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
if (!(v[0] instanceof Cell))
return z;
while (!((x = w.apply(ex, true, v, i)) instanceof Cell)) {
if (!(v[0].Cdr instanceof Cell))
return z;
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
z = x;
while (v[0].Cdr instanceof Cell) {
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
while (x.Cdr instanceof Cell)
x = x.Cdr;
x.Cdr = w.apply(ex, true, v, i);
}
}
return z;
# (filter 'fun 'lst ..) -> lst
filter (i j w x z v)
w = (x = ex.Cdr).Car.eval();
z = Nil;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
if (!(v[0] instanceof Cell))
return z;
while (w.apply(ex, true, v, i) == Nil) {
if (!(v[0].Cdr instanceof Cell))
return z;
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
z = x = new Cell(v[0].Car, Nil);
while (v[0].Cdr instanceof Cell) {
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
if (w.apply(ex, true, v, i) != Nil)
x = x.Cdr = new Cell(v[0].Car, Nil);
}
}
return z;
# (extract 'fun 'lst ..) -> lst
extract (i j w x y z v)
w = (x = ex.Cdr).Car.eval();
z = Nil;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
if (!(v[0] instanceof Cell))
return z;
while ((y = w.apply(ex, true, v, i)) == Nil) {
if (!(v[0].Cdr instanceof Cell))
return z;
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
z = x = new Cell(y, Nil);
while (v[0].Cdr instanceof Cell) {
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
if ((y = w.apply(ex, true, v, i)) != Nil)
x = x.Cdr = new Cell(y, Nil);
}
}
return z;
# (seek 'fun 'lst ..) -> lst
seek (i j w x v)
w = (x = ex.Cdr).Car.eval();
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
if ((x = w.apply(ex, false, v, i)) != Nil) {
At2.Car = x;
return v[0];
}
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
return Nil;
# (find 'fun 'lst ..) -> any
find (i j w x v)
w = (x = ex.Cdr).Car.eval();
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
if ((x = w.apply(ex, true, v, i)) != Nil) {
At2.Car = x;
return v[0].Car;
}
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
return Nil;
# (pick 'fun 'lst ..) -> any
pick (i j w x v)
w = (x = ex.Cdr).Car.eval();
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
if ((x = w.apply(ex, true, v, i)) != Nil)
return x;
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
return Nil;
# (fully 'fun 'lst ..) -> flg
fully (i j w x v)
w = (x = ex.Cdr).Car.eval();
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
if (w.apply(ex, true, v, i) == Nil)
return Nil;
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
return T;
# (cnt 'fun 'lst ..) -> cnt
cnt (i j n w x v)
w = (x = ex.Cdr).Car.eval();
n = 0;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
if (w.apply(ex, true, v, i) != Nil)
++n;
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
return new Number(n);
# (sum 'fun 'lst ..) -> num
sum (num i j w x y v)
w = (x = ex.Cdr).Car.eval();
num = Zero;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
if ((y = w.apply(ex, true, v, i)) instanceof Number)
num = num.add((Number)y);
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
return num;
# (maxi 'fun 'lst ..) -> any
maxi (i j w x y z v)
w = (x = ex.Cdr).Car.eval();
y = z = Nil;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
if ((x = w.apply(ex, true, v, i)).compare(y) > 0) {
z = v[0].Car;
y = x;
}
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
At2.Car = y;
return z;
# (mini 'fun 'lst ..) -> any
mini (i j w x y z v)
w = (x = ex.Cdr).Car.eval();
y = T;
z = Nil;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
while (v[0] instanceof Cell) {
if ((x = w.apply(ex, true, v, i)).compare(y) < 0) {
z = v[0].Car;
y = x;
}
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
}
}
At2.Car = y;
return z;
# (fish 'fun 'any) -> lst
fish (w v)
w = ex.Cdr.Car.eval();
(v = new Any[1])[0] = ex.Cdr.Cdr.Car.eval();
return fish(ex, w, v, Nil);
# (by 'fun1 'fun2 'lst ..) -> lst
by (i j w x y z v)
w = (x = ex.Cdr).Car.eval();
y = (x = x.Cdr).Car.eval();
z = Nil;
if ((x = x.Cdr) instanceof Cell) {
v = new Any[6];
i = 0;
do
v = append(v, i++, x.Car.eval());
while ((x = x.Cdr) instanceof Cell);
z = x = new Cell(new Cell(w.apply(ex, true, v, i), v[0].Car), Nil);
while (v[0].Cdr instanceof Cell) {
for (j = i; --j >= 0;)
v[j] = v[j].Cdr;
x = x.Cdr = new Cell(new Cell(w.apply(ex, true, v, i), v[0].Car), Nil);
}
v[0] = z;
z = y.apply(ex, false, v, 1);
for (x = z; x instanceof Cell; x = x.Cdr)
x.Car = x.Car.Cdr;
}
return z;
############ flow ############
# (as 'any1 . any2) -> any2 | NIL
as ()
return ex.Cdr.Car.eval() == Nil? Nil : ex.Cdr.Cdr;
# (lit 'any) -> any
lit (x)
return (x = ex.Cdr.Car.eval()) instanceof Number || x == Nil || x == T || x instanceof Cell && x.Car instanceof Number? x : new Cell(Quote, x);
# (eval 'any ['cnt]) -> any
eval (y)
if ((y = (ex = ex.Cdr).Car.eval()) instanceof Number)
return y;
if (ex.Cdr == Nil || Env.Bind == null)
return y.eval();
return evRun(true, y, evInt(ex.Cdr));
# (run 'any ['cnt]) -> any
run (y)
if ((y = (ex = ex.Cdr).Car.eval()) instanceof Number)
return y;
if (ex.Cdr == Nil || Env.Bind == null)
return y.run();
return evRun(false, y, evInt(ex.Cdr));
# (def 'sym 'any) -> sym
# (def 'sym 'sym 'any) -> sym
def (w x y s)
s = (Symbol)(ex = ex.Cdr).Car.eval();
x = (ex = ex.Cdr).Car.eval();
if (ex.Cdr == Nil) {
if (s.Car != Nil && s.Car != s && !x.equal(s.Car))
redefMsg(s, null);
s.Car = x;
putSrc(s, null);
}
else {
y = ex.Cdr.Car.eval();
if ((w = s.get(x)) != Nil && !x.equal(w))
redefMsg(s,x);
s.put(x,y);
putSrc(s,x);
}
return s;
# (de sym . any) -> sym
de ()
ex = ex.Cdr;
redefine((Symbol)ex.Car, ex.Cdr);
return ex.Car;
# (dm sym . fun|cls2) -> sym
# (dm (sym . cls) . fun|cls2) -> sym
# (dm (sym sym2 [. cls]) . fun|cls2) -> sym
dm (x y s t)
if (!((x = ex.Cdr).Car instanceof Cell)) {
s = (Symbol)x.Car;
t = (Symbol)Class.Car;
}
else {
s = (Symbol)x.Car.Car;
t = (Symbol)
(!((y = x.Car).Cdr instanceof Cell)?
y.Cdr :
(y.Cdr.Cdr == Nil? Class.Car : y.Cdr.Cdr).get(y.Cdr.Car) );
}
if (s != T)
redefine(s, Meth.Car);
if (x.Cdr instanceof Symbol) {
y = x.Cdr.Car;
for (;;) {
if (!(y instanceof Cell) || !(y.Car instanceof Cell))
err(ex, s, "Bad message");
if (y.Car.Car == s) {
x = y.Car;
break;
}
y = y.Cdr;
}
}
for (y = t.Car; y instanceof Cell && y.Car instanceof Cell; y = y.Cdr)
if (y.Car.Car == s) {
if (!x.Cdr.equal(y.Car.Cdr))
redefMsg(s, t);
y.Car.Cdr = x.Cdr;
putSrc(t, s);
return s;
}
t.Car = x.Car instanceof Cell?
new Cell(new Cell(s, x.Cdr), t.Car) :
new Cell(x, t.Car);
putSrc(t, s);
return s;
# (box 'any) -> sym
box ()
return new Symbol(ex.Cdr.Car.eval(), null);
# (new ['typ ['any ..]]) -> obj
new (x s)
s = new Symbol((ex = ex.Cdr).Car.eval(), null);
TheKey = T; TheCls = null;
if ((x = method(s)) != null)
evMethod(s, x, ex.Cdr);
else {
while ((ex = ex.Cdr) != Nil) {
x = ex.Car.eval();
s.put(x, (ex = ex.Cdr).Car.eval());
}
}
return s;