Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
Remove result output when in non-interactive mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeattie committed Sep 20, 2024
1 parent bdedbff commit 4e1da56
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Starship/Rockstar.Engine/rockstar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

Notes on Rockstar grammar

Rockstar has significant whitespace. Most operators, keywords, etc. *must* be separated by _.
Rockstar has significant whitespace. Most operators, keywords, etc.*must* be separated by _.

Rules beginning with _ include their own leading whitespace, so should
go immediately after the preceding expression. Rules ending with _ including their own trailing
whitespace.
Rules beginning with _ include their own leading whitespace, so should go immediately after the preceding expression.

Rules ending with _ including their own trailing whitespace.

*/

Expand Down
9 changes: 6 additions & 3 deletions Starship/Rockstar/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ private static void RunPrompt() {
env.Write("» ");
var line = env.ReadInput();
if (line == null) break;
Run(line, env);
var result = Run(line, env);
Console.WriteLine("« " + result.Value);
}
}

private static void Run(string source, RockstarEnvironment env) {
private static Result Run(string source, RockstarEnvironment env) {
try {
var program = parser.Parse(source);
var result = env.Execute(program);
if (result.WhatToDo == WhatToDo.Exit) Environment.Exit(0);
Console.WriteLine("« " + result.Value);
return result;
} catch (FormatException ex) {
Console.Error.WriteLine(ex);
}

return Result.Unknown;
}
}
18 changes: 8 additions & 10 deletions codewithrockstar.com/docs/08-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ Function arguments must be primary expressions:

{% rockstar_include function-calls-as-arguments.rock %}

The reason you can't use operators inside function arguments is that it makes it awkward to write recursive function calls. Consider this expression:
> The reason you can't use operators inside function arguments is that it makes it awkward to write recursive function calls. Consider this expression
>
> ```
> result = foo taking 1 + foo taking 2
> ```
> ...is that `foo(1 + foo(2)`, or `foo(1 + foo(2))`? Without using parentheses to surround function arguments, the parser can't disambiguate between the two - and since there's no way we're putting parentheses in Rockstar, the only solution is to disallow operators in function arguments.
```
function taking 1 with function taking 2
```

...is that `function(1) + function(2)`, or `function(1 + function(2))`? Without using parentheses to surround function arguments, the *parser* doesn't know which argument goes with which function call.

This is one of the few features where the language **grammar** is ambiguous, and what's produced by the parser doesn't necessarily match what's executed by the interpreter. The parser is greedy and it doesn't know anything about how many arguments a function takes (its *arity*), so this expression:
This is also one of the few features where the language **grammar** is ambiguous, and what's produced by the parser doesn't necessarily match what's executed by the interpreter. The parser is greedy and it doesn't know anything about how many arguments a function takes (its *arity*), so this expression:
```rockstar
FuncA taking FuncB taking 1, 2, FuncB taking 3, 4
Expand All @@ -49,7 +48,7 @@ function call: FuncA
4
```

That's actually wrong, because it'll try to invoke FuncB with three arguments - so rather than failing, the Rockstar interpreter only evaluates as many function arguments as the function is expecting, and any "leftover" expressions will be passed back to the outer function call, so what actually gets executed is:
Thing is, FuncB doesn't take three arguments - so rather than failing, the Rockstar interpreter only evaluates as many function arguments as the function is expecting, and any "leftover" expressions will be passed back to the outer function call, so what actually gets executed is:

```
call: FuncA
Expand All @@ -75,7 +74,6 @@ To declare a function with no arguments, specify it `takes null` (or aliases `no
```rockstar
{% rockstar_include functions-with-no-arguments.rock %}
```

### Variables, Closures and Function Scope
Rockstar uses the same scoping mechanism as JavaScript:

Expand Down
Binary file modified codewithrockstar.com/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion codewithrockstar.com/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h3><i class="fa-solid fa-book-open-cover"></i> Show Me The Way</h3>
</section>
<section>
<div>
<h3><i class="fa-solid fa-shirt"></i> Sharp Dressed man(1)</h3>
<h3><i class="fa-solid fa-shirt"></i> Denim &amp; Leather</h3>
<p>Wear your Rockstar credentials right next to your heart with
shirts from our Teemill store.</p>
</div>
Expand Down
Binary file modified rockstar-icon.ico
Binary file not shown.

0 comments on commit 4e1da56

Please sign in to comment.