Skip to content
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
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c4c1044
Update visit_statements.jac
Thamirawaran Sep 16, 2024
b323494
Correct typo (flaot -> float)
Thamirawaran Sep 16, 2024
a5b11f6
Create FAQ.md
Thamirawaran Sep 19, 2024
baa000e
Update FAQ.md
Thamirawaran Sep 19, 2024
d432f4e
Update FAQ.md
Thamirawaran Sep 20, 2024
565f400
reference examlpe file code updates for importinclude, names and refe…
kugesan1105 Sep 20, 2024
976446c
Fixed issue: declaring ability inside enum and Examples added to enum…
kugesan1105 Sep 20, 2024
82502c0
Add files via upload
Thamirawaran Sep 27, 2024
2956387
Add files via upload
Thamirawaran Sep 27, 2024
ebb950d
Update mkdocs.yml
Thamirawaran Sep 27, 2024
2ee433f
Old FAQ.md file deleted
Thamirawaran Oct 1, 2024
44dc66b
FAQ.md file updated
Thamirawaran Oct 1, 2024
e5ac1af
FAQ.md file updated
Thamirawaran Oct 1, 2024
5041e87
Merge branch 'main' into improv_ref
kugesan1105 Oct 2, 2024
3b7c3c7
man merge
kugesan1105 Oct 2, 2024
13e57dd
added description for examples of data spatial
kugesan1105 Oct 2, 2024
413c3ea
Merge branch 'main' into improv_ref
kugesan1105 Oct 2, 2024
5758bfd
Bug fix: Updated normalize function for enums to use normalize decora…
kugesan1105 Oct 2, 2024
c128029
test files updated
kugesan1105 Oct 2, 2024
85e1337
FAQ section and example section updated with better explanation and g…
kugesan1105 Oct 3, 2024
e6245d5
data spatial examples updated with new example
Thamirawaran Oct 3, 2024
d6b66ef
examples refactored
kugesan1105 Oct 3, 2024
2e6332b
Update define_walker.jac
Thamirawaran Oct 12, 2024
3fc203e
Update mkdocs.yml
Thamirawaran Oct 12, 2024
4702155
Delete jac/support/jac-lang.org/docs/learn/data_spatial/reference.md
Thamirawaran Oct 12, 2024
a7c90ac
Update filtering.jac
Thamirawaran Oct 12, 2024
baa8b2e
Update FAQ.md
Thamirawaran Oct 12, 2024
3480a78
filtering by edge attribute example added
kugesan1105 Oct 14, 2024
47b9019
Update mkdocs.yml: Update theme palette
kugesan1105 Oct 14, 2024
a7a0d8c
Merge branch 'main' into improv_ref
kugesan1105 Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions jac/examples/data_spatial/create_node.jac
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;


}
23 changes: 23 additions & 0 deletions jac/examples/data_spatial/custom_edge.jac
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:->]);

}
25 changes: 25 additions & 0 deletions jac/examples/data_spatial/define_walker.jac
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);
here +:a:+> Start;
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)]);
}
36 changes: 36 additions & 0 deletions jac/examples/data_spatial/ds_entry_exit.jac
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);
}
22 changes: 22 additions & 0 deletions jac/examples/data_spatial/edge_filtering.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
node A{
has val:int =0;
}

edge a{
has val:int = 0;
}
edge b{
has val:int = 0;
}

with entry{

root +:a:val=10:+> A(10);
root +:a:val=20:+> A(20);
root +:b:val=30:+> A(30);

print([root--> ]);
print([root-:a:-> ]);
print([root-:a:val<=15:-> ]);
print([root-:a:val>=20:-> ]);
}
31 changes: 31 additions & 0 deletions jac/examples/data_spatial/filtering.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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);
Intermediate = B(10);
End = C(25);
root +:a:+> Start;
Start +:b:+> Intermediate +:c:+> C(15);
Start +:b:+> A(20) +:a:+> End;
Intermediate +:c:+> End;

print([root-->-:b:->(`?A)]);
print([root-:a:-> -:b:-> -:a:->(`?C)]);
print([root-:a:-> -:b:-> -:c:->(`?C)]);
print([root-:a:-> -:b:-> -:c:->(?val==25)]);
print([root-:a:-> -:b:-> -:c:->(?val<20)]);
}
25 changes: 25 additions & 0 deletions jac/examples/data_spatial/node_connections.jac
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;

}
20 changes: 20 additions & 0 deletions jac/examples/data_spatial/visiting.jac
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<--]);


}
23 changes: 19 additions & 4 deletions jac/examples/reference/enumerations.jac
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());
}
16 changes: 13 additions & 3 deletions jac/examples/reference/enumerations.py
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())
2 changes: 1 addition & 1 deletion jac/examples/reference/global_variables.jac
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ glob z = 20;

obj:priv Myobj{}

with entry {
with entry:__main__ {
print(a, X, y, z);
}
13 changes: 9 additions & 4 deletions jac/examples/reference/import_include_statements.jac
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))
);
}
}
4 changes: 2 additions & 2 deletions jac/examples/reference/import_include_statements.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from jaclang import jac_import as __jac_import__
import os
from math import sqrt as square_root
import datetime as dt
from math import sqrt as square_root, log

(add, subtract) = __jac_import__(
target="base_module_structure",
Expand All @@ -10,4 +10,4 @@
)

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)))
2 changes: 1 addition & 1 deletion jac/examples/reference/match_patterns.jac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
obj Point {
has x: flaot,
has x: float,
y: float;
}

Expand Down
32 changes: 19 additions & 13 deletions jac/examples/reference/names_and_references.jac
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}");
}
36 changes: 25 additions & 11 deletions jac/examples/reference/names_and_references.py
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}")
Loading
Loading