Browse Source

Simple deconstructor implemented.

Terrence Brannon 9 years ago
parent
commit
b837df5f57
3 changed files with 42 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 6 0
      .idea/vcs.xml
  3. 35 0
      py/pointer.py

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+# Created by .ignore support plugin (hsz.mobi)

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 35 - 0
py/pointer.py

@@ -0,0 +1,35 @@
+class Pointer(object):
+
+    def __init__(self, d):
+        self.d = d
+        self.indices = []
+
+    @property
+    def r(self):
+        self.indices.append(1)
+        return self
+
+    @property
+    def l(self):
+        self.indices.append(0)
+        return self
+
+    @property
+    def E(self):
+        d = self.d
+        for i in self.indices:
+            d = d[i]
+        return d
+
+    # $ fun --m="&l"
+    # (True, None)
+
+    # $ fun --m="&ll"
+    # ((True, None), None)
+
+
+if __name__ == '__main__':
+    d = (3, (1,(7,2)))
+    p = Pointer(d)
+
+    print p.r.r.l.E