This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%%% Formalization of a simply typed lambda-calculus with n-ary tuples. | |
| % I decided to do this because it seemed like something small and | |
| % interesting that was definitely not on the twelf wiki as a case | |
| % study or a tutorial. n-ary tuples are a great feature in that they | |
| % add no expressive power over pairs but are a much bigger pain to | |
| % machine formalize! | |
| % | |
| % Doing it on paper is mostly just a matter of sprinkling "subscript i" | |
| % and "..." around, but is otherwise pretty straightforward. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Do a FULL OUTER JOIN on User.name[0] = Card.name[0] | |
| # (the seed computable is to demonstrate that it works with computed data) | |
| WITH | |
| L := User { seed := random() }, | |
| R := Card, | |
| joined := DISTINCT { | |
| (FOR l IN {L} UNION ([l.id], [(SELECT R FILTER l.name[0] = R.name[0]).id] ?? <array<uuid>>[])), | |
| (FOR r IN {R} UNION (([(SELECT L FILTER L.name[0] = r.name[0]).id] ?? <array<uuid>>[]), [r.id])), | |
| }, | |
| FOR row in {joined} UNION ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # Run with: | |
| # edb test tests/test_edgeql_ir_scopetree.py 2>&1 | python3 scopetree-test-fixup.py -i | |
| import textwrap | |
| import sys | |
| from typing import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3.8 | |
| import sys | |
| import re | |
| def extract(s): | |
| return [int(x) for x in re.findall(r'-?\d+', s)] | |
| from z3 import Bool, Int, If, Not, Solver, And |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Fixer for six.iterkeys() -> .keys(), and similarly for iteritems and itervalues.""" | |
| from lib2to3 import fixer_util, fixer_base | |
| from lib2to3 import pytree | |
| from lib2to3.fixes import fix_dict | |
| from lib2to3.fixer_util import Call, Name | |
| import libpostmodernize | |
| class FixDict(fix_dict.FixDict): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| signature UNLAMBDA_REPR = | |
| sig | |
| type F | |
| val ap : F * F -> F | |
| val ul_I : F | |
| val ul_K : F | |
| val ul_S : F | |
| val ul_V : F | |
| val ul_Dot : char -> F | |
| val ul_C : F |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ... don't do this | |
| import sys | |
| from types import ModuleType | |
| def callme(): | |
| print("lol I'm a module") | |
| class CallableModule(ModuleType): | |
| def __call__(self, *args, **kwargs): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| initial state: # | |
| ..... => . | |
| ....# => . | |
| #.... => . | |
| #...# => . | |
| ...#. => # | |
| ...## => # | |
| #..#. => # | |
| #..## => # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from types import MethodType | |
| class strict_staticmethod: | |
| def __init__(self, f): | |
| self.f = f | |
| def __get__(self, obj, type=None): | |
| if obj is not None: | |
| raise AttributeError("strict_staticmethod can't be accessed through obj") | |
| return self.f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import cast | |
| class Tree: | |
| def accept(self, v: 'TreeVisitor') -> object: | |
| pass | |
| class Leaf(Tree): | |
| def accept(self, v: 'TreeVisitor') -> object: | |
| return v.visit_leaf(self) | |
| class Node(Tree): | |
| def __init__(self, value: int, left: Tree, right: Tree) -> None: | |
| self.value = value |