Tribalify is syntax sugar library aimed on creating Nim interface for
indev programming language called Tribal.
Tribalify offers Tribal features by adding them onto Nim experience by use of macros,
templates and other procedures. They are all available under tribalify file.
Take in mind that Tribalify's syntax may differ from pure Tribal. This is because the library tries to incorporate itself into current Nim language.
Just because I love Nim, but there are some things from Tribal language ideas that I wanted to see there as well. Tribalify is actually heavily inspired by other few libraries that bring my beloved languages into Nim:
- classes - introducing Python-like OOP with class type
- questionable - introducing Kotlin-like syntax sugar for Option
- results - introducing Rust-like Result type
- with - introducing JS-like deprecated 'with' feature
So, with such legacy, Tribalify was made as final step. It will try to be as small as possible, yet trying to add as many Tribal-like features as it can.
Write following command in your terminal to install Tribalify using Nimble:
nimble install https://github.com/Toma400/Tribalify
Once it is done, you can use Tribalify features simply after importing:
import tribalify
var i = newPair("Tom", "Parker")
whisper("Name of your son is: " & i.first)Nimble by default installs latest release of Tribalify, so you may not be able to
use currently indev features (marked with ⚙️ emoji).
If you want to play with new features before library updates, you can also use
this command in terminal instead:
nimble install https://github.com/Toma400/Tribalify@#HEAD
pair(F, S)- convenience type for double values:- initialise with
newPair()proc - can be stringified (
$) to get string repr - use
.firstand.secondto get specific field - use
.toPairto convert tuple of 2 values to pair ⚙️
- initialise with
triad(F, S, T)- convenience type for triple values:- initialise with
newTriad()proc - can be stringified (
$) to get string repr - use
.first,.secondand.thirdto get specific field - use
.toTriadto convert tuple of 3 values to triad ⚙️
- initialise with
- Types:
str- alias forstringtype
- Operators:
&&- alias forand||- alias foror<>- alias forxor(exclusive OR)
- Procs:
whisper(str)- proc imitatingecho. Also aliased asputs(str)scribe(str)- proc imitatingreadLine(stdin)but with additional string evoking echo. Also aliased asgets(str)
- ability to multiply strings or characters
let str = "hello!"
assert str * 2 == "hello!hello!"tab- key used to separate sections of code aesthetically. Similar to Nim'sblock, but does not create new scope. Example code:
block:
var i = 5
echo i # will result in error, 'i' declared in different scope
tab:
var y = 5
echo y # will work nicely, 'y' is in the same scopeend- key used to optionally signify end of the identation. Aimed mostly at Ruby coders or those who like such system. Tribalify'sendhas several variations:
if 1 == 1: # endIf for conditions
discard
endIf
while true: # endLoop for loops
discard
endLoop
proc x(): string = # endProc for procs
"Hello world"
endProc
block:
tab:
echo "It supports Tribalify's tab too!"
endTab
endBlock<!and!>- append elements to mutable collection-like types. Works on every type that
implements
.addfunction, as it basically uses it in template
- append elements to mutable collection-like types. Works on every type that
implements
isAny(T, varargs[T])⚙️- let you check if first argument is any of next args. Equivalent of
if T == A or T == B or T == C ....
- let you check if first argument is any of next args. Equivalent of
isAll(T, varargs[T])⚙️- let you check if first argument is all of next args. Equivalent of
if T == A and T == B and T == C ....
- let you check if first argument is all of next args. Equivalent of
If you don't know how any of those concepts should be written, look at examples.nim
file to see code references.
You can use import tribalify/experimental to import features that are experimental
and not ready to use yet. Check experimental.nim file for further details.
