September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
14
Task/Polymorphism/Jq/polymorphism-1.jq
Normal file
14
Task/Polymorphism/Jq/polymorphism-1.jq
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
def Point(x;y): {"type": "Point", "x": x, "y": y};
|
||||
def Point(x): Point(x;0);
|
||||
def Point: Point(0);
|
||||
|
||||
def Circle(x;y;r): {"type": "Circle", "x": x, "y": y, "r": r};
|
||||
def Circle(x;y): Circle(x;y;0);
|
||||
def Circle(x): Circle(x;0);
|
||||
def Circle: Circle(0);
|
||||
|
||||
def print:
|
||||
if .type == "Circle" then "\(.type)(\(.x); \(.y); \(.r))"
|
||||
elif .type == "Point" then "\(.type)(\(.x); \(.y))"
|
||||
else empty
|
||||
end;
|
||||
5
Task/Polymorphism/Jq/polymorphism-2.jq
Normal file
5
Task/Polymorphism/Jq/polymorphism-2.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# keyname should be (or evaluate to) a string
|
||||
def set(keyname; value):
|
||||
if type == "object" and .type and has(keyname) then .[keyname] = value
|
||||
else error("set: invalid type: \(.)")
|
||||
end;
|
||||
1
Task/Polymorphism/Jq/polymorphism-3.jq
Normal file
1
Task/Polymorphism/Jq/polymorphism-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
Circle(0;1;2) | .x = 1 | print
|
||||
Loading…
Add table
Add a link
Reference in a new issue