on 6487c21 help sign in
999 lines 15 kB history raw
1+++
2title = "4b: Text Processing"
3weight = 29
4template = "doc.html"
5+++
6### `++at`
8```
9 ++ at
10 |_ a=@
11```
13XX document
17### `++r:at`
19```
20 ++ r
21 ?: ?& (gte (met 3 a) 2)
22 |-
23 ?: =(0 a)
24 &
25 =+ vis=(end 3 1 a)
26 ?& ?|(=('-' vis) ?&((gte vis 'a') (lte vis 'z')))
27 $(a (rsh 3 1 a))
28 ==
29 ==
30 rtam
31 ?: (lte (met 3 a) 2)
32 rud
33 rux
34```
37XX document
39### `++rf:at`
41```
42 ++ rf `tape`[?-(a $& '&', $| '|', * !!) ~]
43```
46XX document
48### `++rn:at`
50```
51 ++ rn `tape`[?>(=(0 a) '~') ~]
52```
54XX document
56### `++rt:at`
58```
59 ++ rt `tape`['\'' (weld (mesc (trip a)) `tape`['\'' ~])]
60```
62XX document
64### `++rta:at`
66```
67 ++ rta rt
68```
70XX document
72### `++rtam:at`
74```
75 ++ rtam `tape`['%' (trip a)]
76```
78XX document
80### `++rub:at`
82```
83 ++ rub `tape`['0' 'b' (rum 2 ~ |=(b/@ (add '0' b)))]
84```
86XX document
88### `++rud:at`
90```
91 ++ rud (rum 10 ~ |=(b/@ (add '0' b)))
92```
94XX document
96### `++rum:at`
98```
99 ++ rum
100 |= {b/@ c/tape d/$-(@ @)}
101 ^- tape
102 ?: =(0 a)
103 [(d 0) c]
104 =+ e=0
105 |- ^- tape
106 ?: =(0 a)
107 c
108 =+ f=&(!=(0 e) =(0 (mod e ?:(=(10 b) 3 4))))
109 %= $
110 a (div a b)
111 c [(d (mod a b)) ?:(f [?:(=(10 b) ',' '-') c] c)]
112 e +(e)
113 ==
114 ::
115```
117XX document
119### `++rup:at`
121```
122 ++ rup
123 =+ b=(met 3 a)
124 ^- tape
125 :- '-'
126 |- ^- tape
127 ?: (gth (met 5 a) 1)
128 %+ weld
129 $(a (rsh 5 1 a), b (sub b 4))
130 `tape`['-' '-' $(a (end 5 1 a), b 4)]
131 ?: =(0 b)
132 ['~' ~]
133 ?: (lte b 1)
134 (trip (tos:po a))
135 |- ^- tape
136 ?: =(2 b)
137 =+ c=(rsh 3 1 a)
138 =+ d=(end 3 1 a)
139 (weld (trip (tod:po c)) (trip (tos:po (mix c d))))
140 =+ c=(rsh 3 2 a)
141 =+ d=(end 3 2 a)
142 (weld ^$(a c, b (met 3 c)) `tape`['-' $(a (mix c d), b 2)])
143 ::
144```
146XX document
148### `++ruv:at`
150```
151 ++ ruv
152 ^- tape
153 :+ '0'
154 'v'
155 %^ rum
156 64
157 ~
158 |= b/@
159 ?: =(63 b)
160 '+'
161 ?: =(62 b)
162 '-'
163 ?:((lth b 26) (add 65 b) ?:((lth b 52) (add 71 b) (sub b 4)))
164 ::
165```
167XX document
169### `++rux:at`
171```
172 ++ rux `tape`['0' 'x' (rum 16 ~ |=(b/@ (add b ?:((lth b 10) 48 87))))]
173 --
174 :::::::::::::::::::::::::::::::::::::::::::::::::::::: ::
175```
177XX document
179---
182---
184### `++cass`
186To lowercase
188Produce the case insensitive (all lowercase) `++cord` of a `++tape`.
190#### Accepts
192`vib` is a `++tape`.
194#### Produces
196A `++cord`.
198#### Source
200```
201 ++ cass :: lowercase
202 |= vib/tape
203 %+ rap 3
204 (turn vib |=(a/@ ?.(&((gte a 'A') (lte a 'Z')) a (add 32 a))))
205```
207#### Examples
209```
210 > (cass "john doe")
211 7.309.170.810.699.673.450
213 > `cord`(cass "john doe")
214 'john doe'
216 > (cass "abc, 123, !@#")
217 2.792.832.775.110.938.439.066.079.945.313
219 > `cord`(cass "abc, 123, !@#")
220 'abc, 123, !@#'
221```
223---
224### `++crip`
226Tape to cord
228Produce a `++cord` from a `++tape`.
230#### Accepts
232`a` is a `++tape`.
234#### Produces
236A `++cord`.
238#### Source
240```
241 ++ crip |=(a=tape `@t`(rap 3 a)) :: tape to cord
242```
244#### Examples
246```
247 > (crip "john doe")
248 'john doe'
250 > (crip "abc 123 !@#")
251 'abc 123 !@#'
253 > `@ud`(crip "abc")
254 6.513.249
255```
257---
258### `++cuss`
260To uppercase
262Turn all occurances of lowercase letters in any `++tape` into uppercase
263letters, as a `++cord`.
265#### Accepts
267`vib` is a `++tape`.
269#### Produces
271A `++cord`.
273#### Source
275```
276 ++ cuss :: uppercase
277 |= vib=tape
278 ^- @t
279 %+ rap 3
280 (turn vib |=(a=@ ?.(&((gte a 'a') (lte a 'z')) a (sub a 32))))
281```
283#### Examples
285```
286 > (cuss "john doe")
287 'JOHN DOE'
289 > (cuss "abc ABC 123 !@#")
290 'ABC ABC 123 !@#'
292 > `@ud`(cuss "abc")
293 4.407.873
295 > (cuss "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsQqRrVvWwXxYyZz")
296 'AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSQQRRVVWWXXYYZZ'
297```
299---
300### `++mesc`
302Escape special chars
304Escape special characters, used in `++show`.
306#### Accepts
308`vib` is a `++tape`.
310#### Produces
312A `++tape`.
314#### Source
316```
317 ++ mesc :: ctrl code escape
318 |= vib/tape
319 ^- tape
320 ?~ vib
321 ~
322 ?: =('\\' i.vib)
323 ['\\' '\\' $(vib t.vib)]
324 ?: ?|((gth i.vib 126) (lth i.vib 32) =(`@`39 i.vib))
325 ['\\' (welp ~(rux at i.vib) '/' $(vib t.vib))]
326 [i.vib $(vib t.vib)]
327```
329#### Examples
331```
332 > (mesc "ham lus")
333 "ham lus"
334 > (mesc "bas\\hur")
335 "bas\\\\hur"
336 > (mesc "as'saß")
337 "as\0x27/sa\0xc3/\0x9f/"
338```
341---
342### `++runt`
344Prepend `n` times
346Add `a` repetitions of character `b` to the head of `++tape` `c`.
348#### Accepts
350`a` and `b` are atoms.
352`c` is a `++tape`.
354#### Produces
356A `++tape`.
358#### Source
360```
361 ++ runt :: prepend repeatedly
362 |= [[a/@ b/@] c/tape]
363 ^- tape
364 ?: =(0 a)
365 c
366 [b $(a (dec a))]
367 ::
368```
370#### Examples
372```
373 > (runt [2 '/'] "ham")
374 "//ham"
375 > (runt [10 'a'] "")
376 "aaaaaaaaaa"
377```
380---
381### `++sand`
383Soft-cast by odor
385Soft-cast validity by odor.
387#### Accepts
389`a` is a `++span` (`@ta`).
391`b` is an atom.
393#### Produces
395A `(unit @)`.
397#### Source
399```
400 ++ sand :: atom sanity
401 |= a/@ta
402 |= b/@ ^- (unit @)
403 ?.(((sane a) b) ~ [~ b])
404 ::
405```
407#### Examples
409```
410 > `(unit @ta)`((sand %ta) 'sym-som')
411 [~ ~.sym-som]
412 > `(unit @ta)`((sand %ta) 'err!')
413 ~
414```
417---
418### `++sane`
420Check odor validity
422Check validity by odor. Produces a gate.
424#### Accepts
426`a` is a `++span` (`@ta`).
428`b` is an atom.
430#### Produces
432A boolean.
434#### Source
436```
437 ++ sane :: atom sanity
438 |= a/@ta
439 |= b/@ ^- ?
440 ?. =(%t (end 3 1 a))
441 ~|(%sane-stub !!)
442 =+ [inx=0 len=(met 3 b)]
443 ?: =(%tas a)
444 |- ^- ?
445 ?: =(inx len) &
446 =+ cur=(cut 3 [inx 1] b)
447 ?& ?| &((gte cur 'a') (lte cur 'z'))
448 &(=('-' cur) !=(0 inx) !=(len inx))
449 &(&((gte cur '0') (lte cur '9')) !=(0 inx))
450 ==
451 $(inx +(inx))
452 ==
453 ?: =(%ta a)
454 |- ^- ?
455 ?: =(inx len) &
456 =+ cur=(cut 3 [inx 1] b)
457 ?& ?| &((gte cur 'a') (lte cur 'z'))
458 &((gte cur '0') (lte cur '9'))
459 |(=('-' cur) =('~' cur) =('_' cur) =('.' cur))
460 ==
461 $(inx +(inx))
462 ==
463 |- ^- ?
464 ?: =(0 b) &
465 =+ cur=(end 3 1 b)
466 ?: &((lth cur 32) !=(10 cur)) |
467 =+ len=(teff cur)
468 ?& |(=(1 len) =+(i=1 |-(|(=(i len) &((gte (cut 3 [i 1] b) 128) $(i +(i)))))))
469 $(b (rsh 3 len b))
470 ==
471 ::
472```
474#### Examples
476```
477 > ((sane %tas) %mol)
478 %.y
479 > ((sane %tas) 'lam')
480 %.y
481 > ((sane %tas) 'more ace')
482 %.n
483```
486---
487### `++teff`
489UTF8 Length
491Produces the number of utf8 bytes.
493#### Accepts
495`a` is a `@t`.
497#### Produces
499An atom.
501#### Source
503```
504 |= a/@t ^- @
505 =+ b=(end 3 1 a)
506 ~| %bad-utf8
507 ?: =(0 b)
508 ?>(=(`@`0 a) 0)
509 ?> |((gte b 32) =(10 b))
510 ?:((lte b 127) 1 ?:((lte b 223) 2 ?:((lte b 239) 3 4)))
511```
513#### Examples
515```
516 > (teff 'a')
517 1
518 > (teff 'ß')
519 2
520```
523---
524### `++trim`
526Tape split
528Split first `a` characters off `++tape` `b`.
530#### Accepts
532`a` is an atom.
534`b` is a `++tape`.
536#### Produces
538A cell of `++tape`s, `p` and `q`.
540#### Source
542```
543 ++ trim :: 31-bit nonzero
544 |= key/@
545 =+ syd=0xcafe.babe
546 |- ^- @
547 =+ haz=(spec syd key)
548 =+ ham=(mix (rsh 0 31 haz) (end 0 31 haz))
549 ?.(=(0 ham) ham $(syd +(syd)))
550 --
551 ::
552```
554#### Examples
556```
557 > (trim 5 "lasok termun")
558 [p="lasok" q=" termun"]
559 > (trim 5 "zam")
560 [p="zam" q=""]
561```
564---
565### `++trip`
567Cord to tape
569Produce a `++tape` from `++cord`.
571#### Accepts
573`a` is an atom.
575#### Produces
577A `++tape`.
579#### Source
581```
582 ++ trip :: cord to tape
583 ~/ %trip
584 |= a/@ ^- tape
585 ?: =(0 (met 3 a))
586 ~
587 [^-(@ta (end 3 1 a)) $(a (rsh 3 1 a))]
588 ::
589```
591#### Examples
593```
594 > (trip 'john doe')
595 "john doe"
596 > (trip 'abc 123 !@#')
597 "abc 123 !@#"
598 > (trip 'abc')
599 "abc"
600```
603---
604### `++tuba`
606UTF8 to UTF32 tape
608Convert `++tape` to a `++list` of codepoints (`@c`).
610#### Accepts
612`a` is a `++tape`.
614#### Produces
616A `++list` of codepoints `@c`.
618#### Source
620```
621 ++ tuba :: utf8 to utf32 tape
622 |= a/tape
623 ^- (list @c)
624 (rip 5 (turf (rap 3 a))) :: XX horrible
625 ::
626```
628#### Examples
630```
631 > (tuba "я тут")
632 ~[~-~44f. ~-. ~-~442. ~-~443. ~-~442.]
633 > (tuba "chars")
634 ~[~-c ~-h ~-a ~-r ~-s]
635```
638---
639### `++tufa`
641UTF32 to UTF8 tape
643Wrap a `++list` of utf32 codepoints into a utf8 `++tape`.
645#### Accepts
647`a` is a `++list` of `@c`.
649#### Produces
651A `++tape`.
653#### Source
655```
656 ++ tufa :: utf32 to utf8 tape
657 |= a=(list @c)
658 ^- tape
659 ?~ a ""
660 (weld (rip 3 (tuft i.a)) $(a t.a))
661 ::
662```
664#### Examples
666```
667 > (tufa ~[~-~44f. ~-. ~-~442. ~-~443. ~-~442.])
668 "я тут"
669 > (tufa ((list @c) ~[%a %b 0xb1 %c]))
670 "ab±c"
671```
674---
675### `++tuft`
677UTF32 to UTF8 text
679Convert utf32 glyph to
680LSB utf8 `++cord`.
682#### Accepts
684`a` is a codepoint (`@c`).
686#### Produces
688A `++cord`.
690#### Source
692```
693 ++ tuft :: utf32 to utf8 text
694 |= a/@c
695 ^- @t
696 %+ rap 3
697 |- ^- (list @)
698 ?: =(`@`0 a)
699 ~
700 =+ b=(end 5 1 a)
701 =+ c=$(a (rsh 5 1 a))
702 ?: (lte b 0x7f)
703 [b c]
704 ?: (lte b 0x7ff)
705 :* (mix 0b1100.0000 (cut 0 [6 5] b))
706 (mix 0b1000.0000 (end 0 6 b))
707 c
708 ==
709 ?: (lte b 0xffff)
710 :* (mix 0b1110.0000 (cut 0 [12 4] b))
711 (mix 0b1000.0000 (cut 0 [6 6] b))
712 (mix 0b1000.0000 (end 0 6 b))
713 c
714 ==
715 :* (mix 0b1111.0000 (cut 0 [18 3] b))
716 (mix 0b1000.0000 (cut 0 [12 6] b))
717 (mix 0b1000.0000 (cut 0 [6 6] b))
718 (mix 0b1000.0000 (end 0 6 b))
719 c
720 ==
721```
723#### Examples
725```
726 > (tuft `@c`%a)
727 'a'
728 > (tuft `@c`0xb6)
729 '¶'
730```
733---
734### `++turf`
736UTF8 to UTF32 cord
738Convert utf8 (`++cord`) to utf32 codepoints.
740#### Accepts
742`a` is a `@t`.
744#### Produces
746A `@c`, UTF-32 codepoint.
748#### Source
750```
751 ++ turf :: utf8 to utf32
752 |= a/@t
753 ^- @c
754 %+ rap 5
755 |- ^- (list @c)
756 =+ b=(teff a)
757 ?: =(0 b) ~
758 =+ ^= c
759 %+ can 0
760 %+ turn
761 ^- (list {p/@ q/@})
762 ?+ b !!
763 $1 [[0 7] ~]
764 $2 [[8 6] [0 5] ~]
765 $3 [[16 6] [8 6] [0 4] ~]
766 $4 [[24 6] [16 6] [8 6] [0 3] ~]
767 ==
768 |=({p/@ q/@} [q (cut 0 [p q] a)])
769 ?. =((tuft c) (end 3 b a)) ~|(%bad-utf8 !!)
770 [c $(a (rsh 3 b a))]
771 ::
772```
774#### Examples
776```
777 > (turf 'my ßam')
778 ~-my.~df.am
779 > 'я тут'
780 'я тут'
781 > (turf 'я тут')
782 ~-~44f..~442.~443.~442.
783 > `@ux`'я тут'
784 0x82.d183.d182.d120.8fd1
785 > `@ux`(turf 'я тут')
786 0x442.0000.0443.0000.0442.0000.0020.0000.044f
787```
790---
791### `++wack`
793Coin format encode
795Escape `++span` `~` as `~~` and `_` as `~-`. Used for printing.
797#### Accepts
799`a` is a `++span` (`@ta`).
801#### Produces
803A `++span` (`@ta`).
805#### Source
807```
808 ++ wack :: coin format
809 |= a/@ta
810 ^- @ta
811 =+ b=(rip 3 a)
812 %+ rap 3
813 |- ^- tape
814 ?~ b
815 ~
816 ?: =('~' i.b) ['~' '~' $(b t.b)]
817 ?: =('_' i.b) ['~' '-' $(b t.b)]
818 [i.b $(b t.b)]
819 ::
820```
822#### Examples
824```
825 > (wack '~20_sam~')
826 ~.~~20~-sam~~
828 > `@t`(wack '~20_sam~')
829 '~~20~-sam~~'
831 > ~(rend co %many ~[`ud/5 `ta/'~20_sam'])
832 "._5_~~.~~20~-sam__"
834 > ._5_~~.~~20~-sam__
835 [5 ~.~20_sam]
836```
838---
839### `++wick`
841Coin format decode
843Unescape `++span` `~~` as `~` and `~-` as `_`.
845#### Accepts
847`a` is a an atom.
849#### Produces
851A `++span` `@ta`.
853#### Source
855```
856 ++ wick :: knot format
857 |= a/@
858 ^- (unit @ta)
859 =+ b=(rip 3 a)
860 =- ?^(b ~ (some (rap 3 (flop c))))
861 =| c/tape
862 |- ^- {b/tape c/tape}
863 ?~ b [~ c]
864 ?. =('~' i.b)
865 $(b t.b, c [i.b c])
866 ?~ t.b [b ~]
867 ?- i.t.b
868 $'~' $(b t.t.b, c ['~' c])
869 $'-' $(b t.t.b, c ['_' c])
870 @ [b ~]
871 ==
872 ::
873```
875#### Examples
877```
878 > `@t`(wick '~-ams~~lop')
879 '_ams~lop'
881 > `@t`(wick (wack '~20_sam~'))
882 '~20_sam~'
883```
886---
887### `++woad`
889Unescape cord
891Unescape `++cord` codepoints.
893#### Accepts
895`a` is a `@ta`.
897#### Produces
899A `++cord`.
901#### Source
903```
904 ++ woad :: cord format
905 |= a/@ta
906 ^- @t
907 %+ rap 3
908 |- ^- (list @)
909 ?: =(`@`0 a)
910 ~
911 =+ b=(end 3 1 a)
912 =+ c=(rsh 3 1 a)
913 ?: =('.' b)
914 [' ' $(a c)]
915 ?. =('~' b)
916 [b $(a c)]
917 => .(b (end 3 1 c), c (rsh 3 1 c))
918 ?+ b =- (weld (rip 3 (tuft p.d)) $(a q.d))
919 ^= d
920 =+ d=0
921 |- ^- {p/@ q/@}
922 ?: =('.' b)
923 [d c]
924 ?< =(0 c)
925 %= $
926 b (end 3 1 c)
927 c (rsh 3 1 c)
928 d %+ add (mul 16 d)
929 %+ sub b
930 ?: &((gte b '0') (lte b '9')) 48
931 ?>(&((gte b 'a') (lte b 'z')) 87)
932 ==
933 $'.' ['.' $(a c)]
934 $'~' ['~' $(a c)]
935 ==
936 ::
937```
939#### Examples
941```
942 > (woad ~.~b6.20.as)
943 '¶20 as'
944```
947---
948### `++wood`
950Escape cord
952Escape `++cord` codepoints.
954#### Accepts
956`a` is a `++span` (`@ta`).
958#### Produces
960A `++span` (`@ta`).
962#### Source
964```
965 ++ wood :: cord format
966 |= a/@t
967 ^- @ta
968 %+ rap 3
969 |- ^- (list @)
970 ?: =(`@`0 a)
971 ~
972 =+ b=(teff a)
973 =+ c=(turf (end 3 b a))
974 =+ d=$(a (rsh 3 b a))
975 ?: ?| &((gte c 'a') (lte c 'z'))
976 &((gte c '0') (lte c '9'))
977 =(`@`'-' c)
978 ==
979 [c d]
980 ?+ c
981 :- '~'
982 =+ e=(met 2 c)
983 |- ^- tape
984 ?: =(0 e)
985 ['.' d]
986 =. e (dec e)
987 =+ f=(rsh 2 e c)
988 [(add ?:((lte f 9) 48 87) f) $(c (end 2 e c))]
989 ::
990```
992#### Examples
994```
995 > (wood 'my ßam')
996 ~.my.~df.am
997```
999---