on 8564483 help sign in
985 lines 15 kB history raw
1---
2navhome: /docs
3---
6# 4b: text processing
7### `++at`
9 ++ at
10 |_ a/@
12XX document
14### `++r`
16 ++ r
17 ?: ?& (gte (met 3 a) 2)
18 |-
19 ?: =(0 a)
20 &
21 =+ vis=(end 3 1 a)
22 ?& ?|(=('-' vis) ?&((gte vis 'a') (lte vis 'z')))
23 $(a (rsh 3 1 a))
24 ==
25 ==
26 rtam
27 ?: (lte (met 3 a) 2)
28 rud
29 rux
30 ::
32XX document
34### `++rf`
36 ++ rf `tape`[?-(a $& '&', $| '|', * !!) ~]
39XX document
41### `++rn`
43 ++ rn `tape`[?>(=(0 a) '~') ~]
45XX document
47### `++rt`
49 ++ rt `tape`['\'' (weld (mesc (trip a)) `tape`['\'' ~])]
51XX document
53### `++rta`
55 ++ rta rt
57XX document
59### `++rtam`
61 ++ rtam `tape`['%' (trip a)]
63XX document
65### `++rub`
67 ++ rub `tape`['0' 'b' (rum 2 ~ |=(b/@ (add '0' b)))]
69XX document
71### `++rud`
73 ++ rud (rum 10 ~ |=(b/@ (add '0' b)))
75XX document
77### `++rum`
79 ++ rum
80 |= {b/@ c/tape d/$-(@ @)}
81 ^- tape
82 ?: =(0 a)
83 [(d 0) c]
84 =+ e=0
85 |- ^- tape
86 ?: =(0 a)
87 c
88 =+ f=&(!=(0 e) =(0 (mod e ?:(=(10 b) 3 4))))
89 %= $
90 a (div a b)
91 c [(d (mod a b)) ?:(f [?:(=(10 b) ',' '-') c] c)]
92 e +(e)
93 ==
94 ::
97XX document
99### `++rup`
101 ++ rup
102 =+ b=(met 3 a)
103 ^- tape
104 :- '-'
105 |- ^- tape
106 ?: (gth (met 5 a) 1)
107 %+ weld
108 $(a (rsh 5 1 a), b (sub b 4))
109 `tape`['-' '-' $(a (end 5 1 a), b 4)]
110 ?: =(0 b)
111 ['~' ~]
112 ?: (lte b 1)
113 (trip (tos:po a))
114 |- ^- tape
115 ?: =(2 b)
116 =+ c=(rsh 3 1 a)
117 =+ d=(end 3 1 a)
118 (weld (trip (tod:po c)) (trip (tos:po (mix c d))))
119 =+ c=(rsh 3 2 a)
120 =+ d=(end 3 2 a)
121 (weld ^$(a c, b (met 3 c)) `tape`['-' $(a (mix c d), b 2)])
122 ::
124XX document
126### `++ruv`
128 ++ ruv
129 ^- tape
130 :+ '0'
131 'v'
132 %^ rum
133 64
134 ~
135 |= b/@
136 ?: =(63 b)
137 '+'
138 ?: =(62 b)
139 '-'
140 ?:((lth b 26) (add 65 b) ?:((lth b 52) (add 71 b) (sub b 4)))
141 ::
143XX document
145### `++rux`
147 ++ rux `tape`['0' 'x' (rum 16 ~ |=(b/@ (add b ?:((lth b 10) 48 87))))]
148 --
149 :::::::::::::::::::::::::::::::::::::::::::::::::::::: ::
151XX document
153------------------------------------------------------------------------
156***
158### `++cass`
160To lowercase
162Produce the case insensitive (all lowercase) [`++cord`]() of a [`++tape`]().
164Accepts
165-------
167`vib` is a `++tape`.
169Produces
170--------
172A `++cord`.
174Source
175------
177 ++ cass :: lowercase
178 |= vib/tape
179 %+ rap 3
180 (turn vib |=(a/@ ?.(&((gte a 'A') (lte a 'Z')) a (add 32 a))))
182Examples
183--------
185 > (cass "john doe")
186 7.309.170.810.699.673.450
187 > `cord`(cass "john doe")
188 'john doe'
189 > (cass "abc, 123, !@#")
190 2.792.832.775.110.938.439.066.079.945.313
191 > `cord`(cass "abc, 123, !@#")
192 'abc, 123, !@#'
195***
196### `++crip`
198Tape to cord
200Produce a `++cord` from a `++tape`.
202Accepts
203-------
205`a` is a `++tape`.
207Produces
208--------
210A `++cord`.
212Source
213------
215 ++ crip |=(a=tape `@t`(rap 3 a)) :: tape to cord
217Examples
218--------
220 > (crip "john doe")
221 'john doe'
222 > (crip "abc 123 !@#")
223 'abc 123 !@#'
224 > `@ud`(crip "abc")
225 6.513.249
228***
229### `++cuss`
231To uppercase
233Turn all occurances of lowercase letters in any `++tape` into uppercase
234letters, as a `++cord`.
236Accepts
237-------
239`vib` is a `++tape`.
241Produces
242--------
244A `++cord`.
246Source
247------
249 ++ cuss :: uppercase
250 |= vib=tape
251 ^- @t
252 %+ rap 3
253 (turn vib |=(a=@ ?.(&((gte a 'a') (lte a 'z')) a (sub a 32))))
254 ::
256Examples
257--------
259 > (cuss "john doe")
260 'JOHN DOE'
261 > (cuss "abc ABC 123 !@#")
262 'ABC ABC 123 !@#'
263 > `@ud`(cuss "abc")
264 4.407.873
265 > (cuss "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsQqRrVvWwXxYyZz")
266 'AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSQQRRVVWWXXYYZZ'
269***
270### `++mesc`
272Escape special chars
274Escape special characters, used in `++show`.
276Accepts
277-------
279`vib` is a `++tape`.
281Produces
282--------
284A `++tape`.
286Source
287------
289 ++ mesc :: ctrl code escape
290 |= vib/tape
291 ^- tape
292 ?~ vib
293 ~
294 ?: =('\\' i.vib)
295 ['\\' '\\' $(vib t.vib)]
296 ?: ?|((gth i.vib 126) (lth i.vib 32) =(`@`39 i.vib))
297 ['\\' (welp ~(rux at i.vib) '/' $(vib t.vib))]
298 [i.vib $(vib t.vib)]
299 ::
301Examples
302--------
304 /> (mesc "ham lus")
305 "ham lus"
306 /> (mesc "bas\\hur")
307 "bas\\\\hur"
308 /> (mesc "as'saß")
309 "as\0x27/sa\0xc3/\0x9f/"
313***
314### `++runt`
316Prepend `n` times
318Add `a` repetitions of character `b` to the head of `++tape` `c`.
320Accepts
321-------
323`a` and `b` are atoms.
325`c` is a `++tape`.
327Produces
328--------
330A `++tape`.
332Source
333------
335 ++ runt :: prepend repeatedly
336 |= [[a/@ b/@] c/tape]
337 ^- tape
338 ?: =(0 a)
339 c
340 [b $(a (dec a))]
341 ::
343Examples
344--------
346 /> (runt [2 '/'] "ham")
347 "//ham"
348 /> (runt [10 'a'] "")
349 "aaaaaaaaaa"
353***
354### `++sand`
356Soft-cast by odor
358Soft-cast validity by odor.
360Accepts
361-------
363`a` is a `++span` (`@ta`).
365`b` is an atom.
367Produces
368--------
370A `(unit @)`.
372Source
373------
375 ++ sand :: atom sanity
376 |= a/@ta
377 |= b/@ ^- (unit @)
378 ?.(((sane a) b) ~ [~ b])
379 ::
381Examples
382--------
384 /> `(unit @ta)`((sand %ta) 'sym-som')
385 [~ ~.sym-som]
386 /> `(unit @ta)`((sand %ta) 'err!')
387 ~
391***
392### `++sane`
394Check odor validity
396Check validity by odor. Produces a gate.
398Accepts
399-------
401`a` is a `++span` (`@ta`).
403`b` is an atom.
405Produces
406--------
408A boolean.
410Source
411------
413 ++ sane :: atom sanity
414 |= a/@ta
415 |= b/@ ^- ?
416 ?. =(%t (end 3 1 a))
417 ~|(%sane-stub !!)
418 =+ [inx=0 len=(met 3 b)]
419 ?: =(%tas a)
420 |- ^- ?
421 ?: =(inx len) &
422 =+ cur=(cut 3 [inx 1] b)
423 ?& ?| &((gte cur 'a') (lte cur 'z'))
424 &(=('-' cur) !=(0 inx) !=(len inx))
425 &(&((gte cur '0') (lte cur '9')) !=(0 inx))
426 ==
427 $(inx +(inx))
428 ==
429 ?: =(%ta a)
430 |- ^- ?
431 ?: =(inx len) &
432 =+ cur=(cut 3 [inx 1] b)
433 ?& ?| &((gte cur 'a') (lte cur 'z'))
434 &((gte cur '0') (lte cur '9'))
435 |(=('-' cur) =('~' cur) =('_' cur) =('.' cur))
436 ==
437 $(inx +(inx))
438 ==
439 |- ^- ?
440 ?: =(0 b) &
441 =+ cur=(end 3 1 b)
442 ?: &((lth cur 32) !=(10 cur)) |
443 =+ len=(teff cur)
444 ?& |(=(1 len) =+(i=1 |-(|(=(i len) &((gte (cut 3 [i 1] b) 128) $(i +(i)))))))
445 $(b (rsh 3 len b))
446 ==
447 ::
449Examples
450--------
452 /> ((sane %tas) %mol)
453 %.y
454 /> ((sane %tas) 'lam')
455 %.y
456 /> ((sane %tas) 'more ace')
457 %.n
461***
462### `++teff`
464UTF8 Length
466Produces the number of utf8 bytes.
468Accepts
469-------
471`a` is a `@t`.
473Produces
474--------
476An atom.
478Source
479------
481 |= a/@t ^- @
482 =+ b=(end 3 1 a)
483 ~| %bad-utf8
484 ?: =(0 b)
485 ?>(=(`@`0 a) 0)
486 ?> |((gte b 32) =(10 b))
487 ?:((lte b 127) 1 ?:((lte b 223) 2 ?:((lte b 239) 3 4)))
489Examples
490--------
492 /> (teff 'a')
493 1
494 /> (teff 'ß')
495 2
499***
500### `++trim`
502Tape split
504Split first `a` characters off `++tape` `b`.
506Accepts
507-------
509`a` is an atom.
511`b` is a `++tape`.
513Produces
514--------
516A cell of `++tape`s, `p` and `q`.
518Source
519------
521 ++ trim :: 31-bit nonzero
522 |= key/@
523 =+ syd=0xcafe.babe
524 |- ^- @
525 =+ haz=(spec syd key)
526 =+ ham=(mix (rsh 0 31 haz) (end 0 31 haz))
527 ?.(=(0 ham) ham $(syd +(syd)))
528 --
529 ::
532Examples
533--------
535 /> (trim 5 "lasok termun")
536 [p="lasok" q=" termun"]
537 /> (trim 5 "zam")
538 [p="zam" q=""]
542***
543### `++trip`
545Cord to tape
547Produce a `++tape` from `++cord`.
549Accepts
550-------
552`a` is an atom.
554Produces
555--------
557A `++tape`.
559Source
560------
562 ++ trip :: cord to tape
563 ~/ %trip
564 |= a/@ ^- tape
565 ?: =(0 (met 3 a))
566 ~
567 [^-(@ta (end 3 1 a)) $(a (rsh 3 1 a))]
568 ::
571Examples
572--------
574 /> (trip 'john doe')
575 "john doe"
576 /> (trip 'abc 123 !@#')
577 "abc 123 !@#"
578 /> (trip 'abc')
579 "abc"
583***
584### `++tuba`
586UTF8 to UTF32 tape
588Convert `++tape` to a `++list` of codepoints (`@c`).
590Accepts
591-------
593`a` is a `++tape`.
595Produces
596--------
598A `++list` of codepoints `@c`.
600Source
601------
603 ++ tuba :: utf8 to utf32 tape
604 |= a/tape
605 ^- (list @c)
606 (rip 5 (turf (rap 3 a))) :: XX horrible
607 ::
609Examples
610--------
612 /> (tuba "я тут")
613 ~[~-~44f. ~-. ~-~442. ~-~443. ~-~442.]
614 /> (tuba "chars")
615 ~[~-c ~-h ~-a ~-r ~-s]
619***
620### `++tufa`
622UTF32 to UTF8 tape
624Wrap a `++list` of utf32 codepoints into a utf8 `++tape`.
626Accepts
627-------
629`a` is a `++list` of `@c`.
631Produces
632--------
634A `++tape`.
636Source
637------
639 ++ tufa :: utf32 to utf8 tape
640 |= a=(list @c)
641 ^- tape
642 ?~ a ""
643 (weld (rip 3 (tuft i.a)) $(a t.a))
644 ::
646Examples
647--------
649 /> (tufa ~[~-~44f. ~-. ~-~442. ~-~443. ~-~442.])
650 "я тут"
651 /> (tufa ((list @c) ~[%a %b 0xb1 %c]))
652 "ab±c"
656***
657### `++tuft`
659UTF32 to UTF8 text
661Convert utf32 glyph to
662LSB utf8 `++cord`.
664Accepts
665-------
667`a` is a codepoint (`@c`).
669Produces
670--------
672A `++cord`.
674Source
675------
677 ++ tuft :: utf32 to utf8 text
678 |= a/@c
679 ^- @t
680 %+ rap 3
681 |- ^- (list @)
682 ?: =(`@`0 a)
683 ~
684 =+ b=(end 5 1 a)
685 =+ c=$(a (rsh 5 1 a))
686 ?: (lte b 0x7f)
687 [b c]
688 ?: (lte b 0x7ff)
689 :* (mix 0b1100.0000 (cut 0 [6 5] b))
690 (mix 0b1000.0000 (end 0 6 b))
691 c
692 ==
693 ?: (lte b 0xffff)
694 :* (mix 0b1110.0000 (cut 0 [12 4] b))
695 (mix 0b1000.0000 (cut 0 [6 6] b))
696 (mix 0b1000.0000 (end 0 6 b))
697 c
698 ==
699 :* (mix 0b1111.0000 (cut 0 [18 3] b))
700 (mix 0b1000.0000 (cut 0 [12 6] b))
701 (mix 0b1000.0000 (cut 0 [6 6] b))
702 (mix 0b1000.0000 (end 0 6 b))
703 c
704 ==
705 ::
707Examples
708--------
710 /> (tuft `@c`%a)
711 'a'
712 /> (tuft `@c`0xb6)
713 '¶'
717***
718### `++turf`
720UTF8 to UTF32 cord
722Convert utf8 (`++cord`) to utf32 codepoints.
724Accepts
725-------
727`a` is a `@t`.
729Produces
730--------
732A `@c`, UTF-32 codepoint.
734Source
735------
737 ++ turf :: utf8 to utf32
738 |= a/@t
739 ^- @c
740 %+ rap 5
741 |- ^- (list @c)
742 =+ b=(teff a)
743 ?: =(0 b) ~
744 =+ ^= c
745 %+ can 0
746 %+ turn
747 ^- (list {p/@ q/@})
748 ?+ b !!
749 $1 [[0 7] ~]
750 $2 [[8 6] [0 5] ~]
751 $3 [[16 6] [8 6] [0 4] ~]
752 $4 [[24 6] [16 6] [8 6] [0 3] ~]
753 ==
754 |=({p/@ q/@} [q (cut 0 [p q] a)])
755 ?. =((tuft c) (end 3 b a)) ~|(%bad-utf8 !!)
756 [c $(a (rsh 3 b a))]
757 ::
759Examples
760--------
762 /> (turf 'my ßam')
763 ~-my.~df.am
764 /> 'я тут'
765 'я тут'
766 /> (turf 'я тут')
767 ~-~44f..~442.~443.~442.
768 /> `@ux`'я тут'
769 0x82.d183.d182.d120.8fd1
770 /> `@ux`(turf 'я тут')
771 0x442.0000.0443.0000.0442.0000.0020.0000.044f
775***
776### `++wack`
778Coin format encode
780Escape `++span` `~` as `~~` and `_` as `~-`. Used for printing.
782Accepts
783-------
785`a` is a `++span` (`@ta`).
787Produces
788--------
790A `++span` (`@ta`).
792Source
793------
795 ++ wack :: coin format
796 |= a/@ta
797 ^- @ta
798 =+ b=(rip 3 a)
799 %+ rap 3
800 |- ^- tape
801 ?~ b
802 ~
803 ?: =('~' i.b) ['~' '~' $(b t.b)]
804 ?: =('_' i.b) ['~' '-' $(b t.b)]
805 [i.b $(b t.b)]
806 ::
808Examples
809--------
811 /> (wack '~20_sam~')
812 ~.~~20~-sam~~
813 /> `@t`(wack '~20_sam~')
814 '~~20~-sam~~'
815 > ~(rend co %many ~[`ud/5 `ta/'~20_sam'])
816 "._5_~~.~~20~-sam__"
817 > ._5_~~.~~20~-sam__
818 [5 ~.~20_sam]
822***
823### `++wick`
825Coin format decode
827Unescape `++span` `~~` as `~` and `~-` as `_`.
829Accepts
830-------
832`a` is a an atom.
834Produces
835--------
837A `++span` `@ta`.
839Source
840------
842 ++ wick :: knot format
843 |= a/@
844 ^- (unit @ta)
845 =+ b=(rip 3 a)
846 =- ?^(b ~ (some (rap 3 (flop c))))
847 =| c/tape
848 |- ^- {b/tape c/tape}
849 ?~ b [~ c]
850 ?. =('~' i.b)
851 $(b t.b, c [i.b c])
852 ?~ t.b [b ~]
853 ?- i.t.b
854 $'~' $(b t.t.b, c ['~' c])
855 $'-' $(b t.t.b, c ['_' c])
856 @ [b ~]
857 ==
858 ::
860Examples
861--------
863 /> `@t`(wick '~-ams~~lop')
864 '_ams~lop'
865 /> `@t`(wick (wack '~20_sam~'))
866 '~20_sam~'
870***
871### `++woad`
873Unescape cord
875Unescape `++cord` codepoints.
877Accepts
878-------
880`a` is a `@ta`.
882Produces
883--------
885A `++cord`.
887Source
888------
890 ++ woad :: cord format
891 |= a/@ta
892 ^- @t
893 %+ rap 3
894 |- ^- (list @)
895 ?: =(`@`0 a)
896 ~
897 =+ b=(end 3 1 a)
898 =+ c=(rsh 3 1 a)
899 ?: =('.' b)
900 [' ' $(a c)]
901 ?. =('~' b)
902 [b $(a c)]
903 => .(b (end 3 1 c), c (rsh 3 1 c))
904 ?+ b =- (weld (rip 3 (tuft p.d)) $(a q.d))
905 ^= d
906 =+ d=0
907 |- ^- {p/@ q/@}
908 ?: =('.' b)
909 [d c]
910 ?< =(0 c)
911 %= $
912 b (end 3 1 c)
913 c (rsh 3 1 c)
914 d %+ add (mul 16 d)
915 %+ sub b
916 ?: &((gte b '0') (lte b '9')) 48
917 ?>(&((gte b 'a') (lte b 'z')) 87)
918 ==
919 $'.' ['.' $(a c)]
920 $'~' ['~' $(a c)]
921 ==
922 ::
924Examples
925--------
927 /> (woad ~.~b6.20.as)
928 '¶20 as'
932***
933### `++wood`
935Escape cord
937Escape `++cord` codepoints.
939Accepts
940-------
942`a` is a `++span` (`@ta`).
944Produces
945--------
947A `++span` (`@ta`).
949Source
950------
952 ++ wood :: cord format
953 |= a/@t
954 ^- @ta
955 %+ rap 3
956 |- ^- (list @)
957 ?: =(`@`0 a)
958 ~
959 =+ b=(teff a)
960 =+ c=(turf (end 3 b a))
961 =+ d=$(a (rsh 3 b a))
962 ?: ?| &((gte c 'a') (lte c 'z'))
963 &((gte c '0') (lte c '9'))
964 =(`@`'-' c)
965 ==
966 [c d]
967 ?+ c
968 :- '~'
969 =+ e=(met 2 c)
970 |- ^- tape
971 ?: =(0 e)
972 ['.' d]
973 =. e (dec e)
974 =+ f=(rsh 2 e c)
975 [(add ?:((lte f 9) 48 87) f) $(c (end 2 e c))]
976 ::
978Examples
979--------
981 /> (wood 'my ßam')
982 ~.my.~df.am
985***