This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Jaseci-Labs/jaclang
- Loading branch information
Showing
10 changed files
with
132 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Enum for shape types""" | ||
|
||
:enum:ShapeType { | ||
CIRCLE = "Circle", | ||
UNKNOWN = "Unknown" | ||
} | ||
|
||
"""Function to calculate the area of a circle.""" | ||
:can:calculate_area | ||
(radius: float) -> float { | ||
return math.pi * radius * radius; | ||
} | ||
|
||
:obj:Circle:can:<init> (radius: float) { | ||
self.radius = radius; | ||
<super>.<init>(ShapeType.CIRCLE); | ||
} | ||
|
||
"""Overridden method to calculate the area of the circle.""" | ||
:obj:Circle:can:area -> float { | ||
return math.pi * <self>.radius * <self>.radius; | ||
} | ||
|
||
:can:main_run { | ||
print(f"Area of a circle with radius {RAD} using function: {calculate_area(RAD)}"); | ||
print(f"Area of a {c.shape_type.value} with radius {RAD} using class: {c.area()}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
This module demonstrates a simple circle class and a function to calculate | ||
the area of a circle in all of Jac's glory. | ||
""" | ||
import:py math; | ||
|
||
enum ShapeType; | ||
can calculate_area(radius: float) -> float; | ||
can main_run; | ||
|
||
"""Base class for a shape.""" | ||
obj Shape { | ||
has shape_type: ShapeType; | ||
can area -> float abs; | ||
} | ||
|
||
"""Circle class inherits from Shape.""" | ||
obj Circle:Shape: { | ||
has radius: float; | ||
can <init>(radius: float); | ||
can area -> float; | ||
} | ||
|
||
# Radius of the demo circle | ||
glob RAD = 5, c = Circle(radius=RAD); | ||
|
||
"""Here we run the main program.""" | ||
with entry:__main__ { main_run(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
glob expected_area = 78.53981633974483; | ||
test { check.AlmostEqual(calculate_area(RAD), expected_area); } | ||
test { c = Circle(RAD); check.AlmostEqual(c.area(), expected_area); } | ||
test { c = Circle(RAD); check.Equal(c.shape_type, ShapeType.CIRCLE); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters