Ni – A language influenced by Smalltalk written in Nim
goran.krampe.se
goran.krampe.se
"Ni is meant to mix with Nim. The idea is to use Nim for heavylifting and binding with the outside world, and then let Ni be a 100% live dynamically typed scripting engine inside Nim. Ni will stay a very small language, but hopefully useful."
Writing in Smalltalk or Lisp in order to control a more conservative language such as Nim would appear to be a winning idea.
I'd be interested to learn more about the difference between the approach taken by Ni, and the one taken by Hy or Clojure. In the latter two, S-expressions are transformed into the AST (or directly to bytecode) of the host language.
The author of Ni seems to have defined a new AST, and then written an interpreter in Nim:
"Ni comes in two modules, the parser (500 loc) and the interpreter (750 loc). The parser produces an AST which is also the internal representation of data in Ni. The interpreter then interprets the AST."
Perhaps this was necessary due to the more static nature of Nim compared Python or the JVM.
http://www.red-lang.org/2013/11/041-introducing-parse.html
Red is in fact very impressive and definitely the "modern Rebol".
However in terms of the language (syntax & semantics) then Rebol 3 is definitely the "modern Rebol". Have a look at Ren/C for the new ideas and the very latest development of the Rebol 3 codebase - https://github.com/metaeducation/ren-c
There were knights once upon a time who did indeed say Ni, but it is no longer so.
Concerning the language itself, the block-based Lisp influence taken from REBOL is noteworthy. The latter is quite underappreciated in general.
I even think Ni is turning out more readable than Rebol/Red - probably due to the use of keyword syntax and infix arguments. And the idea with arg words made lambdas very lightweight, much more so than in Rebol.
For example, here is a very naive version:
lambda: function [block] [
args: sort unique collect [
parse block [
any [
w: set arg get-word! (
keep to-word arg
change w to-word arg
)
| skip
]
]
]
function args block
]
test in REPL... >> f: lambda [:a + :b]
>> f 1 2
== 3
>> foo: lambda [c: :a + :b print [:a "+" :b "=" c]]
>> foo 1 2
1 + 2 = 3
NB. However you wouldn't really use :arg-name here because this is already reserved for the get-word! datatype.However... if I understand your code properly - you are basically generating an argument declaration by scanning for "get words". So its still a static declaration.
In Ni an arg word is an operation. That means a Ni func can decide how many arguments to pull, and in which order, dynamically, much like stack oriented languages can do. Usefulness? Dunno :) But its not the same.
Also, yes, I opted out of set words in Ni since I want to be able to have keyword syntax á la Smalltalk/Self. And I use "^" instead of ":" prefix for get words, because I wanted the argwords to be similar to how they look in Smalltalk. :)