urbit/gen/cosmetic.hoon

1040 lines
28 KiB
Plaintext
Raw Normal View History

2018-04-20 19:45:45 +03:00
:: "Hello world" sample generator
::
:::: /hoon/hello/gen
::
/? 310
2018-07-30 04:19:29 +03:00
!:
2018-04-20 19:45:45 +03:00
::
::::
::
:- %say
2018-04-22 08:29:21 +03:00
|= {^ {{subject=type ~} ~}}
:- %txt
^- wain
=< =/ spec=spec ~(structure cosmetic subject)
=/ plum=plum (spec-to-plum spec)
~(tall plume plum)
2018-04-20 19:45:45 +03:00
|%
2018-07-30 04:19:29 +03:00
::
:: *cosmetic-state: for cosmetic below
::
2018-08-07 23:35:02 +03:00
+* cosmetic-state [form]
2018-07-30 04:19:29 +03:00
$: :: count: cumulative blocks detected
:: pairs: blocking numbers and specs
::
count=@ud
2018-08-07 23:35:02 +03:00
pairs=(map type (pair @ud form))
2018-07-30 04:19:29 +03:00
==
::
2018-08-07 23:35:02 +03:00
+* analyst [form]
$_ ^?
|%
++ atom *$-([aura=term constant=(unit @)] form)
++ cell *$-([=form =form] form)
++ core *$-([=vair =form =(map term form)] form)
++ face *$-([decor=$@(term tune) =form] form)
++ fork *$-(=(list form) form)
++ loop *$-([=form =(map @ud form)] form)
--
::
:: $xray: initial type analysis
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
+$ scan
$-
$@ $? %noun
%void
==
$% [%bare =atom =aura] :: constant
[%bark =(map atom aura)] :: constant set
2018-07-30 04:19:29 +03:00
+$ shoe
$@ %void :: empty
2018-08-07 23:35:02 +03:00
$% [%bark =(map atom type)] :: flat constants
[%bush wide=shoe long=shoe] :: by cell/atom head
[%leaf =type] :: any atom
[%root flat=shoe deep=shoe] :: by atom/cell
[%tree =type] :: any cell
[%wood =(map atom (pair type type))] :: by atom head
2018-07-30 04:19:29 +03:00
== ::
::
2018-08-07 23:35:02 +03:00
:: =merge: combine two shoes
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
++ merge-shoes
|= [one=shoe two=shoe]
^- (unit shoe)
?@ one `two
?@ two `one
?- -.one
%bark
?- -.two
%bark
:+ ~ %bark
:: (both maps merged, combining collisions)
::
=/ list ~(tap by map.one)
|- ^- (map atom type)
?~ list map.two
%= $
list t.list
map.two
%+ ~(put by map.two)
p.i.list
=+ (~(get by map.two) p.i.list)
?~ - q.i.list
(fork u.- q.i.list ~)
==
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%bush
`[%root one two]
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%leaf
:- ~
:- %leaf
%+ fork
type.two
(turn ~(tap by map.one) |=([* =type] type))
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%root
%+ bind $(two flat.two)
|= new=shoe
[%root new deep.two]
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%tree
`[%root one two]
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%wood
`[%root one two]
==
::
%bush
?+ -.two $(one two, two one)
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%bush
%^ clef
$(one wide.one, two wide.two)
$(one long.one, two long.two)
|=([wide=shoe long=shoe] `[%root wide long])
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%leaf
`[%root two one]
::
%root
%+ bind $(two deep.two)
|= new=shoe
[%root flat.two new]
::
%tree
~
::
%wood
%+ bind $(one long.one)
|= new=shoe
[%bush wide.one new]
2018-07-30 04:19:29 +03:00
==
::
2018-08-07 23:35:02 +03:00
%leaf
?+ -.two $(one two, two one)
::
%leaf
`[%leaf (fork type.one type.two ~)]
::
%root
%+ bind $(two flat.two)
|= new=shoe
[%root new deep.two]
::
%tree
`[%root one two]
::
%wood
`[%root one two]
==
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%root
?+ -.two $(one two, two one)
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%root
%^ clef
$(one flat.one, two flat.two)
$(one deep.one, two deep.two)
|=([flat=shoe deep=shoe] `[%root flat deep])
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%tree
%+ bind $(one deep.one)
|= new=shoe
[%root one new]
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
%wood
%+ bind $(one deep.one)
|= new=shoe
[%root one new]
==
::
%tree
?+ -.two $(one two, two one)
::
%tree
`[%tree (fork type.one type.two ~)]
::
%wood
~
==
::
%wood
?+ -.two $(one two, two one)
::
%wood
:: (both maps merged, combining collisions)
2018-07-30 04:19:29 +03:00
::
2018-08-07 23:35:02 +03:00
:- ~
:- %wood
=/ list ~(tap by map.one)
|- ^- (map atom (pair type type))
?~ list map.two
%= $
list t.list
map.two
%+ ~(put by map.two)
p.i.list
=+ (~(get by map.two) p.i.list)
?~ - q.i.list
[(fork p.u.- p.q.i.list ~) (fork q.u.- q.q.i.list ~)]
2018-07-30 04:19:29 +03:00
==
2018-08-07 23:35:02 +03:00
==
==
::
:: =shew: deconstruct type
::
++ shew
|= =type
:: (analysis of .type, if well-formed)
::
^- (unit shoe)
=- :: (analysis without trivial cases)
::
%+ biff -
|= =shoe
?- shoe
%void ~
[%bark *] ?:(?=([* ~ ~] map.shoe) ~ `shoe)
[%bush *] `shoe
[%leaf *] ~
[%root *] `shoe
[%tree *] ~
[%wood *] ?:(?=([* ~ ~] map.shoe) ~ `shoe)
==
|^ =| gil/(set ^type)
|- ^- (unit shoe)
?- type
%void `%void
%noun ~
::
[%atom *] as-done
[%cell *] :: if the head of .type is always a cell
::
?: is-cell(type p.type)
:: (a trivial bush)
::
`[%bush [%tree type] %void]
:: unless the head of .type is an atom
::
?. is-atom(type p.type)
:: (an opaque cell)
::
`[%tree type]
%+ biff to-atom(type p.type)
|= =atom
:: (a trivial wood)
::
`[%wood [%atom p.type q.type] ~ ~]
[%core *] ~
[%face *] as-done
[%fork *] =/ list ~(tap in p.type)
|- ^- (unit shoe)
?~ list `%void
%+ biff ^$(type i.list)
|= =shoe
%+ biff ^$(list t.list)
|= =^shoe
(merge-shoes shoe ^shoe)
::
[%hint *] $(type q.type)
[%hold *] ?: (~(has in gil) type) `%void
$(gil (~(put in gil) type), type ~(repo ut type))
==
::
++ is-atom (~(nest ut [%atom %$ ~]) %| type)
++ is-cell (~(nest ut [%cell %noun %noun]) %| type)
++ as-done ?: is-atom
=+ to-atom
?~ -
`[%leaf type]
`[%bark [u.- type] ~ ~]
?: is-cell
`[%tree type]
~
++ to-atom |- ^- (unit atom)
?- type
%void ~
%noun !!
[%atom *] q.type
[%cell *] !!
[%core *] !!
[%fork *] =/ list ~(tap in p.type)
?~ list !!
|- ^- (unit atom)
=+ ^$(type i.list)
?~ t.list -
%+ biff -
|= =atom
%+ biff ^$(i.list i.t.list, t.list t.t.list)
|= =^atom
?.(=(atom ^atom) ~ `atom)
[%face *] $(type q.type)
[%hint *] $(type q.type)
[%hold *] $(type ~(repo ut type))
==
2018-07-30 04:19:29 +03:00
--
2018-06-03 00:39:43 +03:00
::
2018-04-22 08:29:21 +03:00
++ cosmetic
2018-08-07 23:35:02 +03:00
%- (kismet spec)
2018-07-30 04:19:29 +03:00
|%
++ atom
|= $: :: aura: flavor of atom
:: constant: one value, or all values
::
aura=term
constant=(unit @)
==
^- spec
:: if atom is not constant
::
?~ constant
:: %base: flavored atom with arbitrary value
::
[%base atom/aura]
:: %leaf: flavored constant
::
[%leaf aura u.constant]
::
++ cell
|= $: :: head: head of cell
:: tail: tail of cell
::
head=spec
tail=spec
==
^- spec
:: %bscl: raw tuple
::
?: ?=(%bscl -.tail)
[%bscl head +.tail]
[%bscl head tail ~]
::
++ core
|= $: :: variance: co/contra/in/bi
:: payload: data
:: battery: code
::
variance=vair
payload=spec
battery=(map term spec)
==
?- variance
%lead [%bszp payload battery]
%gold [%bsdt payload battery]
%zinc [%bstc payload battery]
%iron [%bsnt payload battery]
==
::
++ face
|= $: :: decor: decoration
:: content: decorated content
::
decor=$@(term tune)
body=spec
==
^- spec
?@ decor [%bsts decor body]
:: discard aliases, etc
::
body
::
++ fork
|= specs=(list spec)
^- spec
?< ?=(~ specs)
[%bswt specs]
--
::
:: type-to-spec
::
++ kismet
2018-08-07 23:35:02 +03:00
|* form=mold
|= producer=(analyst form)
2018-04-23 05:41:24 +03:00
=| :: coat: contextual metadata
::
$= coat
$: :: trace: type analysis stack
::
trace=(set type)
==
=| :: load: accumulating metadata (state)
::
2018-08-07 23:35:02 +03:00
load=(cosmetic-state form)
2018-04-22 08:29:21 +03:00
::
:: sut: type we're analyzing
::
|_ sut/type
::
:: +structure: make cosmetic spec from :sut
::
++ structure
^- spec
2018-04-27 02:05:50 +03:00
:: clear superficial structure and hints
::
=. sut |- ^- type
?. ?=([?(%hint %hold) *] sut) sut
$(sut ~(repo ut sut))
::
2018-04-22 08:29:21 +03:00
:: spec: raw analysis product
::
2018-04-23 05:41:24 +03:00
=^ spec load specify
2018-04-22 08:29:21 +03:00
:: if we didn't block, just use it
::
2018-04-23 05:41:24 +03:00
?: =(~ pairs.load) spec
2018-04-22 08:29:21 +03:00
:: otherwise, insert hygienic recursion
::
2018-06-03 00:39:43 +03:00
:+ %bsbs spec
2018-04-22 08:29:21 +03:00
%- ~(gas by *(map term ^spec))
%+ turn
2018-04-23 05:41:24 +03:00
~(tap by pairs.load)
2018-04-22 08:29:21 +03:00
|= [=type index=@ud spec=^spec]
[(synthetic index) spec]
::
:: +pattern: pattern and context for data inspection
::
++ pattern
^- $: :: main: rendering pattern
:: context: recursion points by counter
::
main=plot
loop=(map @ud plot)
==
!!
::
:: +synthetic: convert :number to a synthetic name
::
++ synthetic
|= number=@ud
^- @tas
2018-04-23 08:04:12 +03:00
=/ alf/(list term)
^~ :~ %alf %bet %gim %dal %hej %vav %zay %het
%tet %yod %kaf %lam %mem %nun %sam %ayn
%pej %sad %qof %res %sin %tav
==
?: (lth number 22)
(snag number alf)
(cat 3 (snag (mod number 22) alf) $(number (div number 22)))
2018-04-22 08:29:21 +03:00
::
:: +specify: make spec that matches :sut
::
++ specify
2018-04-23 05:41:24 +03:00
^- [spec _load]
2018-04-22 08:29:21 +03:00
=< entry
|%
:: +entry: make spec at potential entry point
::
++ entry
2018-04-23 05:41:24 +03:00
^- [spec _load]
2018-04-23 08:04:12 +03:00
:: old: old recursion binding for :sut
::
=/ old (~(get by pairs.load) sut)
:: if, already bound, reuse binding
::
?^ old [[%loop (synthetic p.u.old)] load]
2018-04-23 05:41:24 +03:00
:: if, we are already inside :sut
2018-04-22 08:29:21 +03:00
::
2018-04-23 05:41:24 +03:00
?: (~(has in trace.coat) sut)
:: then, produce and record a block reference
2018-04-22 08:29:21 +03:00
::
2018-04-23 05:41:24 +03:00
=+ [%loop (synthetic count.load)]
2018-04-22 08:29:21 +03:00
:- -
2018-04-23 05:41:24 +03:00
%_ load
count +(count.load)
pairs (~(put by pairs.load) sut [count.load -])
2018-04-22 08:29:21 +03:00
==
2018-04-23 05:41:24 +03:00
:: else, filter main loop for block promotion
2018-04-22 08:29:21 +03:00
::
2018-04-23 05:41:24 +03:00
=^ spec load main(trace.coat (~(put in trace.coat) sut))
2018-04-23 08:04:12 +03:00
:: check if we re-entered :sut while traversing
2018-04-22 08:29:21 +03:00
::
2018-04-23 08:04:12 +03:00
=/ new (~(get by pairs.load) sut)
:: if, we did not find :sut inside itself
2018-04-22 08:29:21 +03:00
::
2018-04-23 08:04:12 +03:00
?~ new
:: then, :sut is not a true entry point
::
2018-04-23 05:41:24 +03:00
[spec load]
2018-04-23 08:04:12 +03:00
:: else, produce a reference and record the analysis
2018-04-22 08:29:21 +03:00
::
2018-04-23 08:04:12 +03:00
:- [%loop (synthetic p.u.new)]
load(pairs (~(put by pairs.load) sut [p.u.new spec]))
2018-04-22 08:29:21 +03:00
::
2018-04-24 02:31:22 +03:00
:: +meta: try to make spec from type of filter
::
2018-04-24 09:07:37 +03:00
::++ meta ^- [(unit spec) _load]
2018-04-24 02:31:22 +03:00
::
2018-04-22 08:29:21 +03:00
:: +main: make spec from any type
::
2018-04-23 05:41:24 +03:00
++ main
^- [spec _load]
2018-04-22 08:29:21 +03:00
?- sut
2018-04-23 05:41:24 +03:00
%void :_(load [%base %void])
%noun :_(load [%base %noun])
2018-04-22 08:29:21 +03:00
::
[%atom *] (atom p.sut q.sut)
[%cell *] (cell p.sut q.sut)
[%core *] (core p.sut q.sut)
[%face *] (face p.sut q.sut)
2018-04-25 09:07:21 +03:00
[%hint *] =+((rely p.p.sut q.p.sut) ?^(- u.- main(sut q.sut)))
2018-04-22 08:29:21 +03:00
[%fork *] (fork p.sut)
[%hold *] entry(sut ~(repo ut sut))
==
::
2018-04-25 09:07:21 +03:00
:: +rely: rationalize structure from type (stub)
2018-04-22 08:29:21 +03:00
::
2018-04-25 09:07:21 +03:00
++ rely
|= [=type =note]
^- (unit [spec _load])
2018-06-03 00:39:43 +03:00
?. ?=(%made -.note) ~
?~ q.note
`[`spec`[%like [[p.note ~] ~]] load]
=- `[[%make [%limb p.note] -<] ->]
|- ^- [(list spec) _load]
?~ u.q.note [~ load]
=^ more load $(u.q.note t.u.q.note)
=/ part (~(play ut type) [%tsld [%limb %$] [%wing i.u.q.note]])
=^ spec load entry(sut part)
[[spec more] load]
2018-04-22 08:29:21 +03:00
::
:: +atom: convert atomic type to spec
::
++ atom
|= $: :: aura: flavor of atom
:: constant: one value, or all values
::
aura=term
constant=(unit @)
==
:: pure function
::
2018-07-30 04:19:29 +03:00
[(atom:producer aura constant) load]
2018-04-22 08:29:21 +03:00
::
:: +cell: convert a %cell to a spec
::
++ cell
|= $: :: left: head of cell
:: rite: tail of cell
::
left=type
rite=type
==
2018-04-23 05:41:24 +03:00
^- [spec _load]
2018-04-22 08:29:21 +03:00
:: head: cosmetic structure of head
:: tail: cosmetic structure of tail
::
2018-04-23 05:41:24 +03:00
=^ head load main(sut left)
=^ tail load main(sut rite)
2018-07-30 04:19:29 +03:00
[(cell:producer head tail) load]
2018-04-22 08:29:21 +03:00
::
:: +core: convert a %core to a spec
::
++ core
|= $: :: payload: data
:: battery: code
::
payload=type
battery=coil
==
2018-04-23 05:41:24 +03:00
^- [spec _load]
2018-04-22 08:29:21 +03:00
:: payload-spec: converted payload
::
2018-04-23 05:41:24 +03:00
=^ payload-spec load main(sut payload)
2018-04-22 08:29:21 +03:00
:: arms: all arms in the core, as hoons
::
=/ arms
^- (list (pair term hoon))
%- zing
^- (list (list (pair term hoon)))
2018-06-03 00:39:43 +03:00
%+ turn ~(tap by q.r.battery)
|= [term =tome]
~(tap by q.tome)
2018-04-22 08:29:21 +03:00
:: arm-specs: all arms in the core, as specs
::
2018-04-23 05:41:24 +03:00
=^ arm-specs load
|- ^- [(list (pair term spec)) _load]
?~ arms [~ load]
=^ mor load $(arms t.arms)
=^ les load
2018-04-22 08:29:21 +03:00
main(sut [%hold [%core payload battery] q.i.arms])
2018-04-23 05:41:24 +03:00
[[[p.i.arms les] mor] load]
2018-04-22 08:29:21 +03:00
:: arm-map: all arms in the core, as a a spec map
::
=* arm-map (~(gas by *(map term spec)) arm-specs)
2018-07-30 04:19:29 +03:00
[(core:producer r.p.battery payload-spec arm-map) load]
2018-04-22 08:29:21 +03:00
::
:: +face: convert a %face to a +spec
::
++ face
|= $: :: decor: decoration
:: content: decorated content
::
2018-06-03 00:39:43 +03:00
decor=$@(term tune)
2018-04-22 08:29:21 +03:00
content=type
==
2018-04-23 05:41:24 +03:00
^- [spec _load]
=^ body load main(sut content)
2018-07-30 04:19:29 +03:00
[(face:producer decor body) load]
2018-04-22 08:29:21 +03:00
::
:: +fork: convert a %fork to a +spec
::
++ fork
|= types=(set type)
2018-04-23 05:41:24 +03:00
^- [spec _load]
2018-04-22 08:29:21 +03:00
:: type-list: type set as a list
::
=/ type-list ~(tap by types)
:: specs: type set as a list of specs
::
2018-04-23 05:41:24 +03:00
=^ specs load
|- ^- [(list spec) _load]
?~ type-list [~ load]
=^ mor load $(type-list t.type-list)
=^ les load main(sut i.type-list)
[[les mor] load]
2018-07-30 04:19:29 +03:00
[(fork:producer specs) load]
2018-04-22 08:29:21 +03:00
--
--
::
2018-04-20 19:45:45 +03:00
++ plume
|_ =plum
::
:: +flat: print as a single line
::
++ flat
text:linear
::
:: +tall: print as multiple lines
::
++ tall
^- wain
%+ turn window
|= [indent=@ud text=tape]
(crip (runt [indent ' '] text))
2018-04-22 08:29:21 +03:00
::
:: +adjust: adjust lines to right
::
++ adjust
|= [tab=@ud =(list [length=@ud text=tape])]
(turn list |=([@ud tape] [(add tab +<-) +<+]))
2018-04-20 19:45:45 +03:00
::
:: +window: print as list of tabbed lines
::
++ window
^- (list [indent=@ud text=tape])
:: memoize for random access
::
~+
:: trivial text
::
?@ plum [0 (trip plum)]~
?- -.plum
:: %|: text wrap
::
%| :: wrapping stub, should wrap text to 40 characters
::
[0 +:linear]~
::
:: %&: text tree
::
2018-04-25 09:07:21 +03:00
%& :: trial: attempt at wide hint
2018-04-20 19:45:45 +03:00
::
2018-04-21 08:43:16 +03:00
=/ trial ?~(wide.plum ~ [~ u=linear])
2018-04-25 09:07:21 +03:00
:: if wide hint is available or optimal
2018-04-20 19:45:45 +03:00
::
?: ?& ?=(^ trial)
?| ?=(~ tall.plum)
2018-04-21 08:43:16 +03:00
(lte length.u.trial 40)
2018-04-20 19:45:45 +03:00
== ==
2018-04-25 09:07:21 +03:00
:: then produce wide hint
2018-04-20 19:45:45 +03:00
::
2018-04-21 08:43:16 +03:00
[0 text.u.trial]~
2018-04-20 19:45:45 +03:00
:: else assert tall style (you gotta set either wide or tall)
::
?> ?=(^ tall.plum)
2018-04-22 08:29:21 +03:00
:: blocks: subwindows
2018-04-20 19:45:45 +03:00
:: prelude: intro as tape
::
2018-04-22 08:29:21 +03:00
=/ blocks (turn list.plum |=(=^plum window(plum plum)))
2018-04-20 19:45:45 +03:00
=/ prelude (trip intro.u.tall.plum)
2018-04-21 08:43:16 +03:00
:: if, :indef is empty
2018-04-20 19:45:45 +03:00
::
?~ indef.u.tall.plum
2018-04-21 08:43:16 +03:00
:: then, print in sloping mode
2018-04-20 19:45:45 +03:00
::
2018-04-22 08:29:21 +03:00
:: if, no children
2018-04-21 08:43:16 +03:00
::
2018-04-22 08:29:21 +03:00
?: =(~ blocks)
:: then, the prelude if any
2018-04-21 08:43:16 +03:00
::
?~(prelude ~ [0 prelude]~)
2018-04-22 08:29:21 +03:00
:: else, format children and inject any prelude
2018-04-21 08:43:16 +03:00
::
^- (list [indent=@ud text=tape])
2018-04-22 08:29:21 +03:00
:: concatenate child blocks into a single output
::
2018-04-21 08:43:16 +03:00
%- zing
2018-04-22 08:29:21 +03:00
:: count: number of children
:: index: current child from 1 to n
::
=/ count (lent blocks)
2018-04-21 08:43:16 +03:00
=/ index 1
2018-04-22 08:29:21 +03:00
|- ^+ blocks
?~ blocks ~
:_ $(blocks t.blocks, index +(index))
2018-04-21 08:43:16 +03:00
^- (list [indent=@ud text=tape])
2018-04-22 08:29:21 +03:00
:: indent: backstep indentation level
::
2018-04-21 08:43:16 +03:00
=/ indent (mul 2 (sub count index))
2018-04-22 08:29:21 +03:00
:: unless, we're on the first block
::
?. =(1 index)
:: else, apply normal backstep indentation
::
(adjust indent i.blocks)
:: then, apply and/or inject prelude
::
:: this fixes the naive representations
::
:: :+
:: foo
:: bar
:: baz
::
:: and
::
:: :-
:: foo
:: bar
::
=. indent (max indent (add 2 (lent prelude)))
=. i.blocks (adjust indent i.blocks)
?~ i.blocks ?~(prelude ~ [0 prelude]~)
?~ prelude i.blocks
:_ t.i.blocks
2018-04-21 08:43:16 +03:00
:- 0
2018-04-22 08:29:21 +03:00
~| [%indent indent]
~| [%prelude prelude]
~| [%kids list.plum]
~| [%blocks blocks]
2018-04-21 08:43:16 +03:00
%+ weld prelude
2018-04-22 08:29:21 +03:00
(runt [(sub indent.i.i.blocks (lent prelude)) ' '] text.i.i.blocks)
2018-04-21 08:43:16 +03:00
::
:: else, print in vertical mode
2018-04-20 19:45:45 +03:00
::
:: prefix: before each entry
:: finale: after all entries
::
=/ prefix (trip sigil.u.indef.u.tall.plum)
=/ finale (trip final.u.indef.u.tall.plum)
2018-04-21 08:43:16 +03:00
:: if, no children, then, just prelude and finale
2018-04-20 19:45:45 +03:00
::
2018-04-22 08:29:21 +03:00
?: =(~ blocks)
2018-04-20 19:45:45 +03:00
%+ weld
?~(prelude ~ [0 prelude]~)
?~(finale ~ [0 finale]~)
2018-04-23 08:04:12 +03:00
:: if, no :prefix
2018-04-20 19:45:45 +03:00
::
?: =(~ prefix)
:: kids: flat list of child lines
:: tab: amount to indent kids
::
2018-04-22 08:29:21 +03:00
=/ kids `(list [indent=@ud text=tape])`(zing blocks)
2018-04-21 08:43:16 +03:00
=* tab =+((lent prelude) ?+(- 2 %0 0, %1 2, %2 4))
2018-04-20 19:45:45 +03:00
:: indent kids by tab
::
=. kids (turn kids |=([@ud tape] [(add tab +<-) +<+]))
:: prepend or inject prelude
::
=. kids
?: =(~ prelude) kids
2018-04-23 08:04:12 +03:00
:: if, no kids, or prelude doesn't fit
2018-04-20 19:45:45 +03:00
::
2018-04-21 08:43:16 +03:00
?: |(?=(~ kids) (gte +((lent prelude)) indent.i.kids))
2018-04-20 19:45:45 +03:00
:: don't inject, just add to head if needed
::
[[0 prelude] kids]
:: inject: prelude
::
=* inject %+ weld
prelude
%+ runt
2018-04-21 08:43:16 +03:00
[(sub indent.i.kids (lent prelude)) ' ']
2018-04-20 19:45:45 +03:00
text.i.kids
[[0 inject] t.kids]
:: append finale
::
?~ finale kids
2018-04-21 08:43:16 +03:00
(weld kids ^+(kids [0 finale]~))
2018-04-20 19:45:45 +03:00
:: else, with :prefix
::
:: append :finale
::
=- ?~ finale -
2018-04-21 08:43:16 +03:00
(weld - ^+(- [0 finale]~))
^- (list [indent=@ud text=tape])
2018-04-23 08:04:12 +03:00
:: clear: clearance needed to miss prefix
::
=/ clear (add 2 (lent prefix))
2018-04-20 19:45:45 +03:00
%- zing
:: combine each subtree with the prefix
::
2018-04-22 08:29:21 +03:00
%+ turn blocks
2018-04-20 19:45:45 +03:00
|= =(list [indent=@ud text=tape])
^+ +<
2018-04-23 08:04:12 +03:00
:: tab: depth to indent
::
=* tab ?~(list 0 (sub clear (min clear indent.i.list)))
2018-04-20 19:45:45 +03:00
=. list (turn list |=([@ud tape] [(add tab +<-) +<+]))
2018-04-21 08:43:16 +03:00
?~ list ~
2018-04-20 19:45:45 +03:00
:_ t.list
:- 0
%+ weld
prefix
2018-04-21 08:43:16 +03:00
(runt [(sub indent.i.list (lent prefix)) ' '] text.i.list)
2018-04-20 19:45:45 +03:00
==
::
:: +linear: make length and tape
::
++ linear
^- $: length=@ud
text=tape
==
:: memoize for random access
::
~+
:: atomic plums are just text
::
?@ plum [(met 3 plum) (trip plum)]
?- -.plum
:: %|: text wrap
::
%| :: lay the text out flat, regardless of length
::
|- ^- [length=@ud text=tape]
?~ list.plum [0 ~]
=/ next $(list.plum t.list.plum)
=/ this [length=(met 3 i.list.plum) text=(trip i.list.plum)]
:- (add +(length.this) length.next)
(weld text.this `tape`[' ' text.next])
::
:: %&: text tree
::
%& :: if there is no wide representation
::
?~ wide.plum
:: then lay out a window, then separate with double-spaces
::
=/ window window
|- ^- [length=@ud text=tape]
?~ window [0 ~]
=/ next $(window t.window)
:- :(add (lent text.i.window) 2 length.next)
2018-04-22 08:29:21 +03:00
?~(text.next text.i.window :(weld text.i.window " " text.next))
2018-04-20 19:45:45 +03:00
::
:: else use wide layout
::
=- :: add enclosure if any
::
2018-04-21 08:43:16 +03:00
?~ enclose.u.wide.plum body
2018-04-20 19:45:45 +03:00
=* clamps u.enclose.u.wide.plum
=/ close [(trip -.clamps) (trip +.clamps)]
2018-04-21 08:43:16 +03:00
:- :(add length.body (lent -.close) (lent +.close))
:(weld -.close text.body +.close)
2018-04-20 19:45:45 +03:00
::
2018-04-21 08:43:16 +03:00
:: body: body of wide rendering
::
^= body
2018-04-20 19:45:45 +03:00
=/ stop (trip delimit.u.wide.plum)
|- ^- [length=@ud text=tape]
?~ list.plum [0 ~]
=/ next $(list.plum t.list.plum)
2018-04-21 08:43:16 +03:00
=/ this linear(plum i.list.plum)
2018-04-22 08:29:21 +03:00
?~ text.next this
2018-04-20 19:45:45 +03:00
:- :(add length.this (lent stop) length.next)
:(weld text.this stop text.next)
==
--
:: highly unsatisfactory temporary tank printer
2018-04-20 19:45:45 +03:00
::
++ plum-to-tank
|= =plum
^- tank
?@ plum [%leaf (trip plum)]
?- -.plum
%| :+ %rose
["" " " ""]
(turn list.plum |=(@ta [%leaf (trip +<)]))
%& =/ list (turn list.plum ..$)
?~ tall.plum
?> ?=(^ wide.plum)
=? enclose.u.wide.plum ?=(~ enclose.u.wide.plum) `['{' '}']
:+ %rose
2018-04-22 08:29:21 +03:00
:* (trip delimit.u.wide.plum)
(trip +<:enclose.u.wide.plum)
2018-04-20 19:45:45 +03:00
(trip +>:enclose.u.wide.plum)
==
list
?: ?=(^ indef.u.tall.plum)
:+ %rose
2018-04-22 08:29:21 +03:00
:* (trip sigil.u.indef.u.tall.plum)
(weld (trip intro.u.tall.plum) "[")
(weld "]" (trip final.u.indef.u.tall.plum))
2018-04-20 19:45:45 +03:00
==
list
:+ %palm
:* (weld (trip intro.u.tall.plum) "(")
2018-04-22 08:29:21 +03:00
""
""
2018-04-20 19:45:45 +03:00
")"
==
list
==
++ limb-to-plum
|= =limb
2018-04-26 08:32:37 +03:00
?@ limb limb
2018-04-20 19:45:45 +03:00
?- -.limb
%& (scot %ui p.limb)
%| (crip (runt [0 p.limb] ?~(q.limb "," (trip u.q.limb))))
==
::
++ wing-to-plum
|= =wing
^- plum
:+ %&
[`['.' ~] ~]
(turn wing limb-to-plum)
::
++ battery-to-plum
|= =(map term spec)
%+ turn ~(tap by map)
|= [=term =spec]
:+ %&
2018-04-23 05:41:24 +03:00
[`[' ' ~] `['' ~]]
2018-04-20 19:45:45 +03:00
[term (spec-to-plum spec) ~]
::
++ core-to-plum
|= [=knot =spec =(map term spec)]
^- plum
:+ %&
[~ `[knot ~]]
:~ (spec-to-plum spec)
:+ %&
2018-04-23 05:41:24 +03:00
[~ `['' `['++' '--']]]
2018-04-20 19:45:45 +03:00
(battery-to-plum map)
==
::
2018-04-23 05:41:24 +03:00
++ varying
|= [intro=knot final=knot]
[`[' ' `[(cat 3 intro '(') ')']] `[intro `['' final]]]
::
++ fixed
2018-04-20 19:45:45 +03:00
|= @ta
[`[' ' `[(cat 3 +< '(') ')']] `[+< ~]]
::
++ standard
|= =stud
^- plum
?@ stud stud
:+ %&
[`['/' ~] ~]
`(list plum)`[auth.stud type.stud]
::
++ hoon-to-plum
|= =hoon
^- plum
2018-04-26 08:32:37 +03:00
:: XX fill this in please
::
?: ?=([%limb *] hoon)
p.hoon
2018-04-20 19:45:45 +03:00
%hooon
::
2018-07-30 04:19:29 +03:00
++ skin-to-plum
|= =skin
^- plum
%skinny
::
2018-04-20 19:45:45 +03:00
++ spec-to-plum
|= =spec
^- plum
?- -.spec
%base ?- p.spec
%noun '*'
%cell '^'
%flag '?'
%null '~'
%void '!!'
[%atom *] (cat 3 '@' p.p.spec)
==
%dbug $(spec q.spec)
2018-04-23 05:41:24 +03:00
%leaf =+((scot p.spec q.spec) ?:(=('~' -) - (cat 3 '%' -)))
2018-04-20 19:45:45 +03:00
%like &/[[`[':' ~] ~] (turn `(list wing)`+.spec wing-to-plum)]
2018-04-23 08:04:12 +03:00
%loop (cat 3 '$' p.spec)
2018-04-25 23:24:13 +03:00
%name $(spec q.spec)
%made $(spec q.spec)
2018-04-20 19:45:45 +03:00
%over $(spec q.spec)
%make =+ (lent q.spec)
:+ %&
:- `[' ' `['(' ')']]
:- ~
?: |((gth - 3) =(- 0))
['%:' `['' '==']]
:_ ~
?: =(- 3) '%^'
?: =(- 2) '%+' '%-'
[(hoon-to-plum p.spec) (turn q.spec ..$)]
2018-06-03 00:39:43 +03:00
%bsbs (core-to-plum '$$' p.spec q.spec)
%bsbr &/[(fixed '$|') $(spec p.spec) (hoon-to-plum q.spec) ~]
%bscb (hoon-to-plum p.spec)
%bscl :+ %&
2018-04-20 19:45:45 +03:00
[`[' ' `['[' ']']] `['$:' `['' '==']]]
(turn `(list ^spec)`+.spec ..$)
2018-06-03 00:39:43 +03:00
%bscn &/[(varying '$%' '==') (turn `(list ^spec)`+.spec ..$)]
%bsdt (core-to-plum '$.' p.spec q.spec)
%bsld &/[(fixed '$<') $(spec p.spec) $(spec q.spec) ~]
%bsbn &/[(fixed '$>') $(spec p.spec) $(spec q.spec) ~]
%bshp &/[(fixed '$-') $(spec p.spec) $(spec q.spec) ~]
%bskt &/[(fixed '$-') $(spec p.spec) $(spec q.spec) ~]
%bsls &/[(fixed '$+') (standard p.spec) $(spec q.spec) ~]
%bsnt (core-to-plum '$/' p.spec q.spec)
%bsmc &/[(fixed '$;') (hoon-to-plum p.spec) ~]
%bspd &/[(fixed '$&') $(spec p.spec) (hoon-to-plum q.spec) ~]
%bssg &/[(fixed '$~') (hoon-to-plum p.spec) $(spec q.spec) ~]
%bstc (core-to-plum '$`' p.spec q.spec)
%bsts :+ %&
2018-04-20 19:45:45 +03:00
[`['=' ~] `['$=' ~]]
2018-07-30 04:19:29 +03:00
:~ (skin-to-plum p.spec)
2018-04-20 19:45:45 +03:00
$(spec q.spec)
==
2018-06-03 00:39:43 +03:00
%bsvt &/[(fixed '$@') $(spec p.spec) $(spec q.spec) ~]
%bswt :+ %&
2018-04-23 05:41:24 +03:00
[`[' ' `['?(' ')']] `['$?' `['' '==']]]
(turn `(list ^spec)`+.spec ..$)
2018-06-03 00:39:43 +03:00
%bszp (core-to-plum '$.' p.spec q.spec)
2018-04-20 19:45:45 +03:00
==
--