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

Rename instances of faculty to factorial #71

Merged
merged 2 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,40 +148,40 @@ Expr _ print("= " + $1) # gives some neat result output
> ```

Tokay can also be used for programs without any parsing features.<br>
Next is a recursive attempt for calculating the faculty of an integer.
Next is a recursive attempt for calculating the factorial of an integer.

```tokay
faculty : @x {
factorial : @x {
if !x return 1
x * faculty(x - 1)
x * factorial(x - 1)
}

faculty(4)
factorial(4)
```

> ```
> $ tokay examples/faculty.tok
> $ tokay examples/factorial.tok
> 24
> ```

And this version of above program calculates the faculty for any integer token matches from the input. Just the invocation is different, and uses the Number token.
And this version of above program calculates the factorial for any integer token matches from the input. Just the invocation is different, and uses the Number token.

```tokay
faculty : @x {
factorial : @x {
if !x return 1
x * faculty(x - 1)
x * factorial(x - 1)
}

print(faculty(int(Number)))
print(factorial(int(Number)))
```

> ```
> $ tokay examples/faculty2.tok -- "5 6 ignored 7 other 14 yeah"
> $ tokay examples/factorial2.tok -- "5 6 ignored 7 other 14 yeah"
> 120
> 720
> 5040
> 87178291200
> $ tokay examples/faculty2.tok
> $ tokay examples/factorial2.tok
> 5
> 120
> 6
Expand Down
6 changes: 6 additions & 0 deletions examples/factorial.tok
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
factorial : @x {
if !x return 1
x * factorial(x - 1)
}

factorial(4)
6 changes: 6 additions & 0 deletions examples/factorial2.tok
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
factorial : @x {
if !x return 1
x * factorial(x - 1)
}

print(factorial(int(Number)))
6 changes: 0 additions & 6 deletions examples/faculty.tok

This file was deleted.

6 changes: 0 additions & 6 deletions examples/faculty2.tok

This file was deleted.

2 changes: 1 addition & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ fn examples() {
);

assert_eq!(
run(include_str!("../examples/faculty.tok"), ""),
run(include_str!("../examples/factorial.tok"), ""),
Ok(Some(value!(24)))
);

Expand Down
12 changes: 6 additions & 6 deletions src/value/parselet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,12 @@ fn test_function_as_static_with_args() {
assert_eq!(
crate::run(
"
faculty : @x {
factorial : @x {
if !x return 1
x * faculty(x - 1)
x * factorial(x - 1)
}

faculty(4)
factorial(4)
",
""
),
Expand All @@ -588,12 +588,12 @@ fn test_function_as_variable_with_args() {
assert_eq!(
crate::run(
"
faculty = @x {
factorial = @x {
if !x return 1
x * faculty(x - 1)
x * factorial(x - 1)
}

faculty(4)
factorial(4)
",
""
),
Expand Down
8 changes: 4 additions & 4 deletions tests/err_compiler_identifier_names.tok
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Cident : [A-Za-z_] [A-Za-z0-9_]* $0
cident : Cident # Error: Cannot assign consumable to non-consumable constant.
NewCident : Cident # Ok

faculty : @n {
factorial : @n {
if n <= 0 return 1
n * faculty(n - 1)
n * factorial(n - 1)
}
Faculty : faculty # Error: Cannot assign non-consumable to consumable constant.
Factorial : factorial # Error: Cannot assign non-consumable to consumable constant.

IsOkay : @{
Int if $1 > 100 && $1 < 1000 accept
Expand All @@ -20,5 +20,5 @@ _ : "abc"
#---
#ERR:Line 1, column 1: Cannot assign to constant 'Pi', because it must be consumable. Use an identifier starting in lower-case, e.g. 'pi'
#ERR:Line 5, column 1: Cannot assign constant 'cident' as consumable. Use an identifier starting in upper-case, e.g. 'Cident'
#ERR:Line 12, column 1: Cannot assign to constant 'Faculty', because it must be consumable. Use an identifier starting in lower-case, e.g. 'faculty'
#ERR:Line 12, column 1: Cannot assign to constant 'Factorial', because it must be consumable. Use an identifier starting in lower-case, e.g. 'factorial'
#ERR:Line 18, column 1: Cannot assign to constant '_', because it must be consumable. Use an identifier not starting with '_'.