presidentbeef/brat
{ "createdAt": "2009-04-20T06:10:27Z", "defaultBranch": "main", "description": "Brat is a little language for people who don't like to be told what to do.", "fullName": "presidentbeef/brat", "homepage": "https://www.brat-lang.info/", "language": "C", "name": "brat", "pushedAt": "2022-10-08T16:34:30Z", "stargazersCount": 97, "topics": [ "brat", "language", "lua", "luajit", "programming-language" ], "updatedAt": "2025-11-11T09:07:04Z", "url": "https://github.com/presidentbeef/brat"}Brat is a simple little toy language that lets you do what you want. It is primarily object-oriented with first-class functions and very little syntax.
Brat is flexible enough that you can get by with a very small core and write any functionality that most languages use keywords for. For example, you can write and use a while loop like so:
# Loops until the block returns falsewhile = { block | true? block, { while ->block }}
# Print 1 through 9n = 1while { p n n = n + 1 n < 10}If you would rather have your conditions be separated out, you could define it this way instead:
# Loops until condition is falsewhile = { condition, block | true? condition, { block; while ->condition, ->block }}
n = 1while { n < 10 } { p n; n = n + 1 }Brat compiles to Lua and runs on LuaJit.
Features
Section titled “Features”- Dynamically typed
- Everything is object, except functions
- And functions are closures, which can be attached to objects to make methods
- Objects use a prototyping system and are completely open
- Built-in hash tables and dynamic arrays
- Very flexible unary and binary operators
- Tail calls are optimized to make infinite loops faster (and more infinite)
Requirements
Section titled “Requirements”Please have on hand:
- Linux or OS X
- The usual development tools (like
makeandgcc) - Git if you want to check it out of the repository directly -
sudo urpmi git-core(or the equivalent for your platform)
Installation
Section titled “Installation”Please follow the following steps, in the order in which they are ordered. Otherwise, results are not guaranteed.
With Git:
- Clone the latest Brat version:
git clone git://github.com/presidentbeef/brat.git - Change to new directory:
cd brat - Run
sh ./build.sh - Optionally, run
sudo sh ./install.sh. This will install in/usrby default. Append a directory to change this.
Without Git:
- Download the latest
- Decompress the archive (
unzip brat-master.zip) - Change to the new directory (
cd brat-master) - Run
sh ./build.sh - Optionally, run
sudo sh ./install.sh. This will install in/usrby default. Append a directory to change this.
Testing
Section titled “Testing”Try out your newly discovered power thusly:
- Create a new file, perhaps called
test.brat - In that file, type something like:
p "OK COMPUTER" - Save and close it
- Return to the comfort of your command line
- Type
brat test.brat(or./brat test.bratif you did not run the install script) - Cross fingers
- Press enter
- Marvel or weep, as appropriate
More Testing
Section titled “More Testing”Run brat test/test.brat to run the test suite. SWEET.
More fun
Section titled “More fun”Running Brat without specifying a file will launch interactive mode.
$ ./brat# Interactive Bratbrat:1> 1 + 1#=> 2Even more fun
Section titled “Even more fun”Take a look at some examples of Brat code.
Problems
Section titled “Problems”Sometimes there are problems. Everyone has issues. Report Brat issues here.
License
Section titled “License”The MIT License
Copyright (c) 2009-2019, Justin Collins
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.