Skip to content

Commit 4efe0eb

Browse files
AmarasShadowMitia
andauthored
Removed all "CoconutSyntaxWarning"s that appeared during compilation (#1014)
* Removed all "CoconutSyntaxWarning"s that appeared during compilation * Fix typo --------- Co-authored-by: Dimitri Belopopsky <[email protected]>
1 parent 59c0b9d commit 4efe0eb

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

contents/barnsley/code/coconut/barnsley.coco

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data Point(x=0, y=0):
88
return Point(x, y)
99

1010

11-
def chaos_game(initial_location is Point, hutchinson_op, probabilities):
11+
def chaos_game(Point(initial_location), hutchinson_op, probabilities):
1212
point = initial_location
1313
while True:
1414
yield (point := choices(hutchinson_op, probabilities) @ point)

contents/euclidean_algorithm/code/coconut/euclidean.coco

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
def euclid_sub(a is int, 0) = a
2-
addpattern def euclid_sub(0, b is int) = b
1+
def euclid_sub(int(a), 0) = a
2+
addpattern def euclid_sub(0, int(b)) = b
33

4-
addpattern def euclid_sub(a is int, b is int):
4+
addpattern def euclid_sub(int(a), int(b)):
55
if a < b:
66
return euclid_sub(a, b - a)
77
elif b < a:
88
return euclid_sub(a - b, b)
99
return a
1010

1111

12-
def euclid_mod(a is int, 0) = a
13-
addpattern def euclid_mod(0, b is int) = b
12+
def euclid_mod(int(a), 0) = a
13+
addpattern def euclid_mod(0, int(b)) = b
1414

15-
addpattern def euclid_mod(a is int, b is int) = euclid_mod(b, a % b)
15+
addpattern def euclid_mod(int(a), int(b)) = euclid_mod(b, a % b)
1616

1717
if __name__ == '__main__':
1818
print('[#]\nModulus-based euclidean algorithm result:')

contents/flood_fill/code/coconut/flood_fill.coco

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import numpy as np
33

44

55
data Point(x, y):
6-
def __add__(self, other is Point) = Point(self.x + other.x, self.y + other.y)
6+
def __add__(self, Point(other)) = Point(self.x + other.x, self.y + other.y)
77

88

99
# This function is necessary, because negative indices wrap around the
1010
# array in Coconut.
11-
def inbounds(canvas_shape, location is Point) =
11+
def inbounds(canvas_shape, Point(location)) =
1212
min(location) >= 0 and location.x < canvas_shape[0] and location.y < canvas_shape[1]
1313

1414

15-
def find_neighbours(canvas, location is Point, old_value):
15+
def find_neighbours(canvas, Point(location), old_value):
1616
possible_neighbours = ((Point(0, 1), Point(1, 0), Point(0, -1), Point(-1, 0))
1717
|> map$(location.__add__))
1818

1919
yield from possible_neighbours |> filter$(x -> (inbounds(canvas.shape, x)
2020
and canvas[x] == old_value))
2121

2222

23-
def stack_fill(canvas, location is Point, old_value, new_value):
23+
def stack_fill(canvas, Point(location), old_value, new_value):
2424
if new_value == old_value or not inbounds(canvas.shape, location):
2525
return
2626

@@ -33,7 +33,7 @@ def stack_fill(canvas, location is Point, old_value, new_value):
3333
stack.extend(find_neighbours(canvas, current_location, old_value))
3434

3535

36-
def queue_fill(canvas, location is Point, old_value, new_value):
36+
def queue_fill(canvas, Point(location), old_value, new_value):
3737
if new_value == old_value or not inbounds(canvas.shape, location):
3838
return
3939

@@ -49,7 +49,7 @@ def queue_fill(canvas, location is Point, old_value, new_value):
4949
queue.append(neighbour)
5050

5151

52-
def recursive_fill(canvas, location is Point, old_value, new_value):
52+
def recursive_fill(canvas, Point(location), old_value, new_value):
5353
if new_value == old_value or not inbounds(canvas.shape, location):
5454
return
5555

contents/huffman_encoding/code/coconut/huffman.coco

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ from bisect import bisect
44
class Tree
55

66
data Empty() from Tree
7-
data Leaf(char, n is int) from Tree:
7+
data Leaf(char, int(n)) from Tree:
88
def __str__(self):
99
return f'Leaf({self.char}, {self.n})'
1010

1111
__repr__ = __str__
1212

13-
data Node(left is Tree, right is Tree) from Tree:
13+
data Node(Tree(left), Tree(right)) from Tree:
1414
def __str__(self):
1515
return f'Node({str(self.left)}, {str(self.right)})'
1616
__repr__ = __str__
@@ -52,7 +52,7 @@ def build_huffman_tree(message):
5252

5353
def build_codebook(Empty(), code='') = []
5454
addpattern def build_codebook(Leaf(char, n), code='') = [(char, code)]
55-
addpattern def build_codebook(Node(left, right), code='') =
55+
addpattern def build_codebook(Node(left, right), code='') =
5656
build_codebook(left, code+'0') + build_codebook(right, code+'1')
5757

5858
def huffman_encode(codebook, message):

contents/jarvis_march/code/coconut/jarvis_march.coco

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ data point(x=0, y=0):
33
return f'({self.x}, {self.y})'
44

55
# Is the turn counter-clockwise?
6-
def counter_clockwise(p1 is point, p2 is point, p3 is point) =
6+
def counter_clockwise(point(p1), point(p2), point(p3)) =
77
(p3.y - p1.y) * (p2.x - p1.x) >= (p2.y - p1.y) * (p3.x - p1.x)
88

99

contents/monte_carlo_integration/code/coconut/monte_carlo.coco

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import random
44
data point(x, y):
55
def __abs__(self) = (self.x, self.y) |> map$(pow$(?, 2)) |> sum |> math.sqrt
66

7-
def in_circle(p is point, radius = 1):
7+
def in_circle(point(p), radius = 1):
88
"""Return True if the point is in the circle and False otherwise."""
99
return abs(p) < radius
1010

contents/tree_traversal/code/coconut/tree_traversal.coco

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ def dfs_recursive_postorder(Node(value, children)):
1616

1717
def dfs_recursive_inorder_btree(Node(value, children)):
1818
"""A depth first search approach for printing all values in a binary tree."""
19-
case len(children):
20-
match 2:
19+
match len(children):
20+
case 2:
2121
dfs_recursive_inorder_btree(children[0])
2222
print(value, end=' ')
2323
dfs_recursive_inorder_btree(children[1])
24-
match 1:
24+
case 1:
2525
dfs_recursive_inorder_btree(children[0])
2626
print(value, end=' ')
27-
match 0:
27+
case 0:
2828
print(value, end=' ')
2929
else:
3030
print('Invalid binary tree')
3131

32-
def dfs_stack(node is Node):
32+
def dfs_stack(Node(node)):
3333
"""A depth first approach for printing out all values in a tree using a stack."""
3434
stack = [node]
3535
while stack:
@@ -38,7 +38,7 @@ def dfs_stack(node is Node):
3838
for child in current_node.children:
3939
stack.append(child)
4040

41-
def bfs_queue(node is Node):
41+
def bfs_queue(Node(node)):
4242
"""A breadth first search approach for printing out all values in a tree."""
4343
queue = deque([node])
4444
while queue:

0 commit comments

Comments
 (0)