Skip to content

Instantly share code, notes, and snippets.

@michaelochurch
Created April 29, 2016 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelochurch/d29a3c988ed6ae9ccf6594b7a647f9fd to your computer and use it in GitHub Desktop.
Save michaelochurch/d29a3c988ed6ae9ccf6594b7a647f9fd to your computer and use it in GitHub Desktop.
Building up a power-set operator in FiniteSetBang3
: There is probably a mistake in here...
: Macroexpanded prod in FSB3 with %-comprehensions:
: Keep in mind that [] are *-loops in this language.
: prod : ... X Y -> ... {(x, y) for x in X, y in Y}
prod:%[{~/~/>~{~/~/~/{%[{~/~/>~{~/~/~/>{~/~/>~~{{~/~/>/{~/~/>/{~/~/~/>{{~/~/>/{~/~/>/{{~/~/>/{~/~/>/~{{~/~/>/{~/~/>/]{~/~/>_]{~/~/>_
Conversion of %-comprehensions:
%[(code)] --> {{~/~/>[Z(code){{~/~/~/>{~/~/~/>[Z~{{~/~/>/{~/~/>/{~/~/~/>{~/~/~/>{~/~/>/{~/~/>]_{~/~/>]_
: prod : ... X Y -> ... {(x, y) for x in X, y in Y}
prod: {{~/~/>[Z{~/~/>~{~/~/~/{{{~/~/>[Z{~/~/>~{~/~/~/>{~/~/>~~{{~/~/>/{~/~/>/{~/~/~/>{{~/~/>/{~/~/>/{{~/~/>/{~/~/>/~{{~/~/>/{~/~/>/{{~/~/~/>{~/~/~/>[Z~{{~/~/>/{~/~/>/{~/~/~/>{~/~/~/>{~/~/>/{~/~/>]_{~/~/>]_{~/~/>_{{~/~/~/>{~/~/~/>[Z~{{~/~/>/{~/~/>/{~/~/~/>{~/~/~/>{~/~/>/{~/~/>]_{~/~/>]_{~/~/>_
: lists : ... X -> ... {l : l is a #X-long linked list of either {x} or {} for x ∈ X using some consistent order}
lists:{~/{~/~/>[Z~{{~/~/>/{~/~/>/{~/~/~/>{~/~/>{{{~/~/>/{~/~/>/{~/~/>{{~/~/>[Z{~/~/>~{~/~/~/{{{~/~/>[Z{~/~/>~{~/~/~/>{~/~/>~~{{~/~/>/{~/~/>/{~/~/~/>{{~/~/>/{~/~/>/{{~/~/>/{~/~/>/~{{~/~/>/{~/~/>/{{~/~/~/>{~/~/~/>[Z~{{~/~/>/{~/~/>/{~/~/~/>{~/~/~/>{~/~/>/{~/~/>]_{~/~/>]_{~/~/>_{{~/~/~/>{~/~/~/>[Z~{{~/~/>/{~/~/>/{~/~/~/>{~/~/~/>{~/~/>/{~/~/>]_{~/~/>]_{~/~/>_{~/~/>]_
: recall [(then),(else)] -> ~{=~[__(else){{{]__~[_(then){{]__
: removeEmpty : ... x y z w -> ... a b c which are three of x y z w with an {} removed. Loops forever if no {}.
: removeEmpty:[{~/~/~/~/>]_
: dup2 in FSB3
: dup2 : ... X Y -> X Y X Y
: dup2 : {~/~/>~{~/~/~/>{~/~/~/>~{~/~/~/>
: not in FSB3
: not:{=
: magic : ... a b c -> ... returns h t where [h, h, t] is some permutation of a b c. Loops forever if no two are equal.
: magic:{~/[_{~/~/~/>(dup2)=(not)]_{~/~/>
: magic:{~/[_{~/~/~/>{~/~/>~{~/~/~/>{~/~/~/>~{~/~/~/>={=]_{~/~/>
: split : ... (h, t) -> ... h t
: This is surprisingly complicated, because we've given up our set operations. We use a bunch of Z's and movement operators to get
: ... (h, t) -> <h t h {} in some order>
: then we use removeEmpty to remove an {} and magic to get h t in the right order.
split:Z{~/~/>Z{~/~/>_~{=~[___~{{{]__~[_{{]__~Z{~/~/>Z{~/~/~/>{~/~/~/>~Z{~/~/>Z(removeEmpty)(magic)
split:Z{~/~/>Z{~/~/>_~{=~[___~{{{]__~[_{{]__~Z{~/~/>Z{~/~/~/>{~/~/~/>~Z{~/~/>Z[{~/~/~/~/>]_{~/[_{~/~/~/>{~/~/>~{~/~/~/>{~/~/~/>~{~/~/~/>={=]_{~/~/>
1st:(split)_
2nd:(split){~/~/>_
: union
union:[Z{~/~/~/>{~/~/~/>{~/~/>/{~/~/>]_
listToSet:{{~/~/>[~(1st){~/~/>(2n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/>]_{~/~/>_{~/~/>]_{{~/~/>[Z{{~/~/>[~Z{~/~/>Z{~/~/>_~{=~[___~{{{]__~[_{{]__~Z{~/~/>Z{~/~/~/>{~/~/~/>~Z{~/~/>Z[{~/~/~/~/>]_{~/[_{~/~/~/>{~/~/>~{~/~/~/>{~/~/~/>~{~/~/~/>={=]_{~/~/>_{~/~/>Z{~/~/>Z{~/~/>_~{=~[___~{{{]__~[_{{]__~Z{~/~/>Z{~/~/~/>{~/~/~/>~Z{~/~/>Z[{~/~/~/~/>]_{~/[_{~/~/~/>{~/~/>~{~/~/~/>{~/~/~/>~{~/~/~/>={=]_{~/~/>{~/~/>_{~/~/}>~{=~[___{{{]__~[_[Z{~/~/~/>{~/~/~/>{~/~/>/{~/~/>]_{{]__{~/~/>]_{{~/~/>/{{~/~/~/>{~/~/~/>[Z~{{~/~/>/{~/~/>/{~/~/~/>{~/~/~/>{~/~/>/{~/~/>]_{~/~/>]_
: 824 characters long!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment