Derive `zip`.
This commit is contained in:
parent
787dc6a7b3
commit
da0e1e685e
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,56 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Zip</title>
|
||||||
|
<link rel="stylesheet" href="/css/font/fonts.css">
|
||||||
|
<link rel="stylesheet" href="/css/site.css">
|
||||||
|
<script src="/Joy.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="joy_interpreter"></div>
|
||||||
|
<h1>Zip</h1>
|
||||||
|
<p>Let's derive <code>zip</code>.</p>
|
||||||
|
<pre><code> [a b c ...] [e f g ...] zip
|
||||||
|
---------------------------------
|
||||||
|
[[a e] [b f] [c g] ...]
|
||||||
|
</code></pre>
|
||||||
|
<p>It's a <code>genrec</code>:</p>
|
||||||
|
<pre><code>zip == [null] [popop []] [R0] [R1] genrec
|
||||||
|
</code></pre>
|
||||||
|
<p>If the top list is empty, pop both lists and put a new empty list...</p>
|
||||||
|
<p>Hmm...</p>
|
||||||
|
<pre><code>zip == [null] [pop] [R0] [R1] genrec
|
||||||
|
</code></pre>
|
||||||
|
<p>We will assume that both lists are the same size, so if the top list is empty the second list shall be too, and we can reuse it to store our pairs.</p>
|
||||||
|
<p>Now then, we have two non-empty lists:</p>
|
||||||
|
<pre><code>[a b c ...] [e f g ...] R0 [zip] R1
|
||||||
|
</code></pre>
|
||||||
|
<p>Let's imagine a function <code>shift-pair</code>:</p>
|
||||||
|
<pre><code> [a ...] [e ...] shift-pair
|
||||||
|
--------------------------------
|
||||||
|
[a e] [...] [...]
|
||||||
|
</code></pre>
|
||||||
|
<p>I'm going to defer derivation of that for now.</p>
|
||||||
|
<pre><code>[a b c ...] [e f g ...] shift-pair [zip] R1
|
||||||
|
|
||||||
|
[a e] [b c ...] [f g ...] [zip] R1
|
||||||
|
</code></pre>
|
||||||
|
<p>And so <code>R1</code> is <code>i cons</code> (it's a list builder.)</p>
|
||||||
|
<pre><code>zip == [null] [pop] [shift-pair] [i cons] genrec
|
||||||
|
</code></pre>
|
||||||
|
<p>And now:</p>
|
||||||
|
<pre><code>shift-pair == uncons-two [quote-two] dipd
|
||||||
|
</code></pre>
|
||||||
|
<p>w/</p>
|
||||||
|
<pre><code>uncons-two == [uncons] ii swapd
|
||||||
|
quote-two == unit cons
|
||||||
|
|
||||||
|
[zip [null] [pop] [shift-pair] [i cons] genrec] inscribe
|
||||||
|
[shift-pair uncons-two [quote-two] dipd] inscribe
|
||||||
|
[uncons-two [uncons] ii swapd] inscribe
|
||||||
|
[quote-two unit cons] inscribe
|
||||||
|
</code></pre>
|
||||||
|
<script>var joy_interpreter = Elm.Main.init({node: document.getElementById('joy_interpreter')});</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -3362,5 +3362,5 @@ from each list. The smallest list sets the length of the result list.
|
||||||
|
|
||||||
[1 2 3] [4 5 6] zip
|
[1 2 3] [4 5 6] zip
|
||||||
-------------------------
|
-------------------------
|
||||||
[[4 1] [5 2] [6 3]]
|
[[1 4] [2 5] [3 6]]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
# Zip
|
||||||
|
|
||||||
|
Let's derive `zip`.
|
||||||
|
|
||||||
|
[a b c ...] [e f g ...] zip
|
||||||
|
---------------------------------
|
||||||
|
[[a e] [b f] [c g] ...]
|
||||||
|
|
||||||
|
It's a `genrec`:
|
||||||
|
|
||||||
|
zip == [null] [popop []] [R0] [R1] genrec
|
||||||
|
|
||||||
|
If the top list is empty, pop both lists and put a new empty list...
|
||||||
|
|
||||||
|
Hmm...
|
||||||
|
|
||||||
|
zip == [null] [pop] [R0] [R1] genrec
|
||||||
|
|
||||||
|
We will assume that both lists are the same size, so if the top list is empty the second list shall be too, and we can reuse it to store our pairs.
|
||||||
|
|
||||||
|
Now then, we have two non-empty lists:
|
||||||
|
|
||||||
|
[a b c ...] [e f g ...] R0 [zip] R1
|
||||||
|
|
||||||
|
Let's imagine a function `shift-pair`:
|
||||||
|
|
||||||
|
[a ...] [e ...] shift-pair
|
||||||
|
--------------------------------
|
||||||
|
[a e] [...] [...]
|
||||||
|
|
||||||
|
I'm going to defer derivation of that for now.
|
||||||
|
|
||||||
|
[a b c ...] [e f g ...] shift-pair [zip] R1
|
||||||
|
|
||||||
|
[a e] [b c ...] [f g ...] [zip] R1
|
||||||
|
|
||||||
|
And so `R1` is `i cons` (it's a list builder.)
|
||||||
|
|
||||||
|
zip == [null] [pop] [shift-pair] [i cons] genrec
|
||||||
|
|
||||||
|
And now:
|
||||||
|
|
||||||
|
shift-pair == uncons-two [quote-two] dipd
|
||||||
|
|
||||||
|
w/
|
||||||
|
|
||||||
|
uncons-two == [uncons] ii swapd
|
||||||
|
quote-two == unit cons
|
||||||
|
|
||||||
|
[zip [null] [pop] [shift-pair] [i cons] genrec] inscribe
|
||||||
|
[shift-pair uncons-two [quote-two] dipd] inscribe
|
||||||
|
[uncons-two [uncons] ii swapd] inscribe
|
||||||
|
[quote-two unit cons] inscribe
|
||||||
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
(define (defs) (list "eq [false] [true] [false] cmp" "gt [true] [false] [false] cmp" "lt [false] [false] [true] cmp" "neq [true] [false] [true] cmp" "le [false] [true] [true] cmp" "ge [true] [true] [false] cmp" "? dup bool" "!- 0 >=" "++ 1 +" "-- 1 -" "<{} [] swap" "<<{} [] rollup" "abs dup 0 < [] [neg] branch" "anamorphism [pop []] swap [dip swons] genrec" "and nulco [nullary [false]] dip branch" "app1 grba infrst" "app2 [grba swap grba swap] dip [infrst] cons ii" "app3 3 appN" "appN [grabN] codi map reverse disenstacken" "at drop first" "average [sum] [size] cleave /" "b [i] dip i" "binary unary popd" "ccccons ccons ccons" "ccons cons cons" "clear [] swaack pop" "cleave fork popdd" "clop cleave popdd" "cmp [[>] swap] dipd [ifte] ccons [=] swons ifte" "codi cons dip" "codireco codi reco" "dinfrirst dip infrst" "dipd [dip] codi" "dipdd [dip] cons dipd" "dipddd [dipd] cons dipd" "disenstacken swaack pop" "divmod [/] [%] clop" "down_to_zero [0 >] [dup --] while" "drop [rest] times" "dupdd [dup] dipd" "dupd [dup] dip" "dupdipd dup dipd" "dupdip dupd dip" "enstacken stack [clear] dip" "first uncons pop" "flatten <{} [concat] step" "fork [i] app2" "fourth rest third" "gcd true [tuck mod dup 0 >] loop pop" "genrec [[genrec] ccccons] nullary swons concat ifte" "grabN <{} [cons] times" "grba [stack popd] dip" "hypot [sqr] ii + sqrt" "ifte [nullary] dipd swap branch" "ii [dip] dupdip i" "infra swons swaack [i] dip swaack" "infrst infra first" "<< lshift" "lshift [2 *] times" "make_generator [codireco] ccons" "mod %" "neg 0 swap -" "not [true] [false] branch" "nulco [nullary] cons" "nullary [stack] dinfrirst" "null [] swap concat bool not" "of swap at" "or nulco [nullary] dip [true] branch" "over [dup] dip swap" "pam [i] map" "pm [+] [-] clop" "popdd [pop] dipd" "popd [pop] dip" "popopdd [popop] dipd" "popopd [popop] dip" "popopop pop popop" "popop pop pop" "pow 1 roll> swap [*] cons times" "product 1 swap [*] step" "quoted [unit] dip" "range [0 <=] [-- dup] anamorphism" "range_to_zero unit [down_to_zero] infra" "reco rest cons" "rest uncons popd" "reverse <{} shunt" "rolldown roll<" "roll< swapd swap" "roll> swap swapd" "rollup roll>" "rrest rest rest" ">> rshift" "rshift [2 /] times" "run <{} infra" "second rest first" "shift uncons [swons] dip" "shunt [swons] step" "size [pop ++] step_zero" "small dup null [rest null] [pop true] branch" "spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte" "split_at [drop] [take] clop" "split_list [take reverse] [drop] clop" "sqr dup mul" "stackd [stack] dip" "step_zero 0 roll> step" "stuncons stack uncons" "sum [+] step_zero" "swapd [swap] dip" "swoncat swap concat" "swons swap cons" "tailrec [i] genrec" "take <<{} [shift] times pop" "ternary binary popd" "third rest second" "tuck dup swapd" "unary nullary popd" "uncons [first] dupdip rest" "unit [] cons" "unquoted [i] dip" "unstack [[] swaack] dip swoncat swaack pop" "unswons uncons swap" "while swap nulco dupdipd concat loop" "x dup i" "step [_step0] x" "_step0 _step1 [popopop] [_stept] branch" "_step1 [?] dipd roll<" "_stept [uncons] dipd [dupdipd] dip x" "times [_times0] x" "_times0 _times1 [popopop] [_timest] branch" "_times1 [dup 0 >] dipd roll<" "_timest [[--] dip dupdipd] dip x" "map [_map0] cons [[] [_map?] [_mape]] dip tailrec" "_map? pop bool not" "_mape popd reverse" "_map0 [_map1] dipd _map2" "_map1 stackd shift" "_map2 [infrst] cons dipd roll< swons" "_isnt_bool not not" "_isnt_two_bools [_isnt_bool] ii" "_\\/_ [_isnt_bool] [not] branch" "/\\ _isnt_two_bools [pop false] [] branch" "\\/ _isnt_two_bools [] [pop true] branch" "xor [] [not] branch"))
|
(define (defs) (list "eq [false] [true] [false] cmp" "gt [true] [false] [false] cmp" "lt [false] [false] [true] cmp" "neq [true] [false] [true] cmp" "le [false] [true] [true] cmp" "ge [true] [true] [false] cmp" "? dup bool" "!- 0 >=" "++ 1 +" "-- 1 -" "<{} [] swap" "<<{} [] rollup" "abs dup 0 < [] [neg] branch" "anamorphism [pop []] swap [dip swons] genrec" "and nulco [nullary [false]] dip branch" "app1 grba infrst" "app2 [grba swap grba swap] dip [infrst] cons ii" "app3 3 appN" "appN [grabN] codi map reverse disenstacken" "at drop first" "average [sum] [size] cleave /" "b [i] dip i" "binary unary popd" "ccccons ccons ccons" "ccons cons cons" "clear [] swaack pop" "cleave fork popdd" "clop cleave popdd" "cmp [[>] swap] dipd [ifte] ccons [=] swons ifte" "codi cons dip" "codireco codi reco" "dinfrirst dip infrst" "dipd [dip] codi" "dipdd [dip] cons dipd" "dipddd [dipd] cons dipd" "disenstacken swaack pop" "divmod [/] [%] clop" "down_to_zero [0 >] [dup --] while" "drop [rest] times" "dupdd [dup] dipd" "dupd [dup] dip" "dupdipd dup dipd" "dupdip dupd dip" "enstacken stack [clear] dip" "first uncons pop" "first_two uncons first" "flatten <{} [concat] step" "fork [i] app2" "fourth rest third" "gcd true [tuck mod dup 0 >] loop pop" "genrec [[genrec] ccccons] nullary swons concat ifte" "grabN <{} [cons] times" "grba [stack popd] dip" "ifte [nullary] dipd swap branch" "ii [dip] dupdip i" "infra swons swaack [i] dip swaack" "infrst infra first" "<< lshift" "lshift [2 *] times" "make_generator [codireco] ccons" "mod %" "neg 0 swap -" "not [true] [false] branch" "nulco [nullary] cons" "nullary [stack] dinfrirst" "null _isnt_list bool not" "of swap at" "or nulco [nullary] dip [true] branch" "over [dup] dip swap" "pam [i] map" "pm [+] [-] clop" "popdd [pop] dipd" "popd [pop] dip" "popopdd [popop] dipd" "popopd [popop] dip" "popopop pop popop" "popop pop pop" "pow 1 roll> swap [*] cons times" "product 1 swap [*] step" "quoted [unit] dip" "range [0 <=] [-- dup] anamorphism" "range_to_zero unit [down_to_zero] infra" "reco rest cons" "rest uncons popd" "reverse <{} shunt" "rolldown roll<" "roll< swapd swap" "roll> swap swapd" "rollup roll>" "rrest rest rest" ">> rshift" "rshift [2 /] times" "run <{} infra" "second rest first" "shift uncons [swons] dip" "shunt [swons] step" "size [pop ++] step_zero" "small dup null [rest null] [pop true] branch" "spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte" "split_at [drop] [take] clop" "split_list [take reverse] [drop] clop" "sqr dup mul" "stackd [stack] dip" "step_zero 0 roll> step" "stuncons stack uncons" "sum [+] step_zero" "swapd [swap] dip" "swoncat swap concat" "swons swap cons" "tailrec [i] genrec" "take <<{} [shift] times pop" "ternary binary popd" "third rest second" "tuck dup swapd" "unary nullary popd" "uncons [first] dupdip rest" "unit [] cons" "unquoted [i] dip" "unstack [[] swaack] dip swoncat swaack pop" "unswons uncons swap" "while swap nulco dupdipd concat loop" "x dup i" "step [_step0] x" "_step0 _step1 [popopop] [_stept] branch" "_step1 [?] dipd roll<" "_stept [uncons] dipd [dupdipd] dip x" "times [_times0] x" "_times0 _times1 [popopop] [_timest] branch" "_times1 [dup 0 >] dipd roll<" "_timest [[--] dip dupdipd] dip x" "map [_map0] cons [[] [_map?] [_mape]] dip tailrec" "_map? pop bool not" "_mape popd reverse" "_map0 [_map1] dipd _map2" "_map1 stackd shift" "_map2 [infrst] cons dipd roll< swons" "_isnt_bool [false] [true] branch" "_isnt_two_bools [_isnt_bool] ii" "_\\/_ [_isnt_bool] [not] branch" "/\\ _isnt_two_bools [pop false] [] branch" "\\/ _isnt_two_bools [] [pop true] branch" "_isnt_list [] swoncat" "zip [null] [pop] [shift-pair] [i cons] genrec" "shift-pair uncons-two [quote-two] dipd" "uncons-two [uncons] ii swapd" "quote-two unit cons"))
|
||||||
Loading…
Reference in New Issue