++co
Literal rendering engine
++co
contains three parts:
- A door that contains arms that operate on the sample coin
lot
. - A core of rendering idioms.
- A core of additional formatting functions used internally.
Accepts
lot
is a coin
.
Source
The arm begins with the door:
++ co!:~% %co ..co ~=< |_ lot=coin
Then after that the rendering idiom core begins with:
=| rep=tape=< |%
And finally the third core:
|%
++rear:co
Prepend & render as tape
Renders a coin lot
as a tape prepended to the sample tape rom
.
Accepts
lot
is a coin
, and is the sample of ++co
.
rom
is a tape
.
Produces
A tape
.
Source
++ rear |=(rom=tape rend(rep rom))
Examples
> (~(rear co %$ %ux 200) "--ha")"0xc8--ha"
++rent:co
Render as knot
Renders a coin lot
as a knot
.
Accepts
lot
is a coin
, and is the sample of ++co
.
Produces
A knot
.
Source
++ rent ~+ `@ta`(rap 3 rend)
Examples
> ~(rent co %$ %ux 200)~.0xc8> `@t`~(rent co %$ %ux 200)'0xc8'
++rend:co
Render as tape
Renders a coin lot
as a tape
.
Accepts
lot
is a coin
, and is the sample of ++co
.
Produces
A tape
.
Source
++ rend^- tape~+?: ?=(%blob -.lot)['~' '0' ((v-co 1) (jam p.lot))]?: ?=(%many -.lot):- '.'|- ^- tape?~ p.lot['_' '_' rep]['_' (weld (trip (wack rent(lot i.p.lot))) $(p.lot t.p.lot))]=+ [yed=(end 3 p.p.lot) hay=(cut 3 [1 1] p.p.lot)]|- ^- tape?+ yed (z-co q.p.lot)%c ['~' '-' (weld (rip 3 (wood (tuft q.p.lot))) rep)]%d?+ hay (z-co q.p.lot)%a=+ yod=(yore q.p.lot)=? rep ?=(^ f.t.yod) ['.' (s-co f.t.yod)]=? rep !&(?=(~ f) =(0 h) =(0 m) =(0 s)):t.yod=. rep ['.' (y-co s.t.yod)]=. rep ['.' (y-co m.t.yod)]['.' '.' (y-co h.t.yod)]=. rep ['.' (a-co d.t.yod)]=. rep ['.' (a-co m.yod)]=? rep !a.yod ['-' rep]['~' (a-co y.yod)]::%r=+ yug=(yell q.p.lot)=? rep ?=(^ f.yug) ['.' (s-co f.yug)]:- '~'?: &(=(0 d.yug) =(0 m.yug) =(0 h.yug) =(0 s.yug))['s' '0' rep]=? rep !=(0 s.yug) ['.' 's' (a-co s.yug)]=? rep !=(0 m.yug) ['.' 'm' (a-co m.yug)]=? rep !=(0 h.yug) ['.' 'h' (a-co h.yug)]=? rep !=(0 d.yug) ['.' 'd' (a-co d.yug)]+.rep==::%f?: =(& q.p.lot)['.' 'y' rep]?:(=(| q.p.lot) ['.' 'n' rep] (z-co q.p.lot))::%n ['~' rep]%i?+ hay (z-co q.p.lot)%f ((ro-co [3 10 4] |=(a=@ ~(d ne a))) q.p.lot)%s ((ro-co [4 16 8] |=(a=@ ~(x ne a))) q.p.lot)==::%p=+ sxz=(fein:ob q.p.lot)=+ dyx=(met 3 sxz):- '~'?: (lte dyx 1)(weld (trip (tod:po sxz)) rep)=+ dyy=(met 4 sxz)=| imp=@ud|- ^- tape?: =(imp dyy)rep%= $imp +(imp)rep =/ log (cut 4 [imp 1] sxz);: weld(trip (tos:po (rsh 3 log)))(trip (tod:po (end 3 log)))?:(=((mod imp 4) 0) ?:(=(imp 0) "" "--") "-")rep== ==::%q:+ '.' '~'=; res=(pair ? tape)(weld q.res rep)%+ roll=* val q.p.lot?:(=(0 val) ~[0] (rip 3 val))|= [q=@ s=? r=tape]:- !s%+ weld(trip (?:(s tod:po tos:po) q))?.(&(s !=(r "")) r ['-' r])::%r?+ hay (z-co q.p.lot)%d ['.' '~' (r-co (rlyd q.p.lot))]%h ['.' '~' '~' (r-co (rlyh q.p.lot))]%q ['.' '~' '~' '~' (r-co (rlyq q.p.lot))]%s ['.' (r-co (rlys q.p.lot))]==::%u?: ?=(%c hay)%+ welp ['0' 'c' (reap (pad:fa q.p.lot) '1')](c-co (enc:fa q.p.lot))::=; gam=(pair tape tape)(weld p.gam ?:(=(0 q.p.lot) `tape`['0' ~] q.gam))?+ hay [~ ((ox-co [10 3] |=(a=@ ~(d ne a))) q.p.lot)]%b [['0' 'b' ~] ((ox-co [2 4] |=(a=@ ~(d ne a))) q.p.lot)]%i [['0' 'i' ~] ((d-co 1) q.p.lot)]%x [['0' 'x' ~] ((ox-co [16 4] |=(a=@ ~(x ne a))) q.p.lot)]%v [['0' 'v' ~] ((ox-co [32 5] |=(a=@ ~(x ne a))) q.p.lot)]%w [['0' 'w' ~] ((ox-co [64 5] |=(a=@ ~(w ne a))) q.p.lot)]==::%s%+ weld?:((syn:si q.p.lot) "--" "-")$(yed 'u', q.p.lot (abs:si q.p.lot))::%t?: =('a' hay)?: =('s' (cut 3 [2 1] p.p.lot))(weld (rip 3 q.p.lot) rep)['~' '.' (weld (rip 3 q.p.lot) rep)]['~' '~' (weld (rip 3 (wood q.p.lot)) rep)]==
Examples
> ~(rend co %$ %ux 200)"0xc8"> ~(rend co %many ~[[%$ ux+200] [%$ p+40]])"._0xc8_~~tem__"> ~(rend co %$ %p 32.819)"~lasmev"> ~(rend co %$ %ux 18)"0x12"> ~(rend co [%$ p=[p=%if q=0x7f00.0001]])".127.0.0.1"> ~(rend co %many ~[[%$ %ud 20] [%$ %uw 133] [%$ %tas 'sam']])"._20_0w25_sam__"> ~(rend co %blob [1 1])"~0ph"
++a-co:co
Render decimal
Render dat
as a decimal integer without separators.
Accepts
dat
is an atom.
Produces
A tape
Source
++ a-co |=(dat=@ ((d-co 1) dat))
Examples
> (a-co:co 123.456.789)"123456789"
++c-co:co
Render base58check
Renders the given atom
as a base58check tape
.
Accepts
An atom
.
Produces
A tape
.
Source
++ c-co (em-co [58 1] |=([? b=@ c=tape] [~(c ne b) c]))
Examples
> (enc:fa 0xdead.beef)0xdead.beef.938b.8b0c> (c-co:co 0xdead.beef.938b.8b0c)"eFGDJSVvRHd"
++d-co:co
Render decimal with min length
Render hol
as a decimal integer without separators and with a minimum length of min
. If hol
has less than min
digits, leading zeros will be added to make up the difference.
Accepts
min
is an atom.
hol
is an atom.
Produces
A tape
.
Source
++ d-co |=(min=@ (em-co [10 min] |=([? b=@ c=tape] [~(d ne b) c])))
Examples
> ((d-co:co 1) 123.456)"123456"> ((d-co:co 9) 123.456)"000123456"
++r-co:co
Render floating point
Render decimal float a
as a tape
.
Accepts
a
is a ++dn
.
Produces
A tape
.
Source
++ r-co|= a=dn?: ?=([%i *] a) (weld ?:(s.a "inf" "-inf") rep)?: ?=([%n *] a) (weld "nan" rep)=; rep ?:(s.a rep ['-' rep])=/ f ((d-co 1) a.a)=^ e e.a=/ e=@s (sun:si (lent f))=/ sci :(sum:si e.a e -1)?: (syn:si (dif:si e.a --3)) [--1 sci] :: 12000 -> 12e3 e>+2?: !(syn:si (dif:si sci -2)) [--1 sci] :: 0.001 -> 1e-3 e<-2[(sum:si sci --1) --0] :: 1.234e2 -> '.'@3 -> 123 .4=? rep !=(--0 e.a):(weld ?:((syn:si e.a) "e" "e-") ((d-co 1) (abs:si e.a)))(weld (ed-co e f) rep)
Examples
> `tape`(r-co:co (rlys .3.14))"3.14"> `tape`(r-co:co (rlys .1.681557e-39))"1.681557e-39"
++s-co:co
Render hex list
Render esc
, a list of atoms, as hex with a dot before each value. Values less than two bytes in length will be padded with zeros.
Accepts
esc
is a (list @)
.
Produces
A tape
.
Source
++ s-co|= esc=(list @) ^- tape?~ esc rep['.' =>(.(rep $(esc t.esc)) ((x-co 4) i.esc))]
Examples
> `tape`(s-co:co ~[0xdead 0xbeef 0xcafe])".dead.beef.cafe"> `tape`(s-co:co ~[0xa 0xb 0xc])".000a.000b.000c"> `tape`(s-co:co ~[0xdead.beef])".deadbeef"
++v-co:co
Render base-32 with minimum length
Render hol
as base-32 with a minimum length of min
. If hol
is shorter than min
it will be padded with zeros.
Accepts
min
is a @ud
.
hol
is an atom.
Produces
A tape
.
Source
++ v-co |=(min=@ (em-co [32 min] |=([? b=@ c=tape] [~(v ne b) c])))
Examples
> `tape`((v-co:co 1) 0v2l7.eiug3.0mbd9)"2l7eiug30mbd9"> `tape`((v-co:co 20) 0v2l7.eiug3.0mbd9)"00000002l7eiug30mbd9"
++w-co:co
Render base-64 with minimum length
Render hol
as base-64 with a minimum length of min
. If hol
is horter than min
it will be padded with zeros.
Accepts
min
is a @ud
.
hol
is an atom.
Produces
A tape
.
Source
++ w-co |=(min=@ (em-co [64 min] |=([? b=@ c=tape] [~(w ne b) c])))
Examples
> `tape`((w-co:co 1) 0w2.OtBSR.pPVeT)"2OtBSRpPVeT"> `tape`((w-co:co 20) 0w2.OtBSR.pPVeT)"0000000002OtBSRpPVeT"
++x-co:co
Render hex with minimum length
Render hol
as hex with a minimum length of min
. If hol
is horter than min
it will be padded with zeros.
Accepts
min
is a @ud
.
hol
is an atom.
Produces
A tape
.
Source
++ x-co |=(min=@ (em-co [16 min] |=([? b=@ c=tape] [~(x ne b) c])))
Examples
> `tape`((x-co:co 1) 0xdead.beef)"deadbeef"> `tape`((x-co:co 20) 0xdead.beef)"000000000000deadbeef"
++y-co:co
Render decimal with at least two digits
Render dat
as a decimal with a minimum of two digits. If dat
is less than two digits it will be padded with zeros.
Accepts
dat
is an atom.
Produces
A tape
.
Source
++ y-co |=(dat=@ ((d-co 2) dat))
Examples
> (y-co:co 0)"00"> (y-co:co 1)"01"> (y-co:co 123)"123"> (y-co:co 123.456)"123456"
++z-co:co
Render '0x'-prefixed hex
Render dat
as hex with a 0x
prefix.
Accepts
dat
is an atom.
Produces
A tape
.
Source
++ z-co |=(dat=@ `tape`['0' 'x' ((x-co 1) dat)])
Examples
> (z-co:co 123)"0x7b"> (z-co:co 0xdead.beef)"0xdeadbeef"> (z-co:co 0)"0x0"
++em-co:co
Render in numeric base
In base bas
, format min
digits of hol
with par
. This is used internally by other rendering functions.
hol
is processed least-significant digit first.- All available digits in
hol
will be processed, butmin
digits can exceed the number available inhol
par
handles all accumulated output on each call, and can edit it, prepend or append digits, etc.- Until
hol
is exhausted,par
's sample is[| digit output]
, subsequently, it's[& 0 output]
.
Accepts
[bas=@ min=@]
, where bas
is the numeric base and min
is the minimum length.
par
is a gate
of $-([? @ tape] tape)
.
hol
is an atom.
Produces
A tape
.
Source
++ em-co|= [[bas=@ min=@] par=$-([? @ tape] tape)]|= hol=@^- tape?: &(=(0 hol) =(0 min))rep=/ [dar=@ rad=@] (dvr hol bas)%= $min ?:(=(0 min) 0 (dec min))hol darrep (par =(0 dar) rad rep)==
Examples
> ((em-co:co [16 10] |=([? b=@ c=tape] [~(x ne b) c])) 0xbeef)"000000beef"
++ed-co:co
Format with decimal place
Format int
by specifying its size with exp
, which may be negative. This is used internally by other rendering functions.
Accepts
exp
is a @s
.
int
is a tape
.
Produces
A tape
.
Source
++ ed-co|= [exp=@s int=tape] ^- tape=/ [pos=? dig=@u] [=(--1 (cmp:si exp --0)) (abs:si exp)]?. pos(into (weld (reap +(dig) '0') int) 1 '.')=/ len (lent int)?: (lth dig len) (into int dig '.')(weld int (reap (sub dig len) '0'))
Examples
> (ed-co:co --3 "100")"100"> (ed-co:co --5 "100")"10000"> (ed-co:co -1 "100")"0.0100"> (ed-co:co -5 "100")"0.00000100"
++ox-co:co
Format dot-separated digits in numeric base
In base bas
, format each digit of hol
with gate dug
, with '.' separators every gop
digits. This is used internally by other rendering functions.
hol
is processed least-significant digit first.dug
handles individual digits, output is prepended.- Every segment but the last is zero-padded to
gop
.
Accepts
[bas=@ gop=@]
where bas
is the numeric base and gop
is dot separator frequency.
dug
is a gate
of $-(@ @)
.
hol
is an atom.
Produces
A tape
.
Source
++ ox-co|= [[bas=@ gop=@] dug=$-(@ @)]%+ em-co[(pow bas gop) 0]|= [top=? seg=@ res=tape]%+ weld?:(top ~ `tape`['.' ~])%. seg%+ em-co(rep res)[bas ?:(top 0 gop)]|=([? b=@ c=tape] [(dug b) c])
Examples
> ((ox-co:co [2 4] |=(a=@ ~(d ne a))) 0b1011.1101)"1011.1101"> ((ox-co:co [2 1] |=(a=@ ~(d ne a))) 0b1011.1101)"1.0.1.1.1.1.0.1"> ((ox-co:co [2 100] |=(a=@ ~(d ne a))) 0b1011.1101)"10111101"
++ro-co:co
Format dot-prefixed bloqs in numeric base
In base bas
, for buz
bloqs 0 to dop
, format at least one digit of hol
, prefixed with .
. This is used internally for @i
address rendering functions.
Accepts
[buz=@ bas=@ dop=@]
where buz
is the bloq size, bas
is the numeric base, and dop
is the number of bloqs.
dug
is a gate
of $-(@ @)
.
hol
is an atom.
Produces
A tape
.
Source
++ ro-co|= [[buz=@ bas=@ dop=@] dug=$-(@ @)]|= hol=@^- tape?: =(0 dop)rep:- '.'=/ pod (dec dop)%. (cut buz [pod 1] hol)%+ em-co(rep $(dop pod))[bas 1]|=([? b=@ c=tape] [(dug b) c])
Examples
> ((ro-co:co [3 10 4] |=(a=@ ~(d ne a))) .127.0.0.1)".127.0.0.1"