on 140ac0e help sign in
980 lines 15 kB history raw
1# 4b: text processing
2### `++at`
4 ++ at
5 |_ a/@
7XX document
9### `++r`
11 ++ r
12 ?: ?& (gte (met 3 a) 2)
13 |-
14 ?: =(0 a)
15 &
16 =+ vis=(end 3 1 a)
17 ?& ?|(=('-' vis) ?&((gte vis 'a') (lte vis 'z')))
18 $(a (rsh 3 1 a))
19 ==
20 ==
21 rtam
22 ?: (lte (met 3 a) 2)
23 rud
24 rux
25 ::
27XX document
29### `++rf`
31 ++ rf `tape`[?-(a $& '&', $| '|', * !!) ~]
34XX document
36### `++rn`
38 ++ rn `tape`[?>(=(0 a) '~') ~]
40XX document
42### `++rt`
44 ++ rt `tape`['\'' (weld (mesc (trip a)) `tape`['\'' ~])]
46XX document
48### `++rta`
50 ++ rta rt
52XX document
54### `++rtam`
56 ++ rtam `tape`['%' (trip a)]
58XX document
60### `++rub`
62 ++ rub `tape`['0' 'b' (rum 2 ~ |=(b/@ (add '0' b)))]
64XX document
66### `++rud`
68 ++ rud (rum 10 ~ |=(b/@ (add '0' b)))
70XX document
72### `++rum`
74 ++ rum
75 |= {b/@ c/tape d/$-(@ @)}
76 ^- tape
77 ?: =(0 a)
78 [(d 0) c]
79 =+ e=0
80 |- ^- tape
81 ?: =(0 a)
82 c
83 =+ f=&(!=(0 e) =(0 (mod e ?:(=(10 b) 3 4))))
84 %= $
85 a (div a b)
86 c [(d (mod a b)) ?:(f [?:(=(10 b) ',' '-') c] c)]
87 e +(e)
88 ==
89 ::
92XX document
94### `++rup`
96 ++ rup
97 =+ b=(met 3 a)
98 ^- tape
99 :- '-'
100 |- ^- tape
101 ?: (gth (met 5 a) 1)
102 %+ weld
103 $(a (rsh 5 1 a), b (sub b 4))
104 `tape`['-' '-' $(a (end 5 1 a), b 4)]
105 ?: =(0 b)
106 ['~' ~]
107 ?: (lte b 1)
108 (trip (tos:po a))
109 |- ^- tape
110 ?: =(2 b)
111 =+ c=(rsh 3 1 a)
112 =+ d=(end 3 1 a)
113 (weld (trip (tod:po c)) (trip (tos:po (mix c d))))
114 =+ c=(rsh 3 2 a)
115 =+ d=(end 3 2 a)
116 (weld ^$(a c, b (met 3 c)) `tape`['-' $(a (mix c d), b 2)])
117 ::
119XX document
121### `++ruv`
123 ++ ruv
124 ^- tape
125 :+ '0'
126 'v'
127 %^ rum
128 64
129 ~
130 |= b/@
131 ?: =(63 b)
132 '+'
133 ?: =(62 b)
134 '-'
135 ?:((lth b 26) (add 65 b) ?:((lth b 52) (add 71 b) (sub b 4)))
136 ::
138XX document
140### `++rux`
142 ++ rux `tape`['0' 'x' (rum 16 ~ |=(b/@ (add b ?:((lth b 10) 48 87))))]
143 --
144 :::::::::::::::::::::::::::::::::::::::::::::::::::::: ::
146XX document
148------------------------------------------------------------------------
151***
153### `++cass`
155To lowercase
157Produce the case insensitive (all lowercase) [`++cord`]() of a [`++tape`]().
159Accepts
160-------
162`vib` is a `++tape`.
164Produces
165--------
167A `++cord`.
169Source
170------
172 ++ cass :: lowercase
173 |= vib/tape
174 %+ rap 3
175 (turn vib |=(a/@ ?.(&((gte a 'A') (lte a 'Z')) a (add 32 a))))
177Examples
178--------
180 > (cass "john doe")
181 7.309.170.810.699.673.450
182 > `cord`(cass "john doe")
183 'john doe'
184 > (cass "abc, 123, !@#")
185 2.792.832.775.110.938.439.066.079.945.313
186 > `cord`(cass "abc, 123, !@#")
187 'abc, 123, !@#'
190***
191### `++crip`
193Tape to cord
195Produce a `++cord` from a `++tape`.
197Accepts
198-------
200`a` is a `++tape`.
202Produces
203--------
205A `++cord`.
207Source
208------
210 ++ crip |=(a=tape `@t`(rap 3 a)) :: tape to cord
212Examples
213--------
215 > (crip "john doe")
216 'john doe'
217 > (crip "abc 123 !@#")
218 'abc 123 !@#'
219 > `@ud`(crip "abc")
220 6.513.249
223***
224### `++cuss`
226To uppercase
228Turn all occurances of lowercase letters in any `++tape` into uppercase
229letters, as a `++cord`.
231Accepts
232-------
234`vib` is a `++tape`.
236Produces
237--------
239A `++cord`.
241Source
242------
244 ++ cuss :: uppercase
245 |= vib=tape
246 ^- @t
247 %+ rap 3
248 (turn vib |=(a=@ ?.(&((gte a 'a') (lte a 'z')) a (sub a 32))))
249 ::
251Examples
252--------
254 > (cuss "john doe")
255 'JOHN DOE'
256 > (cuss "abc ABC 123 !@#")
257 'ABC ABC 123 !@#'
258 > `@ud`(cuss "abc")
259 4.407.873
260 > (cuss "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsQqRrVvWwXxYyZz")
261 'AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSQQRRVVWWXXYYZZ'
264***
265### `++mesc`
267Escape special chars
269Escape special characters, used in `++show`.
271Accepts
272-------
274`vib` is a `++tape`.
276Produces
277--------
279A `++tape`.
281Source
282------
284 ++ mesc :: ctrl code escape
285 |= vib/tape
286 ^- tape
287 ?~ vib
288 ~
289 ?: =('\\' i.vib)
290 ['\\' '\\' $(vib t.vib)]
291 ?: ?|((gth i.vib 126) (lth i.vib 32) =(`@`39 i.vib))
292 ['\\' (welp ~(rux at i.vib) '/' $(vib t.vib))]
293 [i.vib $(vib t.vib)]
294 ::
296Examples
297--------
299 /> (mesc "ham lus")
300 "ham lus"
301 /> (mesc "bas\\hur")
302 "bas\\\\hur"
303 /> (mesc "as'saß")
304 "as\0x27/sa\0xc3/\0x9f/"
308***
309### `++runt`
311Prepend `n` times
313Add `a` repetitions of character `b` to the head of `++tape` `c`.
315Accepts
316-------
318`a` and `b` are atoms.
320`c` is a `++tape`.
322Produces
323--------
325A `++tape`.
327Source
328------
330 ++ runt :: prepend repeatedly
331 |= [[a/@ b/@] c/tape]
332 ^- tape
333 ?: =(0 a)
334 c
335 [b $(a (dec a))]
336 ::
338Examples
339--------
341 /> (runt [2 '/'] "ham")
342 "//ham"
343 /> (runt [10 'a'] "")
344 "aaaaaaaaaa"
348***
349### `++sand`
351Soft-cast by odor
353Soft-cast validity by odor.
355Accepts
356-------
358`a` is a `++span` (`@ta`).
360`b` is an atom.
362Produces
363--------
365A `(unit @)`.
367Source
368------
370 ++ sand :: atom sanity
371 |= a/@ta
372 |= b/@ ^- (unit @)
373 ?.(((sane a) b) ~ [~ b])
374 ::
376Examples
377--------
379 /> `(unit @ta)`((sand %ta) 'sym-som')
380 [~ ~.sym-som]
381 /> `(unit @ta)`((sand %ta) 'err!')
382 ~
386***
387### `++sane`
389Check odor validity
391Check validity by odor. Produces a gate.
393Accepts
394-------
396`a` is a `++span` (`@ta`).
398`b` is an atom.
400Produces
401--------
403A boolean.
405Source
406------
408 ++ sane :: atom sanity
409 |= a/@ta
410 |= b/@ ^- ?
411 ?. =(%t (end 3 1 a))
412 ~|(%sane-stub !!)
413 =+ [inx=0 len=(met 3 b)]
414 ?: =(%tas a)
415 |- ^- ?
416 ?: =(inx len) &
417 =+ cur=(cut 3 [inx 1] b)
418 ?& ?| &((gte cur 'a') (lte cur 'z'))
419 &(=('-' cur) !=(0 inx) !=(len inx))
420 &(&((gte cur '0') (lte cur '9')) !=(0 inx))
421 ==
422 $(inx +(inx))
423 ==
424 ?: =(%ta a)
425 |- ^- ?
426 ?: =(inx len) &
427 =+ cur=(cut 3 [inx 1] b)
428 ?& ?| &((gte cur 'a') (lte cur 'z'))
429 &((gte cur '0') (lte cur '9'))
430 |(=('-' cur) =('~' cur) =('_' cur) =('.' cur))
431 ==
432 $(inx +(inx))
433 ==
434 |- ^- ?
435 ?: =(0 b) &
436 =+ cur=(end 3 1 b)
437 ?: &((lth cur 32) !=(10 cur)) |
438 =+ len=(teff cur)
439 ?& |(=(1 len) =+(i=1 |-(|(=(i len) &((gte (cut 3 [i 1] b) 128) $(i +(i)))))))
440 $(b (rsh 3 len b))
441 ==
442 ::
444Examples
445--------
447 /> ((sane %tas) %mol)
448 %.y
449 /> ((sane %tas) 'lam')
450 %.y
451 /> ((sane %tas) 'more ace')
452 %.n
456***
457### `++teff`
459UTF8 Length
461Produces the number of utf8 bytes.
463Accepts
464-------
466`a` is a `@t`.
468Produces
469--------
471An atom.
473Source
474------
476 |= a/@t ^- @
477 =+ b=(end 3 1 a)
478 ~| %bad-utf8
479 ?: =(0 b)
480 ?>(=(`@`0 a) 0)
481 ?> |((gte b 32) =(10 b))
482 ?:((lte b 127) 1 ?:((lte b 223) 2 ?:((lte b 239) 3 4)))
484Examples
485--------
487 /> (teff 'a')
488 1
489 /> (teff 'ß')
490 2
494***
495### `++trim`
497Tape split
499Split first `a` characters off `++tape` `b`.
501Accepts
502-------
504`a` is an atom.
506`b` is a `++tape`.
508Produces
509--------
511A cell of `++tape`s, `p` and `q`.
513Source
514------
516 ++ trim :: 31-bit nonzero
517 |= key/@
518 =+ syd=0xcafe.babe
519 |- ^- @
520 =+ haz=(spec syd key)
521 =+ ham=(mix (rsh 0 31 haz) (end 0 31 haz))
522 ?.(=(0 ham) ham $(syd +(syd)))
523 --
524 ::
527Examples
528--------
530 /> (trim 5 "lasok termun")
531 [p="lasok" q=" termun"]
532 /> (trim 5 "zam")
533 [p="zam" q=""]
537***
538### `++trip`
540Cord to tape
542Produce a `++tape` from `++cord`.
544Accepts
545-------
547`a` is an atom.
549Produces
550--------
552A `++tape`.
554Source
555------
557 ++ trip :: cord to tape
558 ~/ %trip
559 |= a/@ ^- tape
560 ?: =(0 (met 3 a))
561 ~
562 [^-(@ta (end 3 1 a)) $(a (rsh 3 1 a))]
563 ::
566Examples
567--------
569 /> (trip 'john doe')
570 "john doe"
571 /> (trip 'abc 123 !@#')
572 "abc 123 !@#"
573 /> (trip 'abc')
574 "abc"
578***
579### `++tuba`
581UTF8 to UTF32 tape
583Convert `++tape` to a `++list` of codepoints (`@c`).
585Accepts
586-------
588`a` is a `++tape`.
590Produces
591--------
593A `++list` of codepoints `@c`.
595Source
596------
598 ++ tuba :: utf8 to utf32 tape
599 |= a/tape
600 ^- (list @c)
601 (rip 5 (turf (rap 3 a))) :: XX horrible
602 ::
604Examples
605--------
607 /> (tuba "я тут")
608 ~[~-~44f. ~-. ~-~442. ~-~443. ~-~442.]
609 /> (tuba "chars")
610 ~[~-c ~-h ~-a ~-r ~-s]
614***
615### `++tufa`
617UTF32 to UTF8 tape
619Wrap a `++list` of utf32 codepoints into a utf8 `++tape`.
621Accepts
622-------
624`a` is a `++list` of `@c`.
626Produces
627--------
629A `++tape`.
631Source
632------
634 ++ tufa :: utf32 to utf8 tape
635 |= a=(list @c)
636 ^- tape
637 ?~ a ""
638 (weld (rip 3 (tuft i.a)) $(a t.a))
639 ::
641Examples
642--------
644 /> (tufa ~[~-~44f. ~-. ~-~442. ~-~443. ~-~442.])
645 "я тут"
646 /> (tufa ((list @c) ~[%a %b 0xb1 %c]))
647 "ab±c"
651***
652### `++tuft`
654UTF32 to UTF8 text
656Convert utf32 glyph to
657LSB utf8 `++cord`.
659Accepts
660-------
662`a` is a codepoint (`@c`).
664Produces
665--------
667A `++cord`.
669Source
670------
672 ++ tuft :: utf32 to utf8 text
673 |= a/@c
674 ^- @t
675 %+ rap 3
676 |- ^- (list @)
677 ?: =(`@`0 a)
678 ~
679 =+ b=(end 5 1 a)
680 =+ c=$(a (rsh 5 1 a))
681 ?: (lte b 0x7f)
682 [b c]
683 ?: (lte b 0x7ff)
684 :* (mix 0b1100.0000 (cut 0 [6 5] b))
685 (mix 0b1000.0000 (end 0 6 b))
686 c
687 ==
688 ?: (lte b 0xffff)
689 :* (mix 0b1110.0000 (cut 0 [12 4] b))
690 (mix 0b1000.0000 (cut 0 [6 6] b))
691 (mix 0b1000.0000 (end 0 6 b))
692 c
693 ==
694 :* (mix 0b1111.0000 (cut 0 [18 3] b))
695 (mix 0b1000.0000 (cut 0 [12 6] b))
696 (mix 0b1000.0000 (cut 0 [6 6] b))
697 (mix 0b1000.0000 (end 0 6 b))
698 c
699 ==
700 ::
702Examples
703--------
705 /> (tuft `@c`%a)
706 'a'
707 /> (tuft `@c`0xb6)
708 '¶'
712***
713### `++turf`
715UTF8 to UTF32 cord
717Convert utf8 (`++cord`) to utf32 codepoints.
719Accepts
720-------
722`a` is a `@t`.
724Produces
725--------
727A `@c`, UTF-32 codepoint.
729Source
730------
732 ++ turf :: utf8 to utf32
733 |= a/@t
734 ^- @c
735 %+ rap 5
736 |- ^- (list @c)
737 =+ b=(teff a)
738 ?: =(0 b) ~
739 =+ ^= c
740 %+ can 0
741 %+ turn
742 ^- (list {p/@ q/@})
743 ?+ b !!
744 $1 [[0 7] ~]
745 $2 [[8 6] [0 5] ~]
746 $3 [[16 6] [8 6] [0 4] ~]
747 $4 [[24 6] [16 6] [8 6] [0 3] ~]
748 ==
749 |=({p/@ q/@} [q (cut 0 [p q] a)])
750 ?. =((tuft c) (end 3 b a)) ~|(%bad-utf8 !!)
751 [c $(a (rsh 3 b a))]
752 ::
754Examples
755--------
757 /> (turf 'my ßam')
758 ~-my.~df.am
759 /> 'я тут'
760 'я тут'
761 /> (turf 'я тут')
762 ~-~44f..~442.~443.~442.
763 /> `@ux`'я тут'
764 0x82.d183.d182.d120.8fd1
765 /> `@ux`(turf 'я тут')
766 0x442.0000.0443.0000.0442.0000.0020.0000.044f
770***
771### `++wack`
773Coin format encode
775Escape `++span` `~` as `~~` and `_` as `~-`. Used for printing.
777Accepts
778-------
780`a` is a `++span` (`@ta`).
782Produces
783--------
785A `++span` (`@ta`).
787Source
788------
790 ++ wack :: coin format
791 |= a/@ta
792 ^- @ta
793 =+ b=(rip 3 a)
794 %+ rap 3
795 |- ^- tape
796 ?~ b
797 ~
798 ?: =('~' i.b) ['~' '~' $(b t.b)]
799 ?: =('_' i.b) ['~' '-' $(b t.b)]
800 [i.b $(b t.b)]
801 ::
803Examples
804--------
806 /> (wack '~20_sam~')
807 ~.~~20~-sam~~
808 /> `@t`(wack '~20_sam~')
809 '~~20~-sam~~'
810 > ~(rend co %many ~[`ud/5 `ta/'~20_sam'])
811 "._5_~~.~~20~-sam__"
812 > ._5_~~.~~20~-sam__
813 [5 ~.~20_sam]
817***
818### `++wick`
820Coin format decode
822Unescape `++span` `~~` as `~` and `~-` as `_`.
824Accepts
825-------
827`a` is a an atom.
829Produces
830--------
832A `++span` `@ta`.
834Source
835------
837 ++ wick :: knot format
838 |= a/@
839 ^- (unit @ta)
840 =+ b=(rip 3 a)
841 =- ?^(b ~ (some (rap 3 (flop c))))
842 =| c/tape
843 |- ^- {b/tape c/tape}
844 ?~ b [~ c]
845 ?. =('~' i.b)
846 $(b t.b, c [i.b c])
847 ?~ t.b [b ~]
848 ?- i.t.b
849 $'~' $(b t.t.b, c ['~' c])
850 $'-' $(b t.t.b, c ['_' c])
851 @ [b ~]
852 ==
853 ::
855Examples
856--------
858 /> `@t`(wick '~-ams~~lop')
859 '_ams~lop'
860 /> `@t`(wick (wack '~20_sam~'))
861 '~20_sam~'
865***
866### `++woad`
868Unescape cord
870Unescape `++cord` codepoints.
872Accepts
873-------
875`a` is a `@ta`.
877Produces
878--------
880A `++cord`.
882Source
883------
885 ++ woad :: cord format
886 |= a/@ta
887 ^- @t
888 %+ rap 3
889 |- ^- (list @)
890 ?: =(`@`0 a)
891 ~
892 =+ b=(end 3 1 a)
893 =+ c=(rsh 3 1 a)
894 ?: =('.' b)
895 [' ' $(a c)]
896 ?. =('~' b)
897 [b $(a c)]
898 => .(b (end 3 1 c), c (rsh 3 1 c))
899 ?+ b =- (weld (rip 3 (tuft p.d)) $(a q.d))
900 ^= d
901 =+ d=0
902 |- ^- {p/@ q/@}
903 ?: =('.' b)
904 [d c]
905 ?< =(0 c)
906 %= $
907 b (end 3 1 c)
908 c (rsh 3 1 c)
909 d %+ add (mul 16 d)
910 %+ sub b
911 ?: &((gte b '0') (lte b '9')) 48
912 ?>(&((gte b 'a') (lte b 'z')) 87)
913 ==
914 $'.' ['.' $(a c)]
915 $'~' ['~' $(a c)]
916 ==
917 ::
919Examples
920--------
922 /> (woad ~.~b6.20.as)
923 '¶20 as'
927***
928### `++wood`
930Escape cord
932Escape `++cord` codepoints.
934Accepts
935-------
937`a` is a `++span` (`@ta`).
939Produces
940--------
942A `++span` (`@ta`).
944Source
945------
947 ++ wood :: cord format
948 |= a/@t
949 ^- @ta
950 %+ rap 3
951 |- ^- (list @)
952 ?: =(`@`0 a)
953 ~
954 =+ b=(teff a)
955 =+ c=(turf (end 3 b a))
956 =+ d=$(a (rsh 3 b a))
957 ?: ?| &((gte c 'a') (lte c 'z'))
958 &((gte c '0') (lte c '9'))
959 =(`@`'-' c)
960 ==
961 [c d]
962 ?+ c
963 :- '~'
964 =+ e=(met 2 c)
965 |- ^- tape
966 ?: =(0 e)
967 ['.' d]
968 =. e (dec e)
969 =+ f=(rsh 2 e c)
970 [(add ?:((lte f 9) 48 87) f) $(c (end 2 e c))]
971 ::
973Examples
974--------
976 /> (wood 'my ßam')
977 ~.my.~df.am
980***