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