Skip to content

Commit

Permalink
Update: Documentation for new sample() prompt syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
KennyOliver committed Jan 20, 2025
1 parent 823f5c5 commit 04577a0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
3 changes: 1 addition & 2 deletions docs/brainf_interpreter.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ create brainf_interpreter(code) {
let character = chr(ascii_val);
serve(character, False);
} elif command == "," {
serve("Input a character:");
let input_char = sample();
let input_char = sample("Input a character:");
let ascii_val = ord(input_char);
data_tape[data_ptr] = ascii_val;
} elif command == "[" {
Expand Down
46 changes: 23 additions & 23 deletions docs/language_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ FlavorLang is a programming language designed with a cooking-inspired syntax, co

### 1. Keywords

| Category | Keyword | Description | Example |
| ------------------------ | --------- | ------------------------------ | --------------------------- |
| **Variable Declaration** | `let` | Mutable variable declaration | `let x = 5;` |
| | `const` | Immutable constant declaration | `const PI = 3.14;` |
| **Control Flow** | `if` | Conditional execution | `if condition { ... }` |
| | `elif` | Alternative condition | `elif condition { ... }` |
| | `else` | Default condition | `else { ... }` |
| | `for` | Loop iteration | `for i in range { ... }` |
| | `while` | Conditional loop | `while condition { ... }` |
| | `break` | Exit loop or switch | `break;` |
| **Pattern Matching** | `check` | Pattern matching construct | `check value { ... }` |
| | `is` | Pattern case | `is pattern:` |
| **Functions** | `create` | Function declaration | `create func() { ... }` |
| | `deliver` | Return value | `deliver result;` |
| **Error Handling** | `try` | Exception handling | `try { ... }` |
| | `rescue` | Error catching | `rescue { ... }` |
| | `finish` | Cleanup block | `finish { ... }` |
| | `burn` | Raise error | `burn "Error message";` |
| **I/O Operations** | `serve` | Output | `serve("message");` |
| | `sample` | Input | `let input = sample();` |
| | `plate` | File write | `plate_file(path, data);` |
| | `garnish` | File append | `garnish_file(path, data);` |
| | `taste` | File read | `taste_file(path);` |
| Category | Keyword | Description | Example |
| ------------------------ | --------- | ------------------------------ | ---------------------------------------- |
| **Variable Declaration** | `let` | Mutable variable declaration | `let x = 5;` |
| | `const` | Immutable constant declaration | `const PI = 3.14;` |
| **Control Flow** | `if` | Conditional execution | `if condition { ... }` |
| | `elif` | Alternative condition | `elif condition { ... }` |
| | `else` | Default condition | `else { ... }` |
| | `for` | Loop iteration | `for i in range { ... }` |
| | `while` | Conditional loop | `while condition { ... }` |
| | `break` | Exit loop or switch | `break;` |
| **Pattern Matching** | `check` | Pattern matching construct | `check value { ... }` |
| | `is` | Pattern case | `is pattern:` |
| **Functions** | `create` | Function declaration | `create func() { ... }` |
| | `deliver` | Return value | `deliver result;` |
| **Error Handling** | `try` | Exception handling | `try { ... }` |
| | `rescue` | Error catching | `rescue { ... }` |
| | `finish` | Cleanup block | `finish { ... }` |
| | `burn` | Raise error | `burn "Error message";` |
| **I/O Operations** | `serve` | Output | `serve("message");` |
| | `sample` | Input | `let input = sample("Enter a number:");` |
| | `plate` | File write | `plate_file(path, data);` |
| | `garnish` | File append | `garnish_file(path, data);` |
| | `taste` | File read | `taste_file(path);` |

### 2. Data Types

Expand Down
10 changes: 7 additions & 3 deletions docs/standard_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The FlavorLang Standard Library provides a comprehensive set of built-in functio
- [`float(value) → float`](#floatvalue--float)
- [`int(value) → int`](#intvalue--int)
- [Input/Output](#inputoutput)
- [`sample() → string`](#sample--string)
- [`sample(prompt) → string`](#sampleprompt--string)
- [`serve(*args, newline=True)`](#serveargs-newlinetrue)
- [Error Handling](#error-handling)
- [`burn(*messages)`](#burnmessages)
Expand Down Expand Up @@ -110,9 +110,13 @@ int("-17"); # -17

### Input/Output

#### `sample() → string`
#### `sample(prompt) → string`

Reads a line of input from the terminal.
Reads a line of input from the terminal with an optional prompt.

**Parameters:**

- `prompt`: any value

**Returns:**

Expand Down
3 changes: 1 addition & 2 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ serve("Multiple", "values", "work"); # Spaces between values
Use `sample()` to get user input:

```js
serve("What's your favorite dish?");
let favorite = sample();
let favorite = sample("What's your favorite dish?");
serve("Ah,", favorite, "is delicious!");
```

Expand Down

0 comments on commit 04577a0

Please sign in to comment.