2title = "4k: Atom Printing"
9Literal rendering engine
11`++co` contains three parts:
13- A door that contains arms that operate on the sample coin `lot`.
14- A core of rendering idioms.
15- A core of additional formatting functions used internally.
23The arm begins with the door:
32Then after that the rendering idiom core begins with:
39And finally the third core:
49Prepend & render as tape
51Renders a coin `lot` as a tape prepended to the sample tape `rom`.
55`lot` is a `coin`, and is the sample of `++co`.
66++ rear |=(rom=tape rend(rep rom))
72> (~(rear co %$ %ux 200) "--ha")
82Renders a coin `lot` as a `knot`.
86`lot` is a `coin`, and is the sample of `++co`.
95++ rent ~+ `@ta`(rap 3 rend)
101> ~(rent co %$ %ux 200)
104> `@t`~(rent co %$ %ux 200)
114Renders a coin `lot` as a `tape`.
118`lot` is a `coin`, and is the sample of `++co`.
131 ['~' '0' ((v-co 1) (jam p.lot))]
137 ['_' (weld (trip (wack rent(lot i.p.lot))) $(p.lot t.p.lot))]
138 =+ [yed=(end 3 p.p.lot) hay=(cut 3 [1 1] p.p.lot)]
140 ?+ yed (z-co q.p.lot)
141 %c ['~' '-' (weld (rip 3 (wood (tuft q.p.lot))) rep)]
143 ?+ hay (z-co q.p.lot)
145 =+ yod=(yore q.p.lot)
146 =? rep ?=(^ f.t.yod) ['.' (s-co f.t.yod)]
147 =? rep !&(?=(~ f) =(0 h) =(0 m) =(0 s)):t.yod
148 =. rep ['.' (y-co s.t.yod)]
149 =. rep ['.' (y-co m.t.yod)]
150 ['.' '.' (y-co h.t.yod)]
151 =. rep ['.' (a-co d.t.yod)]
152 =. rep ['.' (a-co m.yod)]
153 =? rep !a.yod ['-' rep]
157 =+ yug=(yell q.p.lot)
158 =? rep ?=(^ f.yug) ['.' (s-co f.yug)]
160 ?: &(=(0 d.yug) =(0 m.yug) =(0 h.yug) =(0 s.yug))
162 =? rep !=(0 s.yug) ['.' 's' (a-co s.yug)]
163 =? rep !=(0 m.yug) ['.' 'm' (a-co m.yug)]
164 =? rep !=(0 h.yug) ['.' 'h' (a-co h.yug)]
165 =? rep !=(0 d.yug) ['.' 'd' (a-co d.yug)]
172 ?:(=(| q.p.lot) ['.' 'n' rep] (z-co q.p.lot))
176 ?+ hay (z-co q.p.lot)
177 %f ((ro-co [3 10 4] |=(a=@ ~(d ne a))) q.p.lot)
178 %s ((ro-co [4 16 8] |=(a=@ ~(x ne a))) q.p.lot)
182 =+ sxz=(fein:ob q.p.lot)
186 (weld (trip (tod:po sxz)) rep)
194 rep =/ log (cut 4 [imp 1] sxz)
196 (trip (tos:po (rsh 3 log)))
197 (trip (tod:po (end 3 log)))
198 ?:(=((mod imp 4) 0) ?:(=(imp 0) "" "--") "-")
208 ?:(=(0 val) ~[0] (rip 3 val))
212 (trip (?:(s tod:po tos:po) q))
213 ?.(&(s !=(r "")) r ['-' r])
216 ?+ hay (z-co q.p.lot)
217 %d ['.' '~' (r-co (rlyd q.p.lot))]
218 %h ['.' '~' '~' (r-co (rlyh q.p.lot))]
219 %q ['.' '~' '~' '~' (r-co (rlyq q.p.lot))]
220 %s ['.' (r-co (rlys q.p.lot))]
225 %+ welp ['0' 'c' (reap (pad:fa q.p.lot) '1')]
226 (c-co (enc:fa q.p.lot))
228 =; gam=(pair tape tape)
229 (weld p.gam ?:(=(0 q.p.lot) `tape`['0' ~] q.gam))
230 ?+ hay [~ ((ox-co [10 3] |=(a=@ ~(d ne a))) q.p.lot)]
231 %b [['0' 'b' ~] ((ox-co [2 4] |=(a=@ ~(d ne a))) q.p.lot)]
232 %i [['0' 'i' ~] ((d-co 1) q.p.lot)]
233 %x [['0' 'x' ~] ((ox-co [16 4] |=(a=@ ~(x ne a))) q.p.lot)]
234 %v [['0' 'v' ~] ((ox-co [32 5] |=(a=@ ~(x ne a))) q.p.lot)]
235 %w [['0' 'w' ~] ((ox-co [64 5] |=(a=@ ~(w ne a))) q.p.lot)]
240 ?:((syn:si q.p.lot) "--" "-")
241 $(yed 'u', q.p.lot (abs:si q.p.lot))
245 ?: =('s' (cut 3 [2 1] p.p.lot))
246 (weld (rip 3 q.p.lot) rep)
247 ['~' '.' (weld (rip 3 q.p.lot) rep)]
248 ['~' '~' (weld (rip 3 (wood q.p.lot)) rep)]
255> ~(rend co %$ %ux 200)
258> ~(rend co %many ~[[%$ ux+200] [%$ p+40]])
261> ~(rend co %$ %p 32.819)
264> ~(rend co %$ %ux 18)
267> ~(rend co [%$ p=[p=%if q=0x7f00.0001]])
270> ~(rend co %many ~[[%$ %ud 20] [%$ %uw 133] [%$ %tas 'sam']])
273> ~(rend co %blob [1 1])
283Render `dat` as a decimal integer without separators.
296++ a-co |=(dat=@ ((d-co 1) dat))
302> (a-co:co 123.456.789)
312Renders the given `atom` as a base58check `tape`.
325++ c-co (em-co [58 1] |=([? b=@ c=tape] [~(c ne b) c]))
331> (enc:fa 0xdead.beef)
334> (c-co:co 0xdead.beef.938b.8b0c)
342Render decimal with min length
344Render `hol` as a decimal integer without separators and with a minimum length
345of `min`. If `hol` has less than `min` digits, leading zeros will be added to
346make up the difference.
361++ d-co |=(min=@ (em-co [10 min] |=([? b=@ c=tape] [~(d ne b) c])))
367> ((d-co:co 1) 123.456)
370> ((d-co:co 9) 123.456)
380Render decimal float `a` as a `tape`.
395 ?: ?=([%i *] a) (weld ?:(s.a "inf" "-inf") rep)
396 ?: ?=([%n *] a) (weld "nan" rep)
397 =; rep ?:(s.a rep ['-' rep])
400 =/ e=@s (sun:si (lent f))
401 =/ sci :(sum:si e.a e -1)
402 ?: (syn:si (dif:si e.a --3)) [--1 sci] :: 12000 -> 12e3 e>+2
403 ?: !(syn:si (dif:si sci -2)) [--1 sci] :: 0.001 -> 1e-3 e<-2
404 [(sum:si sci --1) --0] :: 1.234e2 -> '.'@3 -> 123 .4
406 :(weld ?:((syn:si e.a) "e" "e-") ((d-co 1) (abs:si e.a)))
407 (weld (ed-co e f) rep)
413> `tape`(r-co:co (rlys .3.14))
416> `tape`(r-co:co (rlys .1.681557e-39))
426Render `esc`, a list of atoms, as hex with a dot before each value. Values less
427than two bytes in length will be padded with zeros.
431`esc` is a `(list @)`.
441 |= esc=(list @) ^- tape
443 ['.' =>(.(rep $(esc t.esc)) ((x-co 4) i.esc))]
449> `tape`(s-co:co ~[0xdead 0xbeef 0xcafe])
452> `tape`(s-co:co ~[0xa 0xb 0xc])
455> `tape`(s-co:co ~[0xdead.beef])
463Render base-32 with minimum length
465Render `hol` as base-32 with a minimum length of `min`. If `hol` is shorter than
466`min` it will be padded with zeros.
481++ v-co |=(min=@ (em-co [32 min] |=([? b=@ c=tape] [~(v ne b) c])))
487> `tape`((v-co:co 1) 0v2l7.eiug3.0mbd9)
490> `tape`((v-co:co 20) 0v2l7.eiug3.0mbd9)
491"00000002l7eiug30mbd9"
498Render base-64 with minimum length
500Render `hol` as base-64 with a minimum length of `min`. If `hol` is horter than
501`min` it will be padded with zeros.
516++ w-co |=(min=@ (em-co [64 min] |=([? b=@ c=tape] [~(w ne b) c])))
522> `tape`((w-co:co 1) 0w2.OtBSR.pPVeT)
525> `tape`((w-co:co 20) 0w2.OtBSR.pPVeT)
526"0000000002OtBSRpPVeT"
533Render hex with minimum length
535Render `hol` as hex with a minimum length of `min`. If `hol` is horter than
536`min` it will be padded with zeros.
551++ x-co |=(min=@ (em-co [16 min] |=([? b=@ c=tape] [~(x ne b) c])))
557> `tape`((x-co:co 1) 0xdead.beef)
560> `tape`((x-co:co 20) 0xdead.beef)
561"000000000000deadbeef"
568Render decimal with at least two digits
570Render `dat` as a decimal with a minimum of two digits. If `dat` is less than
571two digits it will be padded with zeros.
584++ y-co |=(dat=@ ((d-co 2) dat))
607Render '0x'-prefixed hex
609Render `dat` as hex with a `0x` prefix.
622++ z-co |=(dat=@ `tape`['0' 'x' ((x-co 1) dat)])
631> (z-co:co 0xdead.beef)
642Render in numeric base
644In base `bas`, format `min` digits of `hol` with `par`. This is used internally
645by other rendering functions.
647- `hol` is processed least-significant digit first.
648- All available digits in `hol` will be processed, but
649 `min` digits can exceed the number available in `hol`
650- `par` handles all accumulated output on each call, and can edit it, prepend or
652- Until `hol` is exhausted, `par`'s sample is `[| digit output]`, subsequently,
657`[bas=@ min=@]`, where `bas` is the numeric base and `min` is the minimum
660`par` is a `gate` of `$-([? @ tape] tape)`.
672 |= [[bas=@ min=@] par=$-([? @ tape] tape)]
675 ?: &(=(0 hol) =(0 min))
677 =/ [dar=@ rad=@] (dvr hol bas)
679 min ?:(=(0 min) 0 (dec min))
681 rep (par =(0 dar) rad rep)
688> ((em-co:co [16 10] |=([? b=@ c=tape] [~(x ne b) c])) 0xbeef)
696Format with decimal place
698Format `int` by specifying its size with `exp`, which may be negative. This is
699used internally by other rendering functions.
715 |= [exp=@s int=tape] ^- tape
716 =/ [pos=? dig=@u] [=(--1 (cmp:si exp --0)) (abs:si exp)]
718 (into (weld (reap +(dig) '0') int) 1 '.')
720 ?: (lth dig len) (into int dig '.')
721 (weld int (reap (sub dig len) '0'))
727> (ed-co:co --3 "100")
730> (ed-co:co --5 "100")
744Format dot-separated digits in numeric base
746In base `bas`, format each digit of `hol` with gate `dug`, with '.' separators
747every `gop` digits. This is used internally by other rendering functions.
749- `hol` is processed least-significant digit first.
750- `dug` handles individual digits, output is prepended.
751- Every segment but the last is zero-padded to `gop`.
755`[bas=@ gop=@]` where `bas` is the numeric base and `gop` is dot separator
758`dug` is a `gate` of `$-(@ @)`.
770 |= [[bas=@ gop=@] dug=$-(@ @)]
773 |= [top=? seg=@ res=tape]
775 ?:(top ~ `tape`['.' ~])
779 |=([? b=@ c=tape] [(dug b) c])
785> ((ox-co:co [2 4] |=(a=@ ~(d ne a))) 0b1011.1101)
788> ((ox-co:co [2 1] |=(a=@ ~(d ne a))) 0b1011.1101)
791> ((ox-co:co [2 100] |=(a=@ ~(d ne a))) 0b1011.1101)
799Format dot-prefixed bloqs in numeric base
801In base `bas`, for `buz` bloqs 0 to `dop`, format at least one digit of `hol`,
802prefixed with `.`. This is used internally for `@i` address rendering functions.
806`[buz=@ bas=@ dop=@]` where `buz` is the bloq size, `bas` is the numeric base,
807and `dop` is the number of bloqs.
809`dug` is a `gate` of `$-(@ @)`.
821 |= [[buz=@ bas=@ dop=@] dug=$-(@ @)]
828 %. (cut buz [pod 1] hol)
829 %+ em-co(rep $(dop pod))
831 |=([? b=@ c=tape] [(dug b) c])
837> ((ro-co:co [3 10 4] |=(a=@ ~(d ne a))) .127.0.0.1)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list