on c19bc7a help sign in
815 lines 18 kB history raw
1---
2navhome: /docs/
3---
62eP diff
7========
9A- more or less low priority and/or currently in the wrong section
10anyway.
12------------------------------------------------------------------------
14------------------------------------------------------------------------
16### `++berk`
18Invert diff patches
20Inverts a list of changes `bur`. Skips stay constant and replaces are
21swapped. Produces a `bur`.
23Accepts
24-------
26`bur` is a [`++urge`]().
28Produces
29--------
31The `++urge` of a noun.
33Source
34------
36 ++ berk :: invert diff patch
37 |* bur=(urge)
38 |- ^+ bur
39 ?~ bur ~
40 :_ $(bur t.bur)
41 ?- -.i.bur
42 & i.bur
43 | [%| q.i.bur p.i.bur]
44 ==
45 ::
47Examples
48--------
50 ~zod/try=> (berk `(urge)`~[`10 %|^[~[2] ~[3 4]] `5])
51 ~[[%.y p=10] [%.n p=~[3 4] q=~[2]] [%.y p=5]]
52 ~zod/try=> (lurk "somes" `(urge char)`~[`1 [%| "o" "a"] `3])
53 "sames"
54 ~zod/try=> (berk `(urge char)`~[`1 [%| "o" "a"] `3])
55 ~[[%.y p=1] [%.n p="a" q="o"] [%.y p=3]]
56 ~zod/try=> (lurk "sames" (berk `(urge char)`~[`1 [%| "o" "a"] `3]))
57 "somes"
59------------------------------------------------------------------------
61### `++diff`
63Generate patch
65Produces a patch between two nouns, by change type
67Accepts
68-------
70`pum` is an [`++umph`]().
72Produces
73--------
75An [`++udon`]()
77Source
78------
80 ++ diff :: generate patch
81 |= pum=umph
82 |= [old=* new=*] ^- udon
83 :- pum
84 ?+ pum ~|(%unsupported !!)
85 %a [%d (nude old new)]
86 %b =+ [hel=(cue ((hard ,@) old)) hev=(cue ((hard ,@) new))]
87 [%d (nude hel hev)]
88 %c =+ [hel=(lore ((hard ,@) old)) hev=(lore ((hard ,@) new))]
89 [%c (lusk hel hev (loss hel hev))]
90 ==
91 ::
93Examples
94--------
96 ~zod/try=> ((diff %a) 20 21)
97 [p=%a q=[%d p=[%1 p=21] q=[%1 p=20]]]
98 ~zod/try=> ((diff %a) [1 2 3] [1 2 4])
99 [ p=%a
100 q
101 [ %d
102 p=[p=[%0 p=2] q=[p=[%0 p=6] q=[%1 p=4]]]
103 q=[p=[%0 p=2] q=[p=[%0 p=6] q=[%1 p=3]]]
104 ]
105 ]
106 ~zod/try=> ~04hh
107 [1 2]
108 ~zod/try=> ~0ph
109 [1 1]
110 ~zod/try=> ((diff %b) 0v4hh 0vph)
111 [p=%b q=[%d p=[p=[%0 p=2] q=[%0 p=2]] q=[p=[%0 p=3] q=[%1 p=2]]]]
112 ~zod/try=> ((diff %c) (role 'sam' 'les' 'les' 'kor' ~) (role 'sam' 'mor' 'kor' ~))
113 [p=%c q=[%c p=~[[%.y p=1] [%.n p=~[7.562.604 7.562.604] q=~[7.499.629]] [%.y p=1]]]]
114 ~[[%.y p=0] [%.y p=0] [%.y p=1] [%.n p=<|les les|> q=<|mor|>] [%.y p=1]]
115 ~zod/try=> (,[%c %c (urge cord)] ((diff %c) (role 'sam' 'les' 'les' 'kor' ~) (role 'sam' 'mor' 'kor' ~)))
116 [%c %c ~[[%.y p=1] [%.n p=<|les les|> q=<|mor|>] [%.y p=1]]]
118------------------------------------------------------------------------
120### `++loss`
122Longest subsequence
124Finds a subsequence of repeated elements within two [`++list`]()s, using
125several internal helper arms. Produces a [`++tape`]().
127Accepts
128-------
130`hel` is a [`++list`]() of [nouns]().
132`hev` is a [++list`]() of nouns.
134Produces
135--------
137XX
139A [++list`]() of nouns.
141Source
142------
144 ++ loss :: longest subsequence
145 ~/ %loss
146 |* [hel=(list) hev=(list)]
147 |- ^+ hev
148 =+ ^= sev
149 =+ [inx=0 sev=*(map ,@t (list ,@ud))]
150 |- ^+ sev
151 ?~ hev sev
152 =+ guy=(~(get by sev) i.hev)
153 $(hev t.hev, inx +(inx), sev (~(put by sev) i.hev [inx ?~(guy ~ u.guy)]))
154 =| gox=[p=@ud q=(map ,@ud ,[p=@ud q=_hev])]
155 =< abet
156 =< main
157 |%
158 ++ abet =.(q.rag ?:(=([& 0] p.rag) q.rag [p.rag q.rag]) (flop q.rag))
159 ++ hink :: extend fits top
160 |= [inx=@ud goy=@ud] ^- ?
161 |(=(p.gox inx) (lth goy p:(need (~(get by q.gox) inx))))
162 ::
163 ++ lonk :: extend fits bottom
164 |= [inx=@ud goy=@ud] ^- ?
165 |(=(0 inx) (gth goy p:(need (~(get by q.gox) (dec inx)))))
166 ::
167 ++ lune :: extend
168 |= [inx=@ud goy=@ud]
169 ^+ +>
170 %_ +>.$
171 gox
172 :- ?:(=(inx p.gox) +(p.gox) p.gox)
173 %+ ~(put by q.gox) inx
174 [goy (snag goy hev) ?:(=(0 inx) ~ q:(need (~(get by q.gox) (dec inx))))]
175 ==
176 ::
177 ++ merg :: merge all matches
178 |= gay=(list ,@ud)
179 ^+ +>
180 =+ ^= zes
181 =+ [inx=0 zes=*(list ,[p=@ud q=@ud])]
182 |- ^+ zes
183 ?: |(?=(~ gay) (gth inx p.gox)) zes
184 ?. (lonk inx i.gay) $(gay t.gay)
185 ?. (hink inx i.gay) $(inx +(inx))
186 $(inx +(inx), gay t.gay, zes [[inx i.gay] zes])
187 |- ^+ +>.^$
188 ?~(zes +>.^$ $(zes t.zes, +>.^$ (lune i.zes)))
189 ::
190 ++ main
191 |- ^+ +
192 ?~ hel
193 ?~ hev
194 ?>(?=(~ lcs) +)
195 $(hev t.hev, rag (done %| ~ [i.hev ~]))
196 ?~ hev
197 $(hel t.hel, rag (done %| [i.hel ~] ~))
198 ?~ lcs
199 +(rag (done %| (flop hel) (flop hev)))
200 ?: =(i.hel i.lcs)
201 ?: =(i.hev i.lcs)
202 $(lcs t.lcs, hel t.hel, hev t.hev, rag (done %& 1))
203 $(hev t.hev, rag (done %| ~ [i.hev ~]))
204 ?: =(i.hev i.lcs)
205 $(hel t.hel, rag (done %| [i.hel ~] ~))
206 $(hel t.hel, hev t.hev, rag (done %| [i.hel ~] [i.hev ~]))
207 --
209Examples
210--------
212 ~zod/try=> (loss "sam" "sem")
213 "sm"
214 ~zod/try=> (loss "samo" "semo")
215 "smo"
216 ~zod/try=> (loss "sakmo" "semo")
217 "smo"
218 ~zod/try=> (loss "ferdinham" "ferdilapos
219 ~ <syntax error at [1 30]>
220 ~zod/try=> (loss "ferdinham" "ferdilapos")
221 "ferdia"
223------------------------------------------------------------------------
225### `++locz`
227Find common
229Finds a subsequence of repeated elements within two
230[`++list`](/docs/hoon/library/1#++list)s, producing a [\`++tape]().
232Accepts
233-------
235A cell of two `++tape`s, `hel` and `hev`.
237Produces
238--------
240A `++tape`.
242Source
243------
245 ++ locz :: trivial algorithm
246 |= [hel=tape hev=tape]
247 ^- tape
248 =+ [leh=(lent hel) veh=(lent hev)]
249 =- (flop q.yun)
250 ^= yun
251 |- ^- [p=@ud q=tape]
252 ~+
253 ?: |(=(0 leh) =(0 veh)) [0 ~]
254 =+ [dis=(snag (dec leh) hel) dat=(snag (dec veh) hev)]
255 ?: =(dis dat)
256 =+ say=$(leh (dec leh), veh (dec veh))
257 [+(p.say) [dis q.say]]
258 =+ [lef=$(leh (dec leh)) rig=$(veh (dec veh))]
259 ?:((gth p.lef p.rig) lef rig)
260 ::
262Examples
263--------
265 ~zod/try=> (locz "samukot" "semelkot")
266 "smkot"
267 ~zod/try=> (locz "samukot" "samelkot")
268 "samkot"
270------------------------------------------------------------------------
272### `++lore`
274Split on `\n`
276Split on newlines, ascii `10`
278Accepts
279-------
281`lub` is an atom.
283Produces
284--------
286XX
288A `++list` of atoms of odor [`@t`]() ([`++cord`]()).
290Source
291------
292 ++ lore :: atom to line list
293 ~/ %lore
294 |= lub=@
295 =| tez=(list ,@t)
296 |- ^+ tez
297 ?: =(0 lub) (flop tez)
298 =+ ^= meg
299 =+ meg=0
300 |- ^- @ud
301 =+ gam=(cut 3 [meg 1] lub)
302 ?:(|(=(10 gam) =(0 gam)) meg $(meg +(meg)))
303 =+ res=(rsh 3 +(meg) lub)
304 ?: &(=(0 (cut 3 [meg 1] lub)) !=(0 res))
305 !!
306 $(lub res, tez [(end 3 meg lub) tez])
307 ::
309Examples
310--------
312 ~zod/try=> (lore 'soke\0alas\0amep')
313 <|soke las mep|>
314 ~zod/try=> (lore '|= a=@\0a=+ b=(add a 5)\0a(mix b a)')
315 <||= a=@ =+ b=(add a 5) (mix b a)|>
316 ~zod/try=> `wain`[(fil 3 80 ' ') (lore '|= a=@\0a=+ b=(add a 5)\0a(mix b a)')]
317 <|
318 |= a=@
319 =+ b=(add a 5)
320 (mix b a)
321 |>
323------------------------------------------------------------------------
325### `++role`
327Join with `\n`
329Join line list with newlines.
331Accepts
332-------
334A `++list` of atoms of [odor]() [`@t`]() ([`++cord`]()).
336Produces
337--------
339XX
341An atom of [odor]() [`@t`]() ([`++cord`]().
343Source
344------
346 ++ role :: line list to atom
347 |= tez=(list ,@t)
348 (rap 3 (turn tez |=(a=@t (cat 3 a 10))))
349 ::
351Examples
352--------
354 ~zod/try=> (role 'sep' 'tek' 'lap' ~)
355 3.230.709.852.558.292.782.985.274.739
356 ~zod/try=> `@t`(role 'sep' 'tek' 'lap' ~)
357 '''
358 sep
359 tek
360 lap
361 '''
363------------------------------------------------------------------------
365### `++lump`
367Change with `++udon`
369Use [`++udon`]() to change [noun]().
371Accepts
372-------
374A cell of an `++udon`, `don`, and a noun, `src`.
376Produces
377--------
379A noun.
381Source
382------
384 ++ lump :: apply patch
385 |= [don=udon src=*]
386 ^- *
387 ?+ p.don ~|(%unsupported !!)
388 %a
389 ?+ -.q.don ~|(%unsupported !!)
390 %a q.q.don
391 %c (lurk ((hard (list)) src) p.q.don)
392 %d (lure src p.q.don)
393 ==
394 ::
395 %c
396 =+ dst=(lore ((hard ,@) src))
397 %- role
398 ?+ -.q.don ~|(%unsupported !!)
399 %a ((hard (list ,@t)) q.q.don)
400 %c (lurk dst p.q.don)
401 ==
402 ==
403 ::
405Examples
406--------
408 ~zod/try=> (lump [%a %a 20 25] 20)
409 25
410 ~zod/try=> (lump [%a %d [[%0 1] [%0 1]] [%0 2]] 20)
411 [20 20]
412 ~zod/try=> (lump [%c %a ~['sa' 'le'] ~['sa' 'lo']] 'sa\0ale')
413 11.473.670.267.251
414 ~zod/try=> (,@t (lump [%c %a ~['sa' 'le'] ~['sa' 'lo']] 'sa\0ale'))
415 '''
416 sa
417 lo
418 '''
419 ~zod/try=> (,@t (lump [%c %c `1 [%| ~['le'] ~['lo' 'ma']] ~] 'sa\0ale'))
420 '''
421 sa
422 ma
423 lo
424 '''
426------------------------------------------------------------------------
428### `++lure`
430Patch `a`
432Patch a by references to axis and literal.
434Accepts
435-------
437A cell of a [noun](), `a`, and an [`++upas`](), `b`.
439Produces
440--------
442A noun.
444Source
445------
447 ++ lure :: apply tree diff
448 |= [a=* b=upas]
449 ^- *
450 ?^ -.b
451 [$(b -.b) $(b +.b)]
452 ?+ -.b ~|(%unsupported !!)
453 %0 .*(a [0 p.b])
454 %1 .*(a [1 p.b])
455 ==
457Examples
458--------
460 ~zod/try=> (lure ~[1 2] [[%0 2] [%1 3] [%0 7]])
461 [1 3 0]
462 ~zod/try=> (lure ~[1 2 4] [[%0 2] [%1 3] [%0 7]])
463 [1 3 4 0]
465------------------------------------------------------------------------
467### `++limp`
469Reverse patch
471Reverse a patch (preprocessor unchanged)
473Accepts
474-------
476`don` is an [`++udon`]().
478Produces
479--------
481An `++udon`.
483Source
484------
486 ++ limp :: invert patch
487 |= don=udon ^- udon
488 :- p.don
489 ?+ -.q.don ~|(%unsupported !!)
490 %a [%a q.q.don p.q.don]
491 %c [%c (berk p.q.don)]
492 %d [%d q.q.don p.q.don]
493 ==
494 ::
496Examples
497--------
499 ~zod/try=> (limp [%a %a 20 40])
500 [p=%a q=[%a p=40 q=20]]
501 ~zod/try=> (limp [%c %c ~[`20 [%| ~[52 53] ~[51]] `6]])
502 [p=%c q=[%c p=~[[%.y p=20] [%.n p=~[51] q=~[52 53]] [%.y p=6]]]]
503 ~zod/try=> (limp [%a %d [[%0 1] [%0 1]] [%0 2]])
504 [p=%a q=[%d p=[%0 p=2] q=[p=[%0 p=1] q=[%0 p=1]]]]
506------------------------------------------------------------------------
508### `++hump`
510Prep for diff
512Prep atom for diff: leave alone, cue, or split by newlines.
514Accepts
515-------
517A cell of an [`++umph`](), `pum`, and a [noun](), `src`.
519Produces
520--------
522A noun.
524Source
525------
527 ++ hump :: general prepatch
528 |= [pum=umph src=*] ^- *
529 ?+ pum ~|(%unsupported !!)
530 %a src
531 %b (cue ((hard ,@) src))
532 %c (lore ((hard ,@) src))
533 ==
534 ::
536Examples
537--------
539 ~zod/try=> (hump %a ~)
540 0
541 ~zod/try=> (hump %a 40)
542 40
543 ~zod/try=> (hump %c 40)
544 [40 0]
545 ~zod/try=> (hump %c 'as')
546 [29.537 0]
547 ~zod/try=> (hump %c 'as\0alok')
548 [29.537 7.040.876 0]
549 ~zod/try=> (hump %b 0vph)
550 [1 1]
552------------------------------------------------------------------------
554### `++husk`
556Atomize post diff
558Re-atomize after diff: leave alone, jam, or join with newlines.
560Accepts
561-------
563A cell of an [`++umph`](), `pum`, and a [noun](), `dst`.
565Produces
566--------
568A noun.
570Source
571------
573 ++ husk :: unprepatch
574 |= [pum=umph dst=*] ^- *
575 ?+ pum ~|(%unsupported !!)
576 %a dst
577 %b (jam dst)
578 %c (role ((hard (list ,@)) dst))
579 ==
580 ::
582Examples
583--------
585 ~zod/try=> (husk %a 0)
586 0
587 ~zod/try=> (husk %a 40)
588 40
589 ~zod/try=> (husk %c [40 0])
590 2.600
591 ~zod/try=> (rip 3 (,@ (husk %c [40 0])))
592 ~[40 10]
593 ~zod/try=> (husk %c [%as 0])
594 684.897
595 ~zod/try=> (husk %c [%as 0])
596 684.897
597 ~zod/try=> (,@t (husk %c [%as 0]))
598 '''
599 as
600 '''
601 ~zod/try=> (husk %c [%as %lok 0])
602 2.932.876.065.272.673
603 ~zod/try=> (,@t (husk %c [%as %lok 0]))
604 '''
605 as
606 lok
607 '''
608 ~zod/try=> (husk %b [1 1])
609 817
610 ~zod/try=> (,@uv (husk %b [1 1]))
611 0vph
612 ~zod/try=> ~0ph
613 [1 1]
615------------------------------------------------------------------------
617### `++lurk`
619Apply list patch
621Amend list using an urge: [`++list`]() of `[%& {number skipped}]` and
622`[%| old new]`
625Accepts
626-------
628A cell of a `++list` of [noun]()s, `hel`, and an [`++urge`]() of a noun, `rug`.
630Produces
631--------
633A `++list` of nouns.
635Source
636------
638 ++ lurk :: apply list patch
639 |* [hel=(list) rug=(urge)]
640 ^+ hel
641 =+ war=`_hel`~
642 |- ^+ hel
643 ?~ rug (flop war)
644 ?- -.i.rug
645 &
646 %= $
647 rug t.rug
648 hel (slag p.i.rug hel)
649 war (weld (flop (scag p.i.rug hel)) war)
650 ==
651 ::
652 |
653 %= $
654 rug t.rug
655 hel =+ gur=(flop p.i.rug)
656 |- ^+ hel
657 ?~ gur hel
658 ?>(&(?=(^ hel) =(i.gur i.hel)) $(hel t.hel, gur t.gur))
659 war (weld q.i.rug war)
660 ==
661 ==
662 ::
664Examples
665--------
667 ~zod/try=> (lurk "hema" `(urge char)`~[`1 [%| "e" "ru"] `2])
668 "hurma"
669 ~zod/try=> (lurk "koltep" `(urge char)`~[`3 [%| "et" ""] `1])
670 "kolp"
672------------------------------------------------------------------------
674### `++lusk`
676`lcs` to list patch
678Using a common sequence, generate urge from two [`++list`]()s.
681Accepts
682-------
684A cell of three `++list`s of [noun](), `hel`, `hev`, and `lcs`.
686Produces
687--------
689Source
690------
692 ++ lusk :: lcs to list patch
693 |* [hel=(list) hev=(list) lcs=(list)]
694 =+ ^= rag
695 ^- $% [& p=@ud]
696 [| p=_lcs q=_lcs]
697 ==
698 [%& 0]
699 => .(rag [p=rag q=*(list ,_rag)])
700 =< abet =< main
701 |%
702 ++ abet =.(q.rag ?:(=([& 0] p.rag) q.rag [p.rag q.rag]) (flop q.rag))
703 ++ done
704 |= new=_p.rag
705 ^+ rag
706 ?- -.p.rag
707 | ?- -.new
708 | [[%| (weld p.new p.p.rag) (weld q.new q.p.rag)] q.rag]
709 & [new [p.rag q.rag]]
710 ==
711 & ?- -.new
712 | [new ?:(=(0 p.p.rag) q.rag [p.rag q.rag])]
713 & [[%& (add p.p.rag p.new)] q.rag]
714 ==
715 ==
716 ::
717 ++ main
718 |- ^+ +
719 ?~ hel
720 ?~ hev
721 ?>(?=(~ lcs) +)
722 $(hev t.hev, rag (done %| ~ [i.hev ~]))
723 ?~ hev
724 $(hel t.hel, rag (done %| [i.hel ~] ~))
725 ?~ lcs
726 +(rag (done %| (flop hel) (flop hev)))
727 ?: =(i.hel i.lcs)
728 ?: =(i.hev i.lcs)
729 $(lcs t.lcs, hel t.hel, hev t.hev, rag (done %& 1))
730 $(hev t.hev, rag (done %| ~ [i.hev ~]))
731 ?: =(i.hev i.lcs)
732 $(hel t.hel, rag (done %| [i.hel ~] ~))
733 $(hel t.hel, hev t.hev, rag (done %| [i.hel ~] [i.hev ~]))
734 --
736Examples
737--------
739 ~zod/try=> (lusk "hamok" "hasok" "haok")
740 ~[[%.y p=2] [%.n p="m" q="s"] [%.y p=2]]
741 ~zod/try=> (lusk "hamok" "hasok" "hak")
742 ~[[%.y p=2] [%.n p="om" q="os"] [%.y p=1]]
743 ~zod/try=> (lusk "telroga" "tesomga" "teoga")
744 ~[[%.y p=2] [%.n p="rl" q="s"] [%.y p=1] [%.n p="" q="m"] [%.y p=2]]
745 ~zod/try=> (lurk "telroga" `(urge char)`~[[%.y p=2] [%.n p="rl" q="s"] [%.y p=1] [%.n p="" q="m"] [%.y p=2]])
746 "tesomga"
748------------------------------------------------------------------------
750### `++nude`
752Tree change
754Generate tree diff from two nouns.
756Accepts
757-------
759A cell of two nouns, `a` and `b`.
761Produces
762--------
764A cell of two [`++upas`](), `p` and `q`.
766Source
767------
769 ++ nude :: tree change
770 |= [a=* b=*]
771 ^- [p=upas q=upas]
772 =< [p=(tred a b) q=(tred b a)]
773 |%
774 ++ axes :: locs of nouns
775 |= [a=@ b=*] ^- (map ,* axis)
776 =+ c=*(map ,* axis)
777 |- ^- (map ,* axis)
778 => .(c (~(put by c) b a))
779 ?@ b
780 c
781 %- ~(uni by c)
782 %- ~(uni by $(a (mul 2 a), b -.b))
783 $(a +((mul 2 a)), b +.b)
784 ::
785 ++ tred :: diff a->b
786 |= [a=* b=*] ^- upas
787 =| c=(unit ,*)
788 =+ d=(axes 1 a)
789 |- ^- upas
790 => .(c (~(get by d) b))
791 ?~ c
792 ?@ b
793 [%1 b]
794 =+ e=^-(upas [$(b -.b) $(b +.b)])
795 ?- e
796 [[%1 *] [%1 *]] [%1 [p.p.e p.q.e]]
797 * e
798 ==
799 [%0 u.c]
800 --
802Examples
803--------
805 ~zod/try=> (nude 40 20)
806 [p=[%1 p=20] q=[%1 p=40]]
807 ~zod/try=> (nude [5 5] 5)
808 [p=[%0 p=3] q=[p=[%0 p=1] q=[%0 p=1]]]
809 ~zod/try=> (nude "sam" "sal")
810 [ p=[p=[%1 p=115] q=[p=[%1 p=97] q=[p=[%1 p=108] q=[%0 p=15]]]]
811 q=[p=[%1 p=115] q=[p=[%1 p=97] q=[p=[%1 p=109] q=[%0 p=15]]]]
812 ]
814------------------------------------------------------------------------