-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement of Jac reference #1293
Open
Thamirawaran
wants to merge
30
commits into
main
Choose a base branch
from
improv_ref
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+790
−55
Open
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c4c1044
Update visit_statements.jac
Thamirawaran b323494
Correct typo (flaot -> float)
Thamirawaran a5b11f6
Create FAQ.md
Thamirawaran baa000e
Update FAQ.md
Thamirawaran d432f4e
Update FAQ.md
Thamirawaran 565f400
reference examlpe file code updates for importinclude, names and refe…
kugesan1105 976446c
Fixed issue: declaring ability inside enum and Examples added to enum…
kugesan1105 82502c0
Add files via upload
Thamirawaran 2956387
Add files via upload
Thamirawaran ebb950d
Update mkdocs.yml
Thamirawaran 2ee433f
Old FAQ.md file deleted
Thamirawaran 44dc66b
FAQ.md file updated
Thamirawaran e5ac1af
FAQ.md file updated
Thamirawaran 5041e87
Merge branch 'main' into improv_ref
kugesan1105 3b7c3c7
man merge
kugesan1105 13e57dd
added description for examples of data spatial
kugesan1105 413c3ea
Merge branch 'main' into improv_ref
kugesan1105 5758bfd
Bug fix: Updated normalize function for enums to use normalize decora…
kugesan1105 c128029
test files updated
kugesan1105 85e1337
FAQ section and example section updated with better explanation and g…
kugesan1105 e6245d5
data spatial examples updated with new example
Thamirawaran d6b66ef
examples refactored
kugesan1105 2e6332b
Update define_walker.jac
Thamirawaran 3fc203e
Update mkdocs.yml
Thamirawaran 4702155
Delete jac/support/jac-lang.org/docs/learn/data_spatial/reference.md
Thamirawaran a7c90ac
Update filtering.jac
Thamirawaran baa8b2e
Update FAQ.md
Thamirawaran 3480a78
filtering by edge attribute example added
kugesan1105 47b9019
Update mkdocs.yml: Update theme palette
kugesan1105 a7a0d8c
Merge branch 'main' into improv_ref
kugesan1105 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,14 @@ | ||
node MyNode{} | ||
|
||
with entry{ | ||
first_tier =[MyNode() for i in range(2)]; | ||
second_tier =[MyNode() for i in range(2)]; | ||
|
||
root ++> first_tier; | ||
first_tier ++> second_tier; | ||
|
||
end_tier = MyNode(); | ||
second_tier ++> end_tier; | ||
|
||
|
||
} |
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,23 @@ | ||
node MyNode{ | ||
has val:int =0; | ||
} | ||
|
||
edge a{} | ||
|
||
edge b{} | ||
|
||
edge c{} | ||
|
||
with entry{ | ||
Start = MyNode(5); | ||
root +:a:+> Start; | ||
Start +:b:+> MyNode(10) +:c:+> MyNode(15); | ||
Start +:b:+> MyNode(20) +:a:+> MyNode(25); | ||
|
||
print([root-->]); | ||
print([root<--]); | ||
print([root-:a:->]); | ||
print([root-:a:-> -:b:->]); | ||
print([root-:a:-> -:b:->-:c:->]); | ||
|
||
} |
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,25 @@ | ||
node A{ | ||
has val:int =0; | ||
} | ||
|
||
edge a{ | ||
} | ||
|
||
walker W{ | ||
can create with `root entry; | ||
} | ||
|
||
:walker:W:can:create{ | ||
Start = A(5); | ||
root +:a:+> Start; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huse 'here' instead of root |
||
Start +:a:+> A(10) +:a:+> A(15); | ||
Start +:a:+> A(20) +:a:+> A(25); | ||
} | ||
|
||
|
||
|
||
with entry{ | ||
root spawn W(); | ||
print([root-->-->(`?A)]); | ||
print([root--> --> -->(`?A)]); | ||
} |
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,36 @@ | ||
node test_node { | ||
has value: int; | ||
} | ||
|
||
walker test_walker { | ||
has visited_nodes: list = []; | ||
has entry_count: int = 0; | ||
has exit_count: int = 0; | ||
|
||
can traverse with `root entry { | ||
visit [-->](`?test_node); | ||
} | ||
|
||
can log_entry with entry { | ||
print("Entering at the beginning of walker: ",here); | ||
self.entry_count += 1; | ||
} | ||
|
||
can log_visit with test_node exit { | ||
print("Visiting node : ", here); | ||
self.visited_nodes.append(here); | ||
} | ||
|
||
can log_exit with exit { | ||
print("Exiting at the end of walker: ",here); | ||
self.exit_count += 1; | ||
} | ||
} | ||
|
||
with entry { | ||
for i in range(10) { | ||
root ++> (next:=test_node(value=i)); | ||
} | ||
wlk_obj = root spawn test_walker(); | ||
print(wlk_obj); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filtering by node attributes should be also included |
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,26 @@ | ||
node A{ | ||
has val:int =0; | ||
} | ||
node B{ | ||
has val:int =0; | ||
} | ||
node C{ | ||
has val:int =0; | ||
} | ||
|
||
edge a{} | ||
|
||
edge b{} | ||
|
||
edge c{} | ||
|
||
with entry{ | ||
Start = A(5); | ||
root +:a:+> Start; | ||
Start +:b:+> B(10) +:c:+> C(15); | ||
Start +:b:+> A(20) +:a:+> C(25); | ||
|
||
print([root-->-:b:->(`?A)]); | ||
print([root-:a:-> -:b:-> -:c:->(`?C)]); | ||
print([root-:a:-> -:b:-> -:c:->(`?C)]); | ||
} |
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,25 @@ | ||
node a{ | ||
has value:int =10; | ||
} | ||
|
||
edge b{ | ||
has value:int = 20; | ||
} | ||
|
||
with entry{ | ||
node_1 = a(value=5); | ||
node_2 = a(); | ||
node_3 = a(value=15); | ||
node_4 = a(value=20); | ||
node_5 = a(value=25); | ||
|
||
root ++> node_1; | ||
node_1 +:edge_1:= b(value=5):+> node_2; | ||
node_1 +:edge_2:=b(value=10):+> node_3; | ||
node_1 +:edge_3:=b(value=15):+> node_4; | ||
node_1 +:edge_4:=b():+> node_5; | ||
|
||
node_1 del --> node_2; | ||
del node_3; | ||
|
||
} |
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,20 @@ | ||
node MyNode{ | ||
has Name:str; | ||
} | ||
|
||
edge a{} | ||
|
||
|
||
with entry{ | ||
Start = MyNode("Start"); | ||
End = MyNode("End"); | ||
root <+:a:+ Start; | ||
root +:a:+> End; | ||
|
||
print([root-->]); | ||
print([root<--]); | ||
print([Start-->]); | ||
print([End<--]); | ||
|
||
|
||
} |
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 |
---|---|---|
@@ -1,8 +1,23 @@ | ||
enum Color { | ||
RED=1, | ||
pencil | ||
import from enum { unique } | ||
|
||
@unique | ||
enum Color; | ||
|
||
:enum:Color { | ||
RED = 1, | ||
GREEN = 2 | ||
} | ||
|
||
enum :protect Role { | ||
ADMIN = 'admin', | ||
USER = 'user', | ||
with entry { | ||
print('Initializing role system..'); | ||
}, | ||
can foo -> str { | ||
return 'Accessing privileged Data'; | ||
} | ||
} | ||
with entry { | ||
print(Color.RED.value); | ||
print(Color.RED.value, Role.foo()); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
from __future__ import annotations | ||
from enum import Enum, auto | ||
from enum import Enum, auto, unique | ||
|
||
|
||
@unique | ||
class Color(Enum): | ||
RED = 1 | ||
pencil = auto() | ||
|
||
|
||
print(Color.RED.value) | ||
class Role(Enum): | ||
ADMIN = ("admin",) | ||
USER = "user" | ||
|
||
print("Initializing role system..") | ||
|
||
def foo(): | ||
return "Accessing privileged Data" | ||
|
||
|
||
print(Color.RED.value, Role.foo()) |
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 |
---|---|---|
|
@@ -8,6 +8,6 @@ glob z = 20; | |
|
||
obj:priv Myobj{} | ||
|
||
with entry { | ||
with entry:__main__ { | ||
print(a, X, y, z); | ||
} |
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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import:py os; | ||
import:py from math, sqrt as square_root; | ||
import:py datetime as dt; | ||
import:jac from base_module_structure, add; | ||
import from base_module_structure, subtract; | ||
import from math { sqrt as square_root, log } | ||
import:jac from base_module_structure { add } | ||
import from base_module_structure { subtract } | ||
include global_variables; | ||
|
||
with entry { | ||
for i in range(int(square_root(dt.datetime.now().year))) { | ||
print(os.getcwd(), add(i, subtract(i, 1))); | ||
print( | ||
os.getcwd(), | ||
add(i, subtract(i, 1)), | ||
int(log(i + 1)) | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
obj Point { | ||
has x: flaot, | ||
has x: float, | ||
y: float; | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -1,24 +1,30 @@ | ||
obj Animal { | ||
can init(species: str) { | ||
self.species = species; | ||
} | ||
has species: str; | ||
has sound: str; | ||
|
||
} | ||
|
||
obj Dog :Animal: { | ||
can init(breed: str) { | ||
super.init(species='Dog'); | ||
self.breed = breed; | ||
self.sound = ""; | ||
self.postinit(); | ||
has breed: str; | ||
has trick: str by postinit; | ||
|
||
can postinit { | ||
self.trick = "Roll over"; | ||
} | ||
can postinit; | ||
} | ||
|
||
:obj:Dog:can:postinit { | ||
self.sound = 'woof woof'; | ||
obj Cat :Animal: { | ||
can init(fur_color: str) { | ||
super.init(species="Cat", sound="Meow!"); | ||
self.fur_color = fur_color; | ||
} | ||
} | ||
|
||
with entry { | ||
dog1 = Dog("Labrador"); | ||
print(dog1.species, dog1.breed, dog1.sound); | ||
dog = Dog(breed="Labrador", species="Dog", sound="Woof!"); | ||
cat = Cat(fur_color="Tabby"); | ||
|
||
print(dog.breed, dog.sound, dog.trick); | ||
# print(f"The dog is a {dog.breed} and says '{dog.sound}'"); | ||
# print(f"The cat's fur color is {cat.fur_color}"); | ||
} |
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 |
---|---|---|
@@ -1,18 +1,32 @@ | ||
from dataclasses import dataclass, field | ||
|
||
|
||
@dataclass | ||
class Animal: | ||
def __init__(self, animal_type): | ||
self.animal_type = animal_type | ||
species: str | ||
sound: str | ||
|
||
|
||
@dataclass | ||
class Dog(Animal): | ||
def __init__(self, breed): | ||
super().__init__("Dog") | ||
self.breed = breed | ||
self.sound = "" | ||
self._post_init() | ||
breed: str | ||
trick: str = field(init=False) | ||
|
||
def __post_init__(self): | ||
self.trick = "Roll over" | ||
|
||
|
||
@dataclass | ||
class Cat(Animal): | ||
|
||
def __init__(self, fur_color: str): | ||
super().__init__(species="Cat", sound="Meow!") | ||
self.fur_color = fur_color | ||
|
||
def _post_init(self): | ||
self.sound = "woof woof" | ||
|
||
dog = Dog(breed="Labrador", species="Dog", sound="Woof!") | ||
cat = Cat(fur_color="Tabby") | ||
|
||
dog1 = Dog(breed="Labrador") | ||
print(dog1.animal_type, dog1.breed, dog1.sound) | ||
print(dog.breed, dog.sound, dog.trick) | ||
# print(f'The dog is a {dog.breed} and says "{dog.sound}"') | ||
# print(f"The cat's fur color is {cat.fur_color}") |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ walker Visitor { | |
can travel with `root entry { | ||
visit [-->] else { | ||
visit root; | ||
disengage; | ||
} | ||
} | ||
} | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show how we can filter by edge attributes.