CuffScript
“As easy as a game, as light as a feather, and as fast as a flash.”
CuffScript is a language built less to perfect any one piece of syntax than to make programming itself feel less intimidating. There is nothing to install or configure: you can run your first line right here on this page.
Latest news
From the CHANGELOG on GitHub: the 3 most recent releases.
Loading…
Why CuffScript
The first wall most people hit when they start learning to program is not logic but unfamiliar symbols and strict rules. After a missing semicolon produces a cryptic error message, it is easy to conclude "I can't think logically", when the real problem is only that you haven't memorized the language's rules yet.
CuffScript started from the idea of lowering that first wall. It uses keywords close to the words people actually use (set, change, do:, end), and when something is wrong it tells you where and why. Each of these choices adds up to an experience where you can understand what you are doing. That doesn't cost expressiveness: functions, asynchronous execution and regex-style pattern matching are all there, and it is a real, working language for small automation scripts or game logic.
The "Cuff" in the name means a sleeve cuff. Like a tool that sits lightly on your wrist and is always within reach, the hope is that you can put the language on without effort and start making something right away. It suits people who have always been afraid of regular expressions, and people who want to run an idea immediately without setting up a project.
Core syntax at a glance
The guide covers the full syntax step by step; here is just a quick look at what it looks like.
| Concept | Code | Notes |
|---|---|---|
| Variable | set number x to 10 | Declare with set, reassign with change ... to |
| Constant | set constant list PRIMES to [2, 3, 5] | Names are ALL-CAPS; lists can be frozen like tuples |
| Conditions and loops | if x > 0 do: ... end | Every block is wrapped in do: ... end |
| Functions | set pure returnable async func f() do: ... end | Combine pure, returnable and async freely |
| Pattern matching | find "[num]+" from text | Readable names like [num] instead of \d |
| Error recovery | risky() or_else do: ... end | Recovers only from calls that raise an error, like a game's restart button |
| Built-in libraries | use DLC:map | 10 libraries: math/string/time/random/list/map/convert/json/network/filesystem |
Browse the documentation
The language guide is organized into the 7 topics below.
Basics
Variables and constants, data types, the colon rule, operators, indexing
Control flow
Conditionals and loops, working with lists and maps
Functions
Defining functions, async (async/await), scope and global
Error handling
or_else and the error code system
Pattern matching
match / find / replace / split / count, quick reference
Modules and libraries
use ... from ..., 10 built-in DLCs
Reference
Common mistakes, known limitations, related links
Example code
A recursive Fibonacci example.
set returnable func fib(n) do:
if n <= 1 do: return n end
return fib(n - 1) + fib(n - 2)
end
print(f"fib(10) = {fib(10)}")
The IDE comes with 10 ready-made examples that take you from basic syntax to modules, in order.
Get started
Try it right away without installing anything, or bring the engine into your own project.
1. In the browser, with nothing to install
The IDE on this site runs the CuffScript engine itself, compiled to WebAssembly, so you can run code immediately without installing anything.
2. Embed in a JS/TS project
With the cuffscript-wasm package you can run CuffScript anywhere, in Node or in the browser.
npm install cuffscript-wasm
3. Build the native CLI yourself
With just a C++17 compiler you can build cuffc straight from source. (Prebuilt binaries aren't provided yet.) File reading and writing (DLC:filesystem) is available only in this native CLI; it is blocked in the browser IDE.
git clone https://github.com/cuffscript/cuffscript.git
cd cuffscript
make
./cuffc your_script.cuff
For more on the syntax, see the language guide; for the history of changes, see the CHANGELOG.
Community & contributing
CuffScript is an open-source project released under the Apache-2.0 license. If you find a bug or want to suggest a feature, please open an issue first. Large features sent as pull requests without prior discussion may be turned down.