|
1 | 1 | #  |
2 | 2 |
|
3 | | - |
4 | | -| Feature | Plastic | Rust | |
| 3 | +| Feature | Plastic (Current) | Rust | |
5 | 4 | | --------------------- | ----------------------- | ----------------------------------- | |
6 | | -| Keywords | Basic | Extensive | |
7 | | -| Data Types | Basic (`i32`, `string`) | Rich (`u8`, `char`, `()`, `&str`) | |
8 | | -| Ownership & Borrowing | ❌ Not Present | ✅ Core Feature | |
9 | | -| Functions | Basic syntax | Advanced (generics, lifetimes) | |
10 | | -| Variables | Basic (`let`) | `let`, `mut`, patterns, annotations | |
11 | | -| Operators | Limited | Full set | |
| 5 | +| Keywords | Basic + Error Handling | Extensive | |
| 6 | +| Data Types | Basic + List/Map/Array | Rich (`u8`, `char`, `()`, `&str`) | |
| 7 | +| Ownership & Borrowing | 🚧 Partial (WIP) | ✅ Core Feature | |
| 8 | +| Functions | Basic, DLL Import, Closures | Advanced (generics, lifetimes) | |
| 9 | +| Variables | `let`, `mut`, `pub` | `let`, `mut`, patterns, annotations | |
| 10 | +| Operators | Arithmetic, Logical, Custom | Full set | |
12 | 11 | | Comments | `//` only | `//`, `/* */`, doc comments | |
13 | | -| Structs/Traits | ❌ | ✅ (`struct`, `trait`, `enum`) | |
| 12 | +| Structs/Traits/Enums | ✅ Supported | ✅ (`struct`, `trait`, `enum`) | |
| 13 | +| Error Handling | `try`, `catch`, `throw`, `finally` | Advanced (`Result`, `panic!`) | |
| 14 | +| Imports/Plugins | `import`, `reference`, `using`, DLL | Advanced modules, crates | |
| 15 | +| File/Process I/O | ✅ Built-in | Via stdlib | |
| 16 | +| HTTP/Localhost | ✅ Built-in server | Via crates | |
| 17 | +| Concurrency | Channels, Threads | Advanced (async, threads, channels) | |
14 | 18 |
|
15 | 19 | --- |
16 | 20 |
|
17 | | -### Explanation of Plastic |
| 21 | +## Plastic Language Overview |
| 22 | + |
| 23 | +### **Keywords & Syntax** |
| 24 | +Plastic now supports a broader set of keywords, including: |
| 25 | +- Control flow: `fn`, `let`, `mut`, `pub`, `if`, `else`, `while`, `for`, `return`, `match` |
| 26 | +- Data modeling: `struct`, `enum`, `trait`, `impl`, `interface` |
| 27 | +- Error handling: `try`, `catch`, `throw`, `finally` |
| 28 | +- Imports: `import`, `reference`, `using`, `dllimport` |
| 29 | +- Others: `self`, `as`, `in`, `true`, `false` |
| 30 | + |
| 31 | +### **Data Types** |
| 32 | +- **Primitives:** `i32`, `i64`, `f32`, `f64`, `bool`, `string`, `void` |
| 33 | +- **Collections:** `array`, `list`, `map`, `List<string>` |
| 34 | +- **User-defined:** `struct`, `enum`, `trait` |
| 35 | +- **Function types:** `fn(...) -> ...` |
| 36 | +- **Special:** `any` |
| 37 | + |
| 38 | +### **Ownership & Borrowing** |
| 39 | +- Plastic has experimental support for ownership and borrowing checks in the type checker (WIP). |
| 40 | +- Mutable and reference types: `mut`, `&`, `&mut` in function parameters. |
| 41 | + |
| 42 | +### **Functions** |
| 43 | +- Standard function declarations. |
| 44 | +- Support for closures and function types. |
| 45 | +- DLL import: Call native functions via `dllimport`. |
| 46 | + |
| 47 | +### **Variables** |
| 48 | +- `let` for variable binding. |
| 49 | +- `mut` for mutability. |
| 50 | +- `pub` for public visibility. |
| 51 | + |
| 52 | +### **Operators** |
| 53 | +- Arithmetic: `+`, `-`, `*`, `/`, `%` |
| 54 | +- Logical: `&&`, `||`, `&|` (and-or) |
| 55 | +- Comparison: `==`, `!=`, `<`, `<=`, `>`, `>=` |
| 56 | +- Assignment: `=` |
| 57 | +- Custom: e.g., `added` as an alias for `+` |
18 | 58 |
|
19 | | -#### **Keywords** |
20 | | -Plastic includes only the essential keywords needed for basic programming, such as `fn`, `let`, `if`, `while`, `for`, and `return`. Its concise syntax helps keep the language simple and easy to learn. |
| 59 | +### **Comments** |
| 60 | +- Single-line comments: `//` |
21 | 61 |
|
22 | | -#### **Data Types** |
23 | | -Plastic’s type system is straightforward, offering a few numeric types like `i32` and a basic `string` type. This makes it ideal for simple scripting and learning programming basics without the complexity of a rich type system. |
| 62 | +### **Structs, Enums, Traits** |
| 63 | +- User-defined types: `struct`, `enum`, `trait`, `impl` |
| 64 | +- Traits and trait implementations for polymorphism. |
24 | 65 |
|
25 | | -#### **Ownership & Borrowing** |
26 | | -Unlike languages such as Rust, Plastic does not implement ownership or borrowing. Memory management is kept simple, and these advanced concepts are not part of the language, which further contributes to its minimalistic design. |
| 66 | +### **Error Handling** |
| 67 | +- `try`, `catch`, `throw`, `finally` blocks for robust error management. |
27 | 68 |
|
28 | | -#### **Functions** |
29 | | -Functions in Plastic are defined with a simple syntax. Each function specifies its name, an optional parameter list (with types for each parameter), and a fixed return type. This consistent syntax ensures clarity in function declarations and calls. |
| 69 | +### **Imports & Plugins** |
| 70 | +- `import`, `reference`, `using` for code and plugin loading. |
| 71 | +- `dllimport` for native interop. |
| 72 | + |
| 73 | +### **File and Process I/O** |
| 74 | +- Built-in functions: `readFile`, `writeFile`, `appendFile`, `deleteFile`, `exists`, `mkdir`, `rmdir`, `listDir`, `copyFile`, `moveFile`, `renameFile` |
| 75 | +- Process control: `runProcess`, `runProcessAndWait`, `openFile`, `command` |
| 76 | + |
| 77 | +### **HTTP/Localhost Support** |
| 78 | +- Start a local HTTP server: `startHttpServer(port)` |
| 79 | +- Access HTTP request data: `GetHttpRequestData()`, `GetHttpRequestMethod()`, `GetHttpRequestPath()` |
| 80 | +- Respond to HTTP requests: `SetHttpResponse(response)` |
| 81 | +- HTTP client: `curl(url, method, data, headers)` |
| 82 | + |
| 83 | +### **Concurrency & Channels** |
| 84 | +- Threading: `CreateNewThread(source, input)` |
| 85 | +- Channels: `SendToChannel(value)`, `ReceiveFromChannel()`, `GetChannelCount()` |
| 86 | + |
| 87 | +### **Other Built-ins** |
| 88 | +- String/number utilities: `len`, `parseInt`, `parseFloat`, `toString`, `toInt`, `toFloat`, `toUpper`, `toLower`, `trim`, `split`, `join`, `contains`, etc. |
| 89 | +- Time/date: `now`, `timestamp`, `formatDate`, `time` |
| 90 | +- Random: `random` |
| 91 | +- UUID: `uuid`, `GenerateUUID` |
| 92 | +- Environment: `env`, `GetEnvironmentVariable`, `GetCurrentDirectory`, `GetCurrentProcessId` |
| 93 | +- Logging: `log`, `error`, `showErrorBox`, `showConfirmBox` |
| 94 | +- JSON: `ParseJSON`, `SerializeJSON` |
| 95 | +- Math: `abs`, `floor`, `ceil`, `round`, `sqrt`, `pow`, `max`, `min`, `clamp` |
| 96 | +- Binary/Morse/Hash: `ConvertToBinary`, `BinaryToConvert`, `ConvertToMorse`, `MorseToConvert`, `Hash`, `VerifyHash` |
| 97 | +- Garbage collection: `CollectGarbage` |
| 98 | + |
| 99 | +--- |
30 | 100 |
|
31 | | -#### **Variables** |
32 | | -Variables in Plastic are introduced using `let`. There is no explicit mechanism for mutable variables or variable destructuring. The language focuses on straightforward, immutable variable binding. |
| 101 | +## Example: Localhost HTTP Server |
33 | 102 |
|
34 | | -#### **Operators** |
35 | | -Plastic provides basic operators for arithmetic and string concatenation. The limited operator set is sufficient for scripting and educational purposes, avoiding the complexity found in languages with a full operator suite. |
36 | 103 |
|
37 | | -#### **Comments** |
38 | | -Plastic supports single-line comments using `//`. This keeps the language simple and is often enough for small scripts and tutorials, without the added complexity of block comments or documentation-specific syntax. |
| 104 | +``` |
| 105 | +startHttpServer("8080"); |
| 106 | +while (true) { |
| 107 | + let method: string = GetHttpRequestMethod(); |
| 108 | + let path: string = GetHttpRequestPath(); |
| 109 | + let data: string = GetHttpRequestData(); |
| 110 | + print("Received", method, path, data); |
| 111 | + SetHttpResponse("Hello from Plastic!"); |
| 112 | +} |
39 | 113 |
|
40 | | -#### **Structs / Traits** |
41 | | -Currently, Plastic does not support user-defined data structures such as `structs`, `enums`, or `traits`. Its design is streamlined, focusing on core scripting capabilities without the overhead of advanced data modeling features. |
| 114 | +``` |
| 115 | + |
| 116 | +## Example: File I/O |
| 117 | + |
| 118 | + |
| 119 | +``` |
| 120 | +writeFile("test.txt", "Hello, file!"); |
| 121 | +let content: string = readFile("test.txt"); |
| 122 | +print(content); |
| 123 | +
|
| 124 | +``` |
| 125 | + |
| 126 | +## Example: Concurrency |
| 127 | + |
| 128 | + |
| 129 | +``` |
| 130 | +SendToChannel("hello"); |
| 131 | +let msg: string = ReceiveFromChannel(); |
| 132 | +print(msg); |
| 133 | +``` |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +> **Note:** Plastic is evolving rapidly. See the [Plastic Syntax in Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=QuantumLeapStudios.plastic-language) for up-to-date syntax highlighting and tooling. |
| 138 | +
|
| 139 | +--- |
42 | 140 |
|
43 | | -> **Note:** The Rust column in the comparison table is provided for reference only, to offer context about features found in more advanced languages. The primary focus here is on explaining Plastic and its design choices. |
| 141 | +**Summary of Recent Additions:** |
| 142 | +- Localhost HTTP server and request/response API |
| 143 | +- File and directory operations |
| 144 | +- Process and command execution |
| 145 | +- Channels and threading |
| 146 | +- Structs, enums, traits, and implementations |
| 147 | +- Error handling with try/catch/finally/throw |
| 148 | +- Many new built-in functions for scripting, system, and utility tasks |
44 | 149 |
|
45 | 150 | --- |
46 | 151 |
|
47 | | -🔗 **Syntax Highlighting for Plastic** |
48 | | -[Plastic Syntax in Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=QuantumLeapStudios.plastic-language) |
| 152 | +Feel free to further expand or reorganize this as needed for your documentation site or repository! |
0 commit comments