diff --git a/Examples/example_module.py b/Examples/example_module.py deleted file mode 100644 index f83e0e3..0000000 --- a/Examples/example_module.py +++ /dev/null @@ -1,14 +0,0 @@ -from pymark.util import flags, enum - -merchandise, reward, bonus = flags(3) -body_armor, helmets, gloves, boots = enum(4) - -def modifiers(*args): return args; -def cost(x): return x - -example_module = { - "explorer_jacket" : ( "Explorer Jacket", "greatcoat_new", merchandise|reward, body_armor, cost(214), {"weight" : 5, "protection" : 11}, modifiers("old", "ragged", "torn") ), - "chaps" : ( "Chaps", "chaps", merchandise|bonus, boots, cost(23), {"weight" : 1, "protection" : 2}, modifiers("wrapped", "posh", "battered") ), - "sailor_shirt" : ( "Sailor Shirt", "sailor_shirt", merchandise, body_armor, cost(112), {"weight" : 3, "protection" : 4}, modifiers("wet") ), - "pegleg" : ( "Peg Leg", "peg_leg_m", None, boots, cost(321), {"weight" : 7, "protection" : 4}, modifiers("wonky", "new") ), -} diff --git a/Examples/pets.py b/Examples/pets.py deleted file mode 100644 index 9dc9286..0000000 --- a/Examples/pets.py +++ /dev/null @@ -1,36 +0,0 @@ - -pets = [ - - {"name": "John", - "animal": "Dog", - "legs": 4, - "age": 10, - "toys": ["squeezy","bone"], - "traits": ["Cute","Funny","Friendly"], - "color": "Brown"}, - - {"name": "Benni", - "animal": "Cat", - "legs": 4, - "age": 8, - "toys": ["mouse_ball","string"], - "traits": ["Cute","Vain"], - "color": "Ginger"}, - - {"name": "Leeroy", - "animal": "Elephant", - "legs": 4.5, - "age": 102, - "toys": ["peanuts"], - "traits": ["Friendly"], - "color": "Grey"}, - - {"name": "Tophat", - "animal": "Sparrow", - "legs": 2, - "age": 1, - "toys": None, - "traits": ["Vain","Speedy"], - "color": "Brown"}, - -] \ No newline at end of file diff --git a/Examples/pets_better.py b/Examples/pets_better.py deleted file mode 100644 index 8ed977d..0000000 --- a/Examples/pets_better.py +++ /dev/null @@ -1,69 +0,0 @@ -from PyMark.Util import * - -""" The "animal" field isn't really looking for a String - it's looking for a type. So we can use this Enum instead. Much better. """ - -Dog, Cat, Elephant, Sparrow = Enum(4) - -""" Lots of the personality traits are shared, perhaps we can use Flags instead! Makes a lot more sense than a list of Strings. """ - -Cute, Funny, Friendly, Vain, Speedy = Flags(5) - -""" It'd be nicer to represent color as a tuple rather than a string, we can do it with this quick function definition. - This adds more expressive power, and we can even ensure that the outputs are floats. """ - -def Color(r,g,b): - return (float(r),float(g),float(b)) - -""" We can define some constants to help us with the colors. That way we can reuse them. """ - -BROWN = Color(156,137,61) -GINGER = Color(247,172,32) -GREY = Color(128,128,128) - -""" - If you're worried about detecting these flags, enums or constants afterwards don't be. All constants are compiled to a special "constants" module, so it should be no problem! - - Finally lets consider the "toys" field. If in fact we consider a toy as another object and if we have toys module defined, then we can use the reference function to express this link! - - Overall I think this is much nicer. We've reduced the instances of Strings to just the parts which actually are strings, and dramatically increased the expressiveness of the data! - Also without all those strings I think it is much easier to read. - I'm not saying that all of these things are the "correct" way to structure the data. - I believe you should structure your data to best suite the task in hand, not by some set of global rules. - Having extra constructs just allows for that a little more easily :) -""" - -pets = [ - - {"name": "John", - "animal": Dog, - "legs": 4, - "age": 10, - "toys": [Ref("toys.squeezy"), Ref("toys.bone")], - "traits": Cute|Funny|Friendly - "color": BROWN}, - - {"name": "Benni", - "animal": Cat, - "legs": 4, - "age": 8, - "toys": [Ref("toys.mouse_ball"), Ref("toys.string")], - "traits": Cute|Vain - "color": GINGER}, - - {"name": "Leeroy", - "animal": Elephant, - "legs": 4.5, - "age": 102, - "toys": [Ref("toys.peanuts")], - "traits": Friendly - "color": GREY}, - - {"name": "Tophat", - "animal": Sparrow, - "legs": 2, - "age": 1, - "toys": None, - "traits": Vain|Speedy, - "color": BROWN}, - -] \ No newline at end of file diff --git a/examples/toys.py b/examples/toys.py deleted file mode 100644 index 66678f0..0000000 --- a/examples/toys.py +++ /dev/null @@ -1,7 +0,0 @@ -toys = [ - "squeezy" : (), - "mouse_ball" : (), - "peanuts" : (), - "bone" : (), - "string" : (), -] \ No newline at end of file