Tribalify

所属分类:编程语言基础
开发工具:Nim
文件大小:0KB
下载次数:0
上传日期:2023-08-26 22:28:03
上 传 者sh-1993
说明:  Nim库添加了来自indev编程语言Tribal的糖语法,试图使Nim更像Tribal语言。,
(Nim library that adds sugar syntax from indev programming language Tribal, trying to make Nim feel more like Tribal language.,)

文件列表:
Tribalify-tribalify/ (0, 2023-09-24)
Tribalify-tribalify/examples.nim (1599, 2023-09-24)
Tribalify-tribalify/tribalify.nim (7731, 2023-09-24)
Tribalify-tribalify/tribalify.nimble (286, 2023-09-24)
Tribalify-tribalify/tribalify.png (151605, 2023-09-24)
Tribalify-tribalify/tribalify/ (0, 2023-09-24)
Tribalify-tribalify/tribalify/experimental.nim (1174, 2023-09-24)
Tribalify-tribalify/tribalify/langs/ (0, 2023-09-24)
Tribalify-tribalify/tribalify/langs/ruby.nim (1157, 2023-09-24)
Tribalify-tribalify/tribalify/langs/rust.nim (652, 2023-09-24)
Tribalify-tribalify/tribalify/pure.nim (199, 2023-09-24)
Tribalify-tribalify/tribalify/std.nim (199, 2023-09-24)

![](https://github.com/Toma400/Tribalify/blob/master/tribalify.png) **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. ### Contents - [Why Tribalify](https://github.com/Toma400/Tribalify/blob/master/#why-tribalify) - [Installation & usage](https://github.com/Toma400/Tribalify/blob/master/#installation--usage) - Features - [New types](https://github.com/Toma400/Tribalify/blob/master/#new-types) - [Aliases](https://github.com/Toma400/Tribalify/blob/master/#aliases) - [Functionalities](https://github.com/Toma400/Tribalify/blob/master/#functionalities) - [Syntax sugar](https://github.com/Toma400/Tribalify/blob/master/#syntax-sugar) - [Experimental features](https://github.com/Toma400/Tribalify/blob/master/#experimental) ### Why Tribalify? 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. ### Installation & usage Write following command in your terminal to install Tribalify using Nimble: ```commandline nimble install https://github.com/Toma400/Tribalify ``` Once it is done, you can use Tribalify features simply after importing: ```nim 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 ``` ### New types - `pair(F, S)` - convenience type for double values: - initialise with `newPair()` proc - can be stringified (`$`) to get string repr - use `.first` and `.second` to get specific field - use `.toPair` to convert tuple of 2 values to pair - `triad(F, S, T)` - convenience type for triple values: - initialise with `newTriad()` proc - can be stringified (`$`) to get string repr - use `.first`, `.second` and `.third` to get specific field - use `.toTriad` to convert tuple of 3 values to triad ### Aliases - Types: - `str` - alias for `string` type - Operators: - `&&` - alias for `and` - `||` - alias for `or` - `<>` - alias for `xor` (exclusive OR) - Procs: - `whisper(str)` - proc imitating `echo`. Also aliased as `puts(str)` - `scribe(str)` - proc imitating `readLine(stdin)` but with additional string evoking echo. Also aliased as `gets(str)` ### Functionalities - `tab` - key used to separate sections of code aesthetically. Similar to Nim's `block`, but does not create new scope. Example code: ```nim 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 scope ``` - `end` - key used to optionally signify end of the identation. Aimed mostly at Ruby coders or those who like such system. Tribalify's `end` has several variations: ```nim 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 ``` ### Syntax sugar - `` - append elements to mutable collection-like types. Works on every type that implements `.add` function, as it basically uses it in template - `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 ... `. - `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 ... `. --- If you don't know how any of those concepts should be written, look at `examples.nim` file to see code references. --- ### Experimental 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.

近期下载者

相关文件


收藏者