Skip to content

Print as function #135

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

Merged
merged 4 commits into from
Jan 4, 2024
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
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ Check out the [documentation](https://kyleect.github.io/locks/#/docs) the start
fn fizzBuzz(n) {
for (let i = 1; i <= n; i = i + 1) {
if (i % 15 == 0) {
print "FizzBuzz";
println("FizzBuzz");
}
else if (i % 3 == 0) {
print "Fizz";
println("Fizz");
}
else if (i % 5 == 0) {
print "Buzz";
println("Buzz");
}
else {
print i;
println(i);
}
}
}
Expand Down Expand Up @@ -75,7 +75,7 @@ $ locks run file.locks
#### Execute locks code as an argument

```shell
$ locks exec 'print "Hello";' # Hello
$ locks exec 'println("Hello");' # Hello
```

#### Execute locks code from stdin
Expand All @@ -90,9 +90,9 @@ $ cat res/benchmarks/fib.locks | locks exec
// example.locks

let value;
print value; // out: nil
println(value); // out: nil
value = 42;
print value; // out: 42;
println(value); // out: 42
```

```shell
Expand Down Expand Up @@ -172,16 +172,16 @@ Program {
fn fizzBuzz(n) {
for (let i = 1; i <= n; i = i + 1) {
if (i % 15 == 0) {
print "FizzBuzz";
println("FizzBuzz");
}
else if (i % 3 == 0) {
print "Fizz";
println("Fizz");
}
else if (i % 5 == 0) {
print "Buzz";
println("Buzz");
}
else {
print i;
println(i);
}
}
}
Expand Down Expand Up @@ -327,6 +327,7 @@ With the syntax and implementation changes so far the Locks language has divered
- Class inheritence: `class Child : Parent {}` -> `class Child extends Parent {}`
- Lists: `[1, 2, 3]`, `arr[0]`, `arr[0] = 123`
- Add the `len` native function for lists and strings
- Change `print` from a statement to a function: `print`, `println`
- Bug Fixes
- Add `#[repr(C)]` to `ObjectNative`. This fixes a segfault that occurred when there were multiple entries in the `Native` enum.
- [Dockerize](Dockerfile) the Locks binary executable
Expand Down
88 changes: 44 additions & 44 deletions playground/src/pages/docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ const Docs: React.FC = () => (
'fn fizzBuzz(n) {',
' for (let i = 1; i <= n; i = i + 1) {',
' if (i % 15 == 0) {',
' print "FizzBuzz";',
' println("FizzBuzz");',
' }',
' else if (i % 3 == 0) {',
' print "Fizz";',
' println("Fizz");',
' }',
' else if (i % 5 == 0) {',
' print "Buzz";',
' println("Buzz");',
' }',
' else {',
' print i;',
' println(i);',
' }',
' }',
'}',
Expand Down Expand Up @@ -214,9 +214,9 @@ const Docs: React.FC = () => (
anchor="variables"
code={[
'let value;',
'print value; // out: nil',
'println(value); // out: nil',
'value = 42;',
'print value; // out: 42;',
'println(value); // out: 42;',
]}
height="75px"
>
Expand All @@ -231,10 +231,10 @@ const Docs: React.FC = () => (
anchor="nil"
code={[
'let value = nil;',
'print nil; // out: nil',
'println(nil); // out: nil',
'',
'fn noReturn() {}',
'print noReturn(); // out: nil',
'println(noReturn()); // out: nil',
]}
height="110px"
>
Expand All @@ -245,16 +245,16 @@ const Docs: React.FC = () => (
title="Numbers"
anchor="numbers"
code={[
'print 123; // out: 123',
'print 123.45; // out: 123.45',
'print -123; // out: -123',
'print -123.45; // out: -123.45',
'print (5 + 7) * 2.5; // out: 30;',
'print 5 % 1; // out: 0',
'print 5 % 2; // out: 1',
'print 5 % 3; // out: 2',
'print 5 % 4; // out: 1',
'print 5 % 5; // out: 0',
'println(123); // out: 123',
'println(123.45); // out: 123.45',
'println(-123); // out: -123',
'println(-123.45); // out: -123.45',
'println((5 + 7) * 2.5); // out: 30;',
'println(5 % 1); // out: 0',
'println(5 % 2); // out: 1',
'println(5 % 3); // out: 2',
'println(5 % 4); // out: 1',
'println(5 % 5); // out: 0',
]}
height="300px"
>
Expand All @@ -264,10 +264,10 @@ const Docs: React.FC = () => (
title="Booleans"
anchor="booleans"
code={[
'print true; // out: true',
'print true and false; // out: false',
'print true or false; // out: true',
'print !true; // out: false',
'println(true); // out: true',
'println(true and false); // out: false',
'println(true or false); // out: true',
'println(!true); // out: false',
]}
height="100px"
>
Expand All @@ -282,7 +282,7 @@ const Docs: React.FC = () => (
'let isTrue = true;',
'',
'if (isTrue) {',
' print "Was true!";',
' println("Was true!");',
'}',
'',
'// out: Was true!',
Expand All @@ -296,9 +296,9 @@ const Docs: React.FC = () => (
'let isTrue = true;',
'',
'if (isTrue) {',
' print "Was true!";',
' println("Was true!");',
'} else {',
' print "Was false!";',
' println("Was false!");',
'}',
'',
'// out: Was true!',
Expand All @@ -309,8 +309,8 @@ const Docs: React.FC = () => (
title="Strings"
anchor="strings"
code={[
'print "Hello World"; // out: Hello World',
'print len("Hello World"); // out: 11',
'println("Hello World"); // out: Hello World',
'println(len("Hello World")); // out: 11',
]}
height="50px"
>
Expand All @@ -319,7 +319,7 @@ const Docs: React.FC = () => (
<DocCard
title="String Concatenation"
anchor="string-concatenation"
code={['print "Hello" +" "+ "World"; // out: Hello World']}
code={['println("Hello" +" "+ "World"); // out: Hello World']}
height="30px"
>
Strings can be concatenated together using the <code>+</code>{' '}
Expand All @@ -333,7 +333,7 @@ const Docs: React.FC = () => (
' return a + b;',
'}',
'',
'print sum(60, 40); // out: 100',
'println(sum(60, 40)); // out: 100',
]}
height="100px"
/>
Expand All @@ -343,7 +343,7 @@ const Docs: React.FC = () => (
code={[
'fn sum (a, b) => a + b;',
'',
'print sum(60, 40); // out: 100',
'println(sum(60, 40)); // out: 100',
]}
height="100px"
/>
Expand All @@ -357,7 +357,7 @@ const Docs: React.FC = () => (
'',
'let add = sum;',
'',
'print add(70, 20); // out: 90',
'println(add(70, 20)); // out: 90',
]}
height="150px"
>
Expand All @@ -376,7 +376,7 @@ const Docs: React.FC = () => (
' return person;',
'}',
'',
'print greet("Hello")("World"); // out: Hello World',
'println(greet("Hello")("World")); // out: Hello World',
]}
height="200px"
>
Expand All @@ -386,8 +386,8 @@ const Docs: React.FC = () => (
title="For Loops"
anchor="for-loops"
code={[
'for (let i = 0; i < 10; i = i + 1) {',
' print i;',
'for (var i = 0; i < 10; i = i + 1) {',
' println(i);',
'}',
'',
'// out: 0',
Expand All @@ -409,7 +409,7 @@ const Docs: React.FC = () => (
code={[
'let a = 1;',
'while (a < 10) {',
' print a;',
' println(a);',
' a = a + 1;',
'}',
'',
Expand Down Expand Up @@ -444,7 +444,7 @@ const Docs: React.FC = () => (
'',
'let greeter = Greeter("Hello");',
'',
'print greeter.greet("World"); // out: Hello World!!!',
'println(greeter.greet("World")); // out: Hello World!!!',
]}
height="325px"
/>
Expand Down Expand Up @@ -473,7 +473,7 @@ const Docs: React.FC = () => (
'',
'let greeter = HelloGreeter();',
'',
'print greeter.greet("World"); // out: Hello World!!!',
'println(greeter.greet("World")); // out: Hello World!!!',
]}
height="425px"
/>
Expand All @@ -496,7 +496,7 @@ const Docs: React.FC = () => (
'',
'let box = Box(123);',
'',
'print box.get(); // out: 123',
'println(box.get()); // out: 123',
]}
height="300px"
/>
Expand All @@ -517,11 +517,11 @@ const Docs: React.FC = () => (
'',
'let box = Box("Hello");',
'',
'print box.get(); // out: Hello',
'println(box.get()); // out: Hello',
'',
'box.value = "World";',
'',
'print box.get(); // out: World',
'println(box.get()); // out: World',
]}
height="350px"
/>
Expand All @@ -531,11 +531,11 @@ const Docs: React.FC = () => (
anchor="lists"
code={[
'let list = [10, 20, 30];',
'print len(list); // out: 3',
'println(len(list)); // out: 3',
'let last = list[2];',
'print last; // out: 30',
'println(last); // out: 30',
'list[1] = list[1] * 2;',
'print list[1]; // out: 40',
'println(list[1]); // out: 40',
]}
height="125px"
>
Expand Down Expand Up @@ -1010,7 +1010,7 @@ const Docs: React.FC = () => (
</div>
<div className="shadow rounded p-3">
<h4>Run Input</h4>
<pre>$ locks exec &squo;print &quot;Hello&quot;;&squo;</pre>
<pre>$ locks exec &squo;println(&quot;Hello&quot;;&squo);</pre>
<pre>$ cat res/benchmarks/fib.locks | locks exec</pre>
</div>
<div className="shadow rounded p-3">
Expand Down
Loading