-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtao-n.lisp
1164 lines (1006 loc) · 36.7 KB
/
tao-n.lisp
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
(tao:common-lisp)
(in-package #:tao-internal)
(define
"nambra-cons"
(expr nil)
:documentation
"形式 : nambra-cons object1 object2
object1 と object2 で構成される名前付ブラケットリストを作成し、返す。"
:example
"(nambra-cons 'head (list 'body 'tail)) -> head[body tail]")
(define
"nambra-list"
(expr nil)
:documentation
"形式 : nambra-list &rest object1 object2 ... objectN
object1 object2 ... objectN で構成される名前付ブラケットを作成し、
返す。"
:example
"(nambra-list 'head 'body 'tail) -> head[body tail]")
(define
"nambracketp"
(subr nil)
:documentation
"形式 : nambracketp object
object が名前付きブラケットリストなら、それを返し、
そうでなければ nil を返す。"
:example
"(!a (nambra-cns 'head (list 'body 'tail))) -> head[body tail]
(nambracketp a) -> head[body tail]")
(define
"namcell-cons"
(expr nil)
:documentation
"形式 : namcell-cons object1 object2
object1 と object2 で構成される名前付きセルを作成し、返す。"
:example
"(namcell-cons 'head (list 'body 'tail)) -> head(body tail)")
(define
"namcell-list"
(expr nil)
:documentation
"形式 : namcell-list &rest object1 object2 ... objectN
関数 list と同じだが、ナムセル型の識別子に用いられ、ナムセルリストが
作られる。ナムセルは名前つきセルのことで、name (element1 element2 ...)
のように書かれる。"
:example
"(namcell-list 'head 'body 'tail) -> head(body tail)")
(define
"namcellp"
(subr nil)
:documentation
"形式 : namcellp object
object がナムセルリストなら、それを返し、そうでなければ nil を返す。
ナムセルは名前つきセルのことで、name (element1 element2 ... ) のように
書かれる。"
:example
"(!a namcell-list 'this 'is 'a 'cat)) -> this(is a cat)
(namcellp a) -> this(is a cat)")
(define
"name-char"
#'name-char
:documentation
"形式 : name-char name
name が、文字型オブジェクトの名前なら name を返し、
そうでなければ、nil を返す。
char-name 参照。"
:example
"(name-char \"Backspace\") -> #\\Backspace
(name-char \"Space\") -> #\\Space
(name-char \"a\") -> nil")
(define
"named-for"
(macro (exit-id var list &body body)
(let ((exit-id/g exit-id))
`(block ,exit-id/g
(dolist (,var ,list nil)
,@body))))
:documentation
"形式 : named-for &rest exit-id var list form1 form2 ... formN
form1 form2 ... formN を順に var を使って実行する。
var は list の中の各要素に逐次束縛されたもの。
exit-id を持つ exit-for 関数により脱出できる。"
:example
"(named-for abc x (index 1 100)
(!y (+ (x ** 3) (x ** 2) x 1))
(cond ((y <= 50) (write y))
(t (exit-for 'end abc))))
-> 4
15
40
end")
(define
"namep"
(expr (object)
(and (typep object '(or symbol string))
object))
:documentation
"形式 : namep object
object がシンボルまたは文字列なら object を返し、それ以外なら
nil を返す。"
:example
"(namep 'gegege-no) -> gegege-no
(namep \"kitarou\") -> \"kitarou\"
(namep 123) -> nil")
(define
"namestring"
#'namestring
:documentation
"形式 : namestring pathname
pathname の full-pathname を返す。"
:example
"(namestring (merge-pathname \"ara.yo\"))
-> \"Ti::bs:<korasa>ara.yo\"
(namestring *default-pathname-defaults*)
-> \"Ho::bs:<dire>foo.tao\"
(namestring (make-pathname :host \"Ti\")) -> \"Ti::.\"")
(define
"nand#"
;;(locative-operator nil)
(subr nil)
:documentation
"形式 : loc1 nand# loc2
loc1 と loc2 のビット nand 操作を行う。"
:example
"")
(define
"nbutlast"
#'nbutlast
:documentation
"形式 : nbutlast list &opt number
list の終わりから number の個数 (既定値は 1) の要素を削除したリストを
返す (butlast の破壊版)。"
:example
"x = (1 2 3 4 5) とすると
(nbutlast x) -> (1 2 3 4) そして
x = (1 2 3 4) さらに
(nbutlast x 2) -> (1 2) そして
x = (1 2)")
(define
"ncadblep"
(subr nil)
:documentation
"形式 : ncadblep object
object が car 関数でも cdr 関数でもエラーにならないなら、nil を返し、
それ以外なら t を返す。
(ncadblep x) = (not (cadblep x))"
:example
"(ncadblep '(a b c)) -> nil
(ncadblep \"abc\") -> t
(ncadblep 'abc) -> t
(ncadblep nil) -> t")
(define
"nconc"
#'nconc
:documentation
"形式 : nconc &rest list1 list2 ... listN
list1 list2 ... listN をこの順序で、しかもコピーしないで連結する。"
:example
"(nconc (list 1 2 3) (list 'a 'b 'c 'd)) -> (1 2 3 a b c d)
x = (h e a d) y = (a n d) z = (t a i l) なら
(nconc x y z) -> (h e a d a n d t a i l)
そして x = (h e a d a n d t a i l) y = (a n d t a i l)
z = (t a i l)
x = (h e a d) y = nil z = (t a i l) なら
(nconc x y z) -> (h e a d t a i l)
そして x = (h e a d t a i l) y = nil z = (t a i l)")
(define
"nconc!"
(macro (var list)
`(tao:selfass nconc !,var ,list))
:documentation
"形式 : nconc! var list
(nconc! var list) = (!var (nconc list var))
ただし左辺では var は一度だけしか評価されない。"
:example
"a = '(1 2 3) のとき
(nconc! a '(a b c)) -> (a b c 1 2 3)")
(define
"ncons"
(subr (x)
(cons x nil))
:documentation
"形式 : ncons list
car 部が、list で、cdr 部が nil である新しいコンスを作り、それを返す。
(ncons x) = (cons x nil)"
:example
"x が (a b c)ならば
(ncons x) -> ((a b c))
(ncons nil) -> (nil)")
(define
"neg"
(subr (number)
(- number))
:documentation
"形式 : neg number
number の負数を返す。"
:example
"(neg 100) -> -100
(neg -100) -> 100")
(define
"neq"
(subr (object1 object2)
(not (eq object1 object2)))
:documentation
"形式 : neq object1 object2
object1 と object2 が以下の条件を満足すれば、nil、それ以外なら t を返す。
(1) 両方とも nil
(2) 等値の小整数 (shortnum)
(3) 同一のシンボル
(4) 同じコード化整数 (codnum)
(5) 同じ文字 (a character string)
(6) 等値の shortfloat (24 ビットで示された浮動小数点数)
2 つの引数のアドレスがメモリー上の同位置にあるときに、nil を返す。
(neq object1 object2) = (not (eq object1 object2))"
:example
"(neq nil nil) -> nil
(neq -345678 -345678) -> nil
(neq #12 #12) -> nil
(neq 12345678 12345678) -> t
(neq 'abc 'cba) -> t
(neq \"a\" \"b\") -> t
(neq \"a\" \"A\") -> t
(neq '(1 2) '(1 2)) -> t
(neq \"abc\" \"abc\") -> t")
(define
"nidp"
(subr (identifier)
(typep identifier '(not symbol)))
:documentation
"形式 : nidp identifier
identifier が識別子なら、nil を返し、それ以外なら t を返す。
(nidp identifier) = (not (idp identifier))"
:example
"(nidp 'asdf) -> nil
(nidp 3) -> t
(nidp '_x) -> t
(nidp #!expr) -> t")
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(define
"nil"
(constant nil)
:documentation
"\"偽\" を表す。nil は、空のリスト () を意味するシンボル。
TAO では、nil は nil と呼ばれるデータを作る。"
:example
"")
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||#
(define
"nintersection"
#'nintersection
:documentation
"形式 : nintersection list1 list2 &key :test :test-not :key
list1 と list2 の共通要素を抽出し、その結果をリスト形式で返す。
共通要素がない場合は、nil を返す。
list1 は破壊されるが、list2 は破壊されない。関数 intersection の破壊版。"
:example
"(nintersection '(a b c) '(b d)) -> (b)
a = (1 2 3) b = (4) の時
(nintersection a b) -> nil")
(define
"ninth"
#'ninth
:documentation
"形式 : ninth list
list の 9 番目の要素を返す。(ninth list) = (nth 8 list)。"
:example
"(ninth '(0 1 2 3 4 5 6 7 8 9)) -> 8")
(define
"nleft"
(expr (number list1 &optional list2)
(let ((len (cl:length list1)))
(if (or (minusp number) (floatp number))
(error "~S is illegal N for NUMBER." number)
(and (tailp list2 list1)
(nthcdr (- len number) list1)))))
:documentation
"形式 : nleft number list1 &opt list2
list2 が nil または省略された場合、list1 の最後から number 個の要素から
成る尾リストを返す。list2 の既定値は nil。
この尾リストに関数 cdr を number 回適用した結果が list2 と eq でなくて
はならない。list2 が list1 のどの尾リストとも eq でない場合、nil を返す。"
:example
"x = (1 2 3 4 5 6 7 8) なら
(nleft 3 x) -> (6 7 8) であり、そして
x = (1 2 3 4 5 6 7 8)
(nleft 3 x (last x)) -> (5 6 7 8)
(nleft 3 x (nleft 2 x)) -> (4 5 6 7 8)
(nleft 3 x '(7 8)) -> nil")
(declaim (inline tao:nlistp))
(define
"nlistp"
(subr (list)
(not (listp list)))
:documentation
"形式 : nlistp list
list がリストか、car 関数と cdr 関数が両方とも適用できるものであれば、
nil を返し、それ以外なら t を返す。
list は listp 関数に適用される前に評価される。
(nlistp list) = (not (listp list))"
:example
"(nlistp '(a b c d)) -> nil
(nlistp '[a b c d]) -> nil
(nlistp 'a) -> t
(nlistp ''a) -> nil
(nlistp '^(a b `c d)) -> nil
(nlistp '(!x (fn y))) -> nil
(nlistp (caddr '(list a b))) -> t
(nlistp ()) -> nil
(nlistp '(a . b)) -> nil")
(define
"no-dumb"
(expr nil)
:documentation
"形式 : no-dumb &opt terno
ターミナル番号 terno のターミナルが dumb モードからぬける。
terno の既定値は、no-dumb が入力されたターミナル。"
:example
"")
(define
"no-local-echo"
(expr nil)
:documentation
"形式 : no-local-echo &opt terno
ターミナル番号 terno のターミナルが local-echo モードからぬける。
terno の既定値は、no-local-echo が入力されたターミナル。"
:example
"")
(define
"no-more"
(expr nil)
:documentation
"形式 : no-more &opt terno
ターミナル番号 terno のターミナルが more モードからぬける。
terno の既定値は、no-more が入力されたターミナル。"
:example
"")
(define
"no-screen"
(expr nil)
:documentation
"形式 : no-screen &opt terno
ターミナル番号 terno のターミナルが screen モードからぬける。
terno の既定値は、no-screen が入力されたターミナル。"
:example
"")
(define
"no-wrap"
(expr nil)
:documentation
"形式 : no-wrap &opt terno
ターミナル番号 terno のターミナルが wrap モードからぬける。
terno の既定値は、no-wrap が入力されたターミナル。"
:example
"")
(define
"nor#"
;;(locative-operator nil)
(subr nil)
:documentation
"形式 : loc1 nor# loc2
loc1 と loc2 のビット nor 操作を行う。"
:example
"")
(define
"normal-stream-p"
(expr nil)
:documentation
"形式 : normal-stream-p stream
stream が normal-stream ならば stream を返し、そうでなければ nil を返す。"
:example
"(!aa (open \"asd.tao\")) -> {udo}71499file-stream
(normal-stream-p aa) -> {udo}71499file-stream")
(define
"not"
#'not
:documentation
"形式 : not object
object の値を評価し、nil なら t を返し、それ以外なら nil を返す。
(not object) = (null object)"
:example
"(not (eq 'a 'b)) -> t ( not (eq 'a 'b)) = (null (eq 'a 'b))
(not (eq 'a 'a)) -> nil ( not (eq 'a 'a)) = (null (eq 'a 'a))")
(define
"notany"
#'notany
:documentation
"形式 : notany pred seq1 &rest seq2 seq3 ... seqN
条件 pred をシーケンス seq1 seq2 ... seqN の各要素に順番に適用し、nil
以外の値になった場合には、nil を返し、最後まで nil であった場合には、t
を返す。"
:example
"(notany #'oddp '(1 2 3)) -> nil
(notany #'evenp '(1 3 5)) -> t")
(define
"notevery"
#'notevery
:documentation
"形式 : notevery pred seq1 &rest seq2 seq3 ... seqN
条件 pred をシーケンス seq1 seq2 ... seqN の各要素に順番に適用し、nil
になった場合には、t を返し、最後まで nil にならなかった場合には nil を
返す。"
:example
"(notevery #'oddp '(1 3 5)) -> nil
(notevery #'evenp '(1 2 3)) -> t")
(define
"nreconc"
#'nreconc
:documentation
"形式 : nreconc list1 list2
list の要素の並び順を逆転させたリストと、list2 をこの順序で、
しかもコピーしないで連結 (append) する。
(nreconc list1 list2) は (nconc (nreverse list1) list2) と等しいが、
より効率的。list1 は破壊される。revappend の破壊版。"
:example
"(nreconc (list 3 2 1) (list 4 5 6 7)) -> (1 2 3 4 5 6 7)")
(define
"common:nreverse"
#'nreverse
:documentation
"形式 : common:nreverse seq
シーケンス seq の要素を逆順に並びかえ、その結果を返す。
seq は破壊される。common:reverse の破壊版。
seq は、TAO ではリストでなければならないが、リストでなかったら nil 。
Common Lisp では、列でもよい。"
:example
"(!x '(a b c d)) -> (a b c d)
(!y (common:nreverse x)) -> (d c b a)
y -> (d c b a)
x -> (a)")
(define
"nreverse"
(subr (list)
(declare (optimize (speed 3) (safety 0) (debug 0)))
(typecase list
(list (cl:nreverse list))
(otherwise nil)))
:documentation
"形式 : nreverse list
list の要素の並び順を逆転させたリストを返す。
list は破壊される。reverse の破壊版。"
:example
"x = (1 2 3) なら
(nreverse x) -> (3 2 1)
そして x は '(1) となる")
(define
"nset-difference"
#'nset-difference
:documentation
"形式 : nset-difference list1 list2 &key :test :test-not :key
list1 には存在するが list2 には含まれていない要素を抽出し、
抽出した要素で構成するリストを返す。list1 は破壊される。
set-difference の破壊版。"
:example
"(nset-difference '(1 2 3) '(2 3 4) -> (1)
(nset-difference '(1 2 3) '(1 2 3) -> nil")
(define
"nset-exclusive-or"
#'nset-exclusive-or
:documentation
"形式 : nset-exclusive-or list1 list2 &key :test :test-not :key
list1 か list2 かのいずれか一方に含まれている要素を抽出し、
抽出した要素で構成するリストを返す。
list1 list2 は共に破壊される。set-exclusive-or の破壊版。"
:example
"(nset-exclusive-or '(1 2 3) '(2 4)) -> (1 3 4)
(ndet-exclusive-or '(1 2 3) '(1 2 3) -> nil")
(define
"nstring-capitalize"
(subr (string &optional (start 0) end)
(nstring-capitalize string :start start :end end))
:documentation
"形式 : nstring-capitalize string &opt start end
string の start と end の範囲内の文字列の文頭を大文字に変換し、その他の
文字を小文字に変換し、変換した結果を返す。
start end の既定値は、それぞれ 0 、string の長さ。
string-capitalize の破壊版。"
:example
"(nstring-capitalize \"abcde\" 0 2) -> \"Abcde\"
(nstring-capitalize \"i loVE FLOWERS.\" 0 6)
-> \"I Love FLOWERS.\"")
(define
"common:nstring-capitalize"
#'nstring-capitalize
:documentation
"形式>: ommon:nstring-capitalize string &key :start :end
string の :start と :end の範囲内の文字列の文頭を大文字に変換し、その他
の文字を小文字に変換し、変換した結果を返す。
:start :end の既定値は、それぞれ 0 、string の長さ。
common:string-capitalize の破壊版。"
:example
"(common:nstring-capitalize \"abcdef\") -> \"Abcdef\"
(common:nstring-capitalize \"i loVE FLOWERS.\")
-> \"I Love Flowers.\"")
(define
"nstring-downcase"
(subr (string &optional (start 0) end)
(nstring-downcase string :start start :end end))
:documentation
"形式 : nstring-downcase string &opt start end
string の start と end の範囲内の大文字をすべて、対応する小文字に変換し、
その結果を返す。string は破壊される。string-downcase の破壊版。
start end の既定値は、それぞれ 0 、string の長さ。"
:example
"(nstring-downcase \"ABCDE\") -> \"abcde\"
(nstring-downcase \"ABCDERD\" 2 4) -> \"ABcdERD\"
(nstring-downcase \"AAAAAAA\" 0 2) -> \"aaAAAAA\"
(nstring-downcase \"漢字\") -> \"漢字\"")
(define
"common:nstring-downcase"
#'nstring-downcase
:documentation
"形式 : common:nstring-downcase string &key :start :end
string の :start と :end の範囲内の大文字をすべて、対応する小文字に変換
し、その結果を返す。string は破壊される。
:start :end の既定値は、それぞれ 0 、string の長さ。
common:string-downcase の破壊版。"
:example
"(common:nstring-downcase \"ABC\") -> \"abc\"
(common:nstring-downcase \"abc\") -> \"abc\"
(common:nstring-downcase \"あいう\") -> \"あいう\"
(common:nstring-downcase \"ABCDERGBD\" :start 1 :end 3)
-> \"AbcDERGBD\"")
(define
"nstring-fill"
(subr (string character &optional (start 0) end)
(fill string character :start start :end end))
:documentation
"形式 : nstring-fill string character &opt start end
string の start と end の範囲内のすべて文字を、character に変更し、
その結果を返す。
start end の既定値は、それぞれ 0 、string の長さ。
string-fill の破壊版。"
:example
"(nstring-fill \"abcdefghij\" \"x\" 2 4) -> \"abxxefghij\"
(nstring-fill \"abcdefghij\" \"x\") -> \"xxxxxxxxxx\"
(nstring-fill \"abcdefghij\" \"xyz\" 2 4) ->エラー
(nstring-fill \"abcdefghij\" 'x 4 2) -> \"abcdefghij\"
(nstring-fill \"abcdefghij\" 'x 12 14) -> \"abcdefghij\"")
(define
"common:nstring-fill"
#'fill
:documentation
"形式 : common:nstring-fill string character &key :start :end
string の :start と :end の範囲内のすべての文字を、character に変更し、
その結果を返す。
:start :end の既定値は、それぞれ 0 、string の長さ。
common:string-fill の破壊版。"
:example
"(common:nstring-fill \"abcdefg\" 'z :start 2 :end 5)
-> \"abzzzfg\"
(common:nstring-fill \"abcdefg\" 'k ) -> \"kkkkkkk\"
(common:nstring-fill \"あいうえお\" 'か :start 1 :end 3)
-> \"あかかえお\"")
(define
"nstring-left-trim"
(subr (string1 string2)
(string-left-trim string1 string2))
:documentation
"形式 : nstring-left-trim string1 string2
string2 の文字列を左から右へ調べて行き、string1 の中のいずれかの文字
と等しい文字を捜す。等しい文字があれば、その文字を string2 から抜き取り、
さらに検索を進める。なければそこで検索を終える。そして、抜き取られ短く
なった文字列を返す。string-left-trim の破壊版。"
:example
"(!p \"acbcaxyabcpqbcaba\") -> \"acbcaxyabcpqbcaba\"
(nstring-left-trim \"abc\" p) -> \"xyabcpqbcaba\"
p -> \"acbcaxyabcpqbcaba\"")
(define
"common:nstring-left-trim"
#'string-left-trim
:documentation
"形式 : common:nstring-left-trim char-bag string
string の文字列を左から右へ調べて行き、char-bag の中のいずれかの文字と
等しい文字を捜す。等しい文字があれば、その文字を string から抜き取り、
さらに検索を進める。なければそこで検索を終える。そして、抜き取られ短く
なった文字列を返す。 char-bag はストリング、文字のリスト、アトムの
リストのどれかでよい。"
:example
"(!p \"acbcaxyabcpqbcaba\") -> \"acbcaxyabcpqbcaba\"
(common:nstring-left-trim \"abc\" p) -> \"xyabcpqbcaba\"
p -> \"acbcaxyabcpqbcaba\"
(common:nstring-left-trim \"あか\" \"かさがあかい\")
-> \"さがあかい\"")
(define
"nstring-right-trim"
(subr (string1 string2)
(string-right-trim string1 string2))
:documentation
"形式 : nstring-right-trim string1 string2
string2 の文字列を右から左へ調べて行き、string1 の中のいずれかの文字
と等しい文字を捜す。等しい文字があれば、その文字を string2 から抜き取り、
さらに検索を進める。なければそこで検索を終える。そして、抜き取られ短く
なった文字列を返す。string-right-trim の破壊版。"
:example
"(!p \"acbcaxyabcpqbcaba\") -> \"acbcaxyabcpqbcaba\"
(nstring-right-trim \"abc\" p) -> \"acbcaxyabcpq\"
p -> \"acbcaxyabcpqbcaba\"
(!q \"abcabcabcxabcyabccabca\") -> \"abcabcabcxabcyabccabca\"
(nstring-right-trim \"abc\" q) -> \"abcabcabcxabcy\"
(!p \"さかのうえのさかなやさん\") -> \"さかのうえのさかなやさん\"
(nstring-right-trim \"さか\" p) -> \"さかのうえのさかなやさん\"")
(define
"common:nstring-right-trim"
#'string-right-trim
:documentation
"形式 : common:nstring-right-trim char-bag string
string の文字列を右から左へ調べて行き、char-bag の中のいずれかの文字
と等しい文字を捜す。等しい文字があれば、その文字を string から抜き取り、
さらに検索を進める。なければそこで検索を終える。そして、抜き取られ短く
なった文字列を返す。 char-bag はストリング、文字のリスト、アトムのリス
トでよい。common:string-right-trim の破壊版。"
:example
"(!x \"abcdefg\") -> \"abcdefg\"
(common:nstring-right-trim \"fg\" x) -> \"abcde\"
x -> \"abcdefg\"
(common:nstring-right-trim \"ab\" x) -> \"abcdefg\"
(!y \"さしすせそたち\") -> \"さしすせそたち\"
(common:nstring-right-trim \"たち\" y) -> \"さしすせそ\"
y -> \"さしすせそたち\"")
(define
"nstring-trim"
(subr (string1 string2)
(string-trim string1 string2))
:documentation
"形式 : nstring-trim string1 string2
まず最初に、string2 の文字列を左から右へ調べて行き、string1 の中のい
ずれかの文字と等しい文字を捜す。等しい文字があれば、string-trim はそ
の文字を string2 から抜き取り、さらに検索を進める。なければそこで検索
を終える。次に string1 の中の文字と等しい文字が string2 にあるかどうか
を、今度は string2 の右から左へ調べて行く。この検索も最初と同じ方法で
進められる。最後にこの 2 つのステップで作られた新しい文字列を返す。
string-trim の破壊版。"
:example
"(!p \"acbcaxyabcpqbcaba\") -> \"acbcaxyabcpqbcaba\"
(nstring-trim \"abc\" p) -> \"xyabcpq\"
p -> \"acbcaxyabcpqbcaba\"
(!r \"さくらさくさ\") -> \"さくらさくさ\"
(nstring-trim \"さく\") -> \"ら\"
q -> \"さくらさくさ\"")
(define
"common:nstring-trim"
#'string-trim
:documentation
"形式 : common:nstring-trim char-bag string
まず最初に、string の文字列を左から右へ調べて行き、char-bag の中のい
ずれかの文字と等しい文字を捜す。等しい文字があれば、その文字を string
から抜き取り、さらに検索を進める。なければそこで検索を終える。次に
char-bag の中の文字と等しい文字が string にあるかどうかを、今度は
string の右から左へ調べて行く。この検索も最初と同じ方法で進められる。
最後にこの 2 つのステップで作られた新しい文字列を返す。 char-bag は
ストリング、文字のリスト、アトムのリストのどれか。
common:string-trim の破壊版。"
:example
"(common:nstring-trim '(#\\Space #\\Tab #\\Newline)
\" garbanzo beans\")
-> \"garbanzo beans\"
(common:nstring-trim '(\"a\") \"agarbanzo beans\")
-> \"garbanzo beans\"
(!x \"さくらさく\") -> \"さくらさく\"
(common:nstring-trim \"さ\" x) -> \"くらさく\"
x -> \"さくらさく\"")
(define
"nstring-upcase"
(subr (string &optional (start 0) end)
(nstring-upcase string :start start :end end))
:documentation
"形式 : nstring-upcase string &opt start end
string の start と end の範囲内の小文字をすべて、大文字に変換し、
その結果を返す。string は破壊される。string-upcase の破壊版。
start end の既定値はそれぞれ 0 、string の長さ。"
:example
"(nstring-upcase \"Dr.Livingston,I presume?\")
-> \"DR.LIVINGSTON,I PRESUME?\"
(nstring-upcase \"Shell we dance?\" 6 8)
-> \"Shell WE dance?\"
(nstring-upcase \"ロケット\") -> \"ロケット\"")
(define
"common:nstring-upcase"
#'nstring-upcase
:documentation
"形式 : common:nstring-upcase string &key :start :end
string の :start と :end の範囲内の小文字をすべて大文字に変換し、
その結果を返す。string は破壊される。common:string-upcase の破壊版。
:start :end の既定値は、それぞれ 0 、string の長さ。"
:example
"(common:string-upcase \"Dr.Livingston,I presume?\") ->
n \"DR.LIVINGSTON,I PRESUME?\"
(common:string-upcase \"Dr.Livingston,I presume?\" :start 4)
-> \"Dr.LIVINGSTON,I PRESUME?\"
(common:string-upcase \"ぁぃぅぇぉ\" :start 0 :end 3)
-> \"ぁぃぅぇぉ\"")
(define
"nsublis"
#'nsublis
:documentation
"形式 : nsublis a-list tree &key :test :test-not :key
連想リスト a-list のキーとなるオブジェクトを tree 中で検索し、
見つけたオブジェクトをそのキーと対応する値に変更して、返す
(tree は破壊される)。sublis の破壊版。"
:example
"(nsublis '(((+ x y) . (- x y)) ((+ x y) . (- x y)))
'(* (/ (+ x y) (+ x p) ( - x y)) :test #'equal)
-> (* (/ (- x y) (+ x p))(- x y))
x = (Hanako is kirei)
(nsublis '((kirei . woman) (small . big)) x)
-> (Hanako is woman)
x -> (Hanako is woman)")
(define
"nsublisq"
(expr (a-list tree)
(nsublis a-list tree :test #'eq))
:documentation
"形式 : nsublisq a-list tree
tree 内のシンボルを、連想リスト a-list の cdr 部と置き換えることに
よって新しい tree を作り、その結果を返す。
a-list のいずれかの要素の car 部 (キー) と eq なシンボルが tree に
あったら、そのシンボルを、その car部に対応する cdr 部で置き換える。
tree は、破壊される。sublisq の破壊版。"
:example
"")
(define
"nsubst"
#'nsubst
:documentation
"形式 : nsubst new old tree &key :test :test-not :key
tree を、値 new で書き換える (破壊的)。そして、値 old を満足する値に
戻し、その結果を返す。subst の破壊版。"
:example
"x = (shakespeare wrote (the hurricane))
(nsubst 'tempest 'hurricane x)
-> (shakespeare wrote (the tempest))
x -> (shakespeare wrote (the tempest))
(nsubst '(a . cons) '(old . pair)
'((old . spice) ((old . shoes) old . pair) (old . pair))
:test #'equal)
-> ((old . spice) ((old . shoes) a .cons) (a . cons))")
(define
"nsubst-if"
#'nsubst-if
:documentation
"形式 : nsubst-if new test tree &key :key
tree のうち、条件 test を満足するものを、値 new で書き換え (破壊的)、
その結果を返す。subst-if の破壊版。"
:example
"x = ((\"asd\" . asd) (qwe . \"qwe\"))
(nsubst-if 'a #'stringp x ) -> ((a . asd) (qwe .a))
x -> ((a . asd) (qwe . a))")
(define
"nsubst-if-not"
#'cl:nsubst-if-not
:documentation
"形式 : nsubst-if-not new test tree &key :key
tree のうち、条件 test を満足しないものを、値 new で書き換え (破壊的)、
その結果を返す。subst-if-not の破壊版。"
:example
"")
(define
"nsubstitute"
#'nsubstitute
:documentation
"形式 : nsubstitute newitem olditem seq
&key :from-end :test :test-not :start :end :count :key
シーケンス seq の :start から :end までの範囲内で、
olditem を :count 個だけ、newitem に変更し、その結果を返す。
substitute の破壊版。"
:example
"(!x '(1 2 4 1 3 4 5))
(nsubstitute 9 4 x) -> (1 2 9 1 3 9 5)
x -> (1 2 9 1 3 9 5)
(nsubstitute 3 1 x :count 1) -> (3 2 9 1 3 9 5)
x -> (3 2 9 1 3 9 5)
(nsubstitute 2 3 x :count 1 :from-end t) -> (3 2 9 1 2 9 5)
x -> (3 2 9 1 2 9 5)
(nsubstitute 9 3 x :test #'>) -> (3 9 9 9 9 9 5)
x -> (3 9 9 9 9 9 5)")
(define
"nsubstitute-if"
#'nsubstitute-if
:documentation
"形式 : nsubstitute-if newitem test seq
&key :from-end :start :end :count :key
シーケンス seq の :start から :end までの範囲内で、条件 test を満足
する値を :count 個だけ、newitem で変更し、その結果を返す。
substitute-if の破壊版。"
:example
"(!x '(1 2 4 1 3 4 5))
(nsubstitute-if 9 #'oddp x) -> (9 2 4 9 9 4 9)
x -> (9 2 4 9 9 4 9)
(nsubstitute-if 9 #'evenp x :count 1 :from-end t)
-> (9 2 4 9 9 9 9 )
x -> (9 2 4 9 9 9 9)")
(define
"nsubstitute-if-not"
#'cl:nsubstitute-if-not
:documentation
"形式 : nsubstitute-if-not newitem test seq
&key :from-end :start :end :count :key
シーケンス seq の :start から :end までの範囲内で、条件 test を満足
しない値を :count 個だけ、newitem に変更し、その結果を返す。
substitute-if-not の破壊版。"
:example
"(!x '(1 2 4 1 3 4 5))
(nsubstitute-if-not 9 #'oddp x) -> (1 9 9 1 2 9 5)
x -> (1 9 9 1 3 9 5)
(nsubstitute-if-not 9 #'evenp x :count 1 :from-end t)
-> (1 9 9 1 3 9 9)
x -> (1 9 9 1 3 9 5)")
(define
"nsubstqu"
(expr nil)
:documentation
"形式 : nsubstqu new old tree
リスト tree 内の、値 old と equal な要素を、値 new に置き換え
(破壊的)、その結果を返す。substqu の破壊版。"
:example
"x = (a b (foo . c) foo . foo)
(nsubstqu 'bar 'foo x) -> (a b (bar . c) bar . bar)
x -> (a b (bar . c) bar . bar)")
(define
"nsubstring"
(subr (string start &optional end)
(multiple-value-bind (string len start end)
(string*-arg-check (string string) start end)
(declare (ignore len))
(if (> start end)
""
(make-array (- end start)
:element-type (array-element-type string)
:displaced-to string
:displaced-index-offset start))))
:documentation
"形式 : nsubstring string start &opt end
string の start から end までの文字からなる部分ストリングを作り、
その結果を返す。end がない場合は、string の長さを用いる。
start と end は 0 から始まる数字で指定し、負の数の場合、逆インデックス
となる。例えば、\"abcd\" の中の a, b, c, d の位置を示す逆インデックスは
各々 -4, -3, -2, -1 。引数はストリングかアトムでなければならない。
nsubstring は substring と同じだが、リターン値は、string を使っており、
substring のようにコピーされたものではない。"
:example
"(nsubstring \"abcd\" 2 3) -> \"c\"
(nsubstring \"abcd\" 2) -> \"cd\"
(nsubstring 'abcdefg 3 0) -> \"\"
(nsubstring \"あいうえお\" 1 3) -> \"いう\"
(nsubstring \"さしすせそ\" 2 3) -> \"す\"")
(define
"nsymbolp"
(subr nil)
:documentation
"形式 : nsymbolp symbol
symbol がシンボルなら、nil を返し、それ以外なら t を返す。
(nsymbolp symbol) = (not (symbolp symbol))"
:example
"(nsymbolp 'x) -> nil
(nsymbolp \"abc\") -> t")
(define
"nth"
#'nth
:documentation
"形式 : nth number list
list の、number が示す位置の要素の値を返す。
(要素の位置は 0 から数える)。number は非負の整数でなければならない。"
:example
"(nth 0 (list 1 2 3)) -> 1
(nth 2 '(a b c)) -> c
(nth 5 '(a b c)) -> nil