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 pull request #180 from Jaseci-Labs/examples_01
refactored examples
- Loading branch information
Showing
46 changed files
with
548 additions
and
545 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
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,34 +1,11 @@ | ||
with entry{ | ||
# Addition | ||
result_addition = 5 + 3; | ||
print("Addition:", result_addition); # Output: 8 | ||
p = print; | ||
|
||
# Subtraction | ||
result_subtraction = 10 - 4; | ||
print("Subtraction:", result_subtraction); # Output: 6 | ||
p("Multiply:", 7 * 2); | ||
p("Division:", 15 / 3); | ||
p("Floor:", 15 // 3); | ||
p("Modulo:", 17 % 5); | ||
p("Expon:", 2 ** 3); | ||
p("combo:", (9+ 2) *9 - 2); | ||
|
||
# Multiplication | ||
result_multiplication = 7 * 2; | ||
print("Multiplication:", result_multiplication); # Output: 14 | ||
|
||
# Division | ||
result_division = 15 / 3; | ||
print("Division:", result_division); # Output: 5.0 (result is a float) | ||
|
||
# Integer Division (Floor Division) | ||
result_floor_division = 15 // 3; | ||
print("Floor Division:", result_floor_division); # Output: 5 (result is an integer) | ||
|
||
# Modulo (Remainder) | ||
result_modulo = 17 % 5; | ||
print("Modulo (Remainder):", result_modulo); # Output: 2 | ||
|
||
# Exponentiation | ||
result_exponentiation = 2 ** 3; | ||
print("Exponentiation:", result_exponentiation); # Output: 8 | ||
|
||
# Combined Operations | ||
combined_result = (4 + 7) * 2 - 3; | ||
print("Combined Operations:", combined_result); # Output: 15 | ||
|
||
} | ||
} |
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,30 +1,8 @@ | ||
result_addition = 5 + 3 | ||
print("Addition:", result_addition) # Output: 8 | ||
|
||
# Subtraction | ||
result_subtraction = 10 - 4 | ||
print("Subtraction:", result_subtraction) # Output: 6 | ||
|
||
# Multiplication | ||
result_multiplication = 7 * 2 | ||
print("Multiplication:", result_multiplication) # Output: 14 | ||
|
||
# Division | ||
result_division = 15 / 3 | ||
print("Division:", result_division) # Output: 5.0 (result is a float) | ||
|
||
# Integer Division (Floor Division) | ||
result_floor_division = 15 // 3 | ||
print("Floor Division:", result_floor_division) # Output: 5 (result is an integer) | ||
|
||
# Modulo (Remainder) | ||
result_modulo = 17 % 5 | ||
print("Modulo (Remainder):", result_modulo) # Output: 2 | ||
|
||
# Exponentiation | ||
result_exponentiation = 2**3 | ||
print("Exponentiation:", result_exponentiation) # Output: 8 | ||
|
||
# Combined Operations | ||
combined_result = (4 + 7) * 2 - 3 | ||
print("Combined Operations:", combined_result) # Output: 15 | ||
p = print | ||
|
||
p("Multiply:", 7 * 2) | ||
p("Division:", 15 / 3) | ||
p("Floor:", 15 // 3) | ||
p("Modulo:", 17 % 5) | ||
p("Expon:", 2**3) | ||
p("combo:", (9 + 2) * 9 - 2) |
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,20 +1,9 @@ | ||
a = b = 5 | ||
c = 10 | ||
a = b = 16 | ||
c = 18 | ||
print(a, b, c) | ||
|
||
|
||
# Right Shift Equal (>>=) | ||
x = 16 # Binary: 0b10000 | ||
x >>= 2 # Right shift x by 2 positions and assign the result back to x | ||
print(x) # After the operation, x will be 4 (Binary: 0b100) | ||
|
||
|
||
# Left shift Equal (<<=) | ||
x <<= 2 # Left shift x by 2 positions and assign the result back to x | ||
print(x) # After the operation, x will be 64 (Binary: 0b1000000) | ||
|
||
|
||
# floor division equal | ||
x = 18 | ||
x //= 4 | ||
print(x) # output gives 4 | ||
a >>= 2 | ||
print(a) | ||
a <<= 2 | ||
print(a) | ||
c //= 4 | ||
print(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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
:enum:x { | ||
a_b=67, | ||
y="aaa" +f"b{a_b}bbcc" | ||
aa=67, | ||
y="aaa" +f"b{aa}bbcc" | ||
} | ||
glob c=(3,4,5) , l_1=[2,3,4,5]; | ||
glob c=(3,4,5) , list1=[2,3,4,5]; | ||
with entry{ | ||
#do we need to give example for what are atoms ? | ||
a="abcde...."; | ||
b=True; | ||
c=bin(12); d=hex(78); | ||
# e=0x4e; ???? | ||
print(l_1,a,b,c,d); | ||
print(list1,a,b,c,d); | ||
# pp=0x4e; | ||
# print(0b1100); | ||
enum x; | ||
print(x.y.value); | ||
} |
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,29 +1,10 @@ | ||
#Bitwise_operators.jac | ||
with entry{ | ||
# Bitwise AND | ||
a = 5; # binary: 0101 | ||
b = 3; # binary: 0011 | ||
result_and = a & b; | ||
print(f"Bitwise AND: {result_and}"); # Output: 1 (binary: 0001) | ||
|
||
# Bitwise OR | ||
result_or = a | b; | ||
print(f"Bitwise OR: {result_or}") ; # Output: 7 (binary: 0111) | ||
|
||
# Bitwise XOR | ||
result_xor = a ^ b; | ||
print(f"Bitwise XOR: {result_xor}"); # Output: 6 (binary: 0110) | ||
|
||
# Bitwise NOT | ||
result_not_a = ~a; | ||
print(f"Bitwise NOT of a: {result_not_a}"); # Output: -6 (binary: 11111010) | ||
|
||
# Left shift | ||
result_left_shift = a << 1; | ||
print(f"Left shift of a: {result_left_shift}"); # Output: 10 (binary: 1010) | ||
|
||
# Right shift | ||
result_right_shift = a >> 1; | ||
print(f"Right shift of a: {result_right_shift}"); # Output: 2 (binary: 0010) | ||
p=print; | ||
p("&:", 5 & 3); | ||
p("|:", 5 | 3); | ||
p("^:", 5 ^ 3); | ||
p("~:", ~5); | ||
p("<<:", 5 << 1); | ||
p(">>:", 5 >> 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,7 @@ | ||
# Bitwise AND | ||
a = 5 | ||
# binary: 0101 | ||
b = 3 | ||
# binary: 0011 | ||
result_and = a & b | ||
print(f"Bitwise AND: {result_and}") # Output: 1 (binary: 0001) | ||
|
||
# Bitwise OR | ||
result_or = a | b | ||
print(f"Bitwise OR: {result_or}") # Output: 7 (binary: 0111) | ||
|
||
# Bitwise XOR | ||
result_xor = a ^ b | ||
print(f"Bitwise XOR: {result_xor}") # Output: 6 (binary: 0110) | ||
|
||
# Bitwise NOT | ||
result_not_a = ~a | ||
print(f"Bitwise NOT of a: {result_not_a}") # Output: -6 (binary: 11111010) | ||
|
||
# Left shift | ||
result_left_shift = a << 1 | ||
print(f"Left shift of a: {result_left_shift}") # Output: 10 (binary: 1010) | ||
|
||
# Right shift | ||
result_right_shift = a >> 1 | ||
print(f"Right shift of a: {result_right_shift}") # Output: 2 (binary: 0010) | ||
p = print | ||
p("&:", 5 & 3) | ||
p("|:", 5 | 3) | ||
p("^:", 5 ^ 3) | ||
p("~:", ~5) | ||
p("<<:", 5 << 1) | ||
p(">>:", 5 >> 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,36 @@ | ||
node node_a{ | ||
has value:int; | ||
node node_a { | ||
has value: int; | ||
} | ||
|
||
walker Creator { | ||
can create with `<root> entry; | ||
can travel with `<root>|node_a entry; | ||
can travel with `<root> | node_a entry; | ||
} | ||
|
||
edge MyEdge { | ||
has val:int =5; | ||
has val: int = 5; | ||
} | ||
:walker:Creator:can:create{ | ||
|
||
:walker:Creator:can:create { | ||
end = <here>; | ||
for i = 0 to i<7 by i+=1{ | ||
if i % 2==0{ | ||
end ++> end := node_a(value=i); | ||
} | ||
else{ | ||
end +:MyEdge:val=i:+> end := node_a(value=i+10); | ||
for i=0 to i<7 by i+=1 { | ||
if i % 2 == 0 { | ||
end ++> (end := node_a(value=i)); | ||
} else { | ||
end +:MyEdge:val=i:+> (end := node_a(value=i + 10)); | ||
} | ||
} | ||
} | ||
:walker:Creator:can:travel{ | ||
for i in -:MyEdge:val<=6 :->{ | ||
print(i.value); | ||
} | ||
visit-->; | ||
|
||
:walker:Creator:can:travel { | ||
for i in -:MyEdge:val <= 6:-> { | ||
print(i.value); | ||
} | ||
visit -->; | ||
} | ||
with entry{ | ||
|
||
with entry { | ||
<root> spawn Creator(); | ||
|
||
# print(<r>._jac_.gen_dot()); | ||
} | ||
} |
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,27 @@ | ||
walker walker_1{ | ||
can func2 with `<root> entry; | ||
walker walker_1 { | ||
can func2 with `<root> entry; | ||
} | ||
node node_1{ | ||
has val :int; | ||
can func_1 with walker_1 entry; | ||
|
||
node node_1 { | ||
has val: int; | ||
|
||
can func_1 with walker_1 entry; | ||
} | ||
:node:node_1:can:func_1{ | ||
print("visiting ",<s>); | ||
visit-->; | ||
} | ||
:walker:walker_1:can:func2{ | ||
|
||
:node:node_1:can:func_1 { | ||
print("visiting ", <s>); | ||
visit -->; | ||
} | ||
|
||
:walker:walker_1:can:func2 { | ||
end = <here>; | ||
for i=0 to i<5 by i+=1 { | ||
end ++> end := node_1(val=i+1); | ||
for i=0 to i<5 by i+=1 { | ||
end ++> (end := node_1(val=i + 1)); | ||
} | ||
visit -->; | ||
} | ||
|
||
with entry{ | ||
<r> spawn |> walker_1 ; | ||
<r> spawn :> walker_1 ; | ||
|
||
with entry { | ||
<r> spawn |> walker_1; | ||
<r> spawn :> walker_1; | ||
} |
Oops, something went wrong.