Skip to content

Commit 65e6229

Browse files
committed
Fix syntax in dot_produnct.dana
The nested dot_product function definition was moved before the main execution statements within main. The equality comparison was changed from == to =. The begin/end keywords were removed from the bodies of main and dot_product because they contained declarations, requiring layout-based blocks instead. Finally, the call dot_product : ... was changed to dot_product(...) to use the correct function call syntax within an expression.
1 parent 6960e00 commit 65e6229

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

dana/programs/dot_product.dana

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
def main
2-
begin
3-
def dot_product is int : n as int, vector1 as int [], vector2 as int []
4-
begin
5-
var product i is int
6-
product := 0
7-
i := 0
8-
loop:
9-
begin
10-
if i == n : begin break end
11-
product := product + vector1[i]*vector2[i]
12-
i := i + 1
13-
end
14-
return : product
15-
end
2+
def dot_product is int : n as int, vector1 as int [], vector2 as int []
3+
var product i is int
4+
product := 0
5+
i := 0
6+
loop:
7+
begin
8+
if i = n : begin break end
9+
product := product + vector1[i]*vector2[i]
10+
i := i + 1
11+
end
12+
return : product
1613

1714
var ex_vector1 ex_vector2 is int[4]
1815

@@ -27,8 +24,7 @@ begin
2724
ex_vector2[3] := 7
2825

2926
var result is int
30-
result := dot_product : 4, ex_vector1, ex_vector2
27+
result := dot_product(4, ex_vector1, ex_vector2)
3128
writeString : "The dot product of the two vectors is: "
3229
writeInteger : result
3330
writeChar : '\n'
34-
end

0 commit comments

Comments
 (0)