r/smalltalk • • Oct 20 '26

Niva: A Smalltalk-like programming language

https://github.com/gavr123456789/Niva
37 Upvotes

8 comments sorted by

6

u/gavr123456789 Oct 20 '26 edited Oct 21 '26

wow, hello, Im the author, Would appreciate any thoughts!
Current status: self hosting is done and soon will be merged.

https://learnxinyminutes.com/niva/
https://gavr123456789.github.io/niva-site/reference.html

Main things: types, exceptions are tagged unions(and more like effects), explicit mutability, inheritance replaced with tagged unions, so the matching always exhaustive, but you can include all the variants of one union into another(https://gavr123456789.github.io/niva-site/unions.html#include-one-union-into-another) so its on the same power level as inheritance\interfaces, but simpler
object capability model, JVM interop

1

u/dharmatech Oct 20 '26

Oh wow... Self-hosting! Very interesting!

Found the branch:

https://github.com/gavr123456789/Niva/tree/self-host

2

u/gavr123456789 Oct 20 '26

stage1 self-hosting in the main branch too: src/NivaInNiva
now its stage2(niva compiles nin, nin compiles nin)

4

u/rsatrioadi Oct 20 '26

Interesting; will keep an eye on it.

2

u/gavr123456789 Oct 20 '26 edited Oct 21 '26

Things I changed in original Smalltalk syntax

\n instead of `.` - some parsing becomes much harder, for example now u need to separate unary messages with `,`, if they span multiple lines(thats the only downside)

1 inc,
  inc,
  inc

| obj syntax for matching, its not possible to express switch in Smalltalk(without makind a map with codeblocks) and now when I have tagged unions, I really need a way to match on them

C nested calls grows like f(g(x))
St nested kw sends grows from the other side
((1 from: 2) from: 3) from: 4
I added `,` syntax sugar to avoid that
1 from: 2, from: 3, from: 4

obviously syntax to define types, it look like a keyword send, union looks like a match `|`
type Person name: String age: Int
since Smalltalk is closed world, there is no difference between class hierarchy and tagged unions beside static dispatch
union Shape = Rectangle x: Int y: Int | Circle r: Int

codeblocs [x y -> x + y]that `->` on par with return type declaration
codebloc with single argument has implicit `it` param
{1 2 3} map: [it * 2], filter: [it % 2 == 0]

literals for basic collections
{} list
#{} hashmap
#() hashset
commas are optional like in Clojure

locals defined as
x = 42 not |x| or :=
its impossible to define uninitialized non-nullable local

syntax sugar for sending kw messages with the same names
obj value1: value1 value2: value2
obj :value1 :value2

1

u/TonyInNY Oct 20 '26

Why? What about your language provides an better solution then other "similar" languages? What issues in the languages you have used lead you to decide to design a new one? What was your motivation?

6

u/gavr123456789 Oct 20 '26 edited Oct 20 '26

"Why?" for Fun!
I have no purpose for a serious new production lang(and I think thats impossible, only python became popular on its own), thats a lang from my dreams, and I think every programmer have smth like that.

-------------
I dont know why I wrote that, but its a pre-story kinda, skip

I really like the simplicity of Smalltalk, "Everything is an object. Object communicate by sending messages" versus "Abstraction. Inheritance. Run-time polymorphism." of Stroustrup.

On my first official job I worked on legacy ERP system implemented in C#(mono) and GTK2. It was written with all SOLID principles(or at least that’s what they thought). It was impossible to navigate, everything was abstract and all the implementations were spread and hidden in 10 different places. Thats where I start to hate java-OOP(also watched https://youtu.be/QM1iUe6IofM )
But then I discovered Pharo Smalltalk
And I realized that OOP was not originally conceived this way at all, things could be much simpler and cleaner. I really liked the fact that in Smalltalk, everything is a message even standard statements like `if` and `while`, so this concept is really powerful (good talk about that uniformity https://youtu.be/Cix0SYZ7CMo ). But at the same time I never coded in dynamically typed lang, ohh so much text, and all useless
--------------

> What about your language provides an better solution then other "similar" languages?

I wanna types, more functional(immutability, tagged unions instead of inheritance) and simplicity like:
Go < Niva < Java < Kotlin < Scala

The whole language is essentially types (type/enum/union) and methods for them, no dynamic dispatch,
I want there to be a way to navigate to the implementation at any time(no inheritance, abstract classes, interfaces)

and explicit errors, but not as bad as checked exceptions in java, or value errors in func langs
and explicit mutability, but so that mutable variables are distinct from mutable types
and object-capability model to track effects, but not as verbose as in algebraic effect systems

I done some research on any langs that tried to add types to Smalltalk syntax.
https://github.com/mpw/Objective-Smalltalk - cool ideas, but thats macos only, obj-C replacer
https://github.com/nikodemus/foolang - dead, no interop
https://github.com/davidgiven/typetalk - cool, it has image based IDE!, web, dead
https://keli-language.gitbook.io/doc - best thing, its motivation is the same
StrongTalk - cool experiment, Win32 only, last version 2007, were bought by Sun Microsystems to work on JVM

> What issues in the languages you have used lead you to decide to design a new one?

I know many langs, and dislike something in every of them.
Smalltalk my beloved. dyn types, closed world(Smalltalk usually calls only Smalltalk, I wanna some rich ecosystem, to make GUI apps\games), image based thats pretty hard to compile to single binary, dont talk about GNU St.

Nim - union types implemented pretty badly, UFCS is cool, exceptions are effects(I stole that)
too complicated, especially with macros powers it becomes unreadable very fast, basically lang has every feature, and all of them are half-baked
D - nim's brother, but C++
Kotlin - too many inheritance from Java, but all the other things are pretty good, best candidate for a lang to find a everyday-job

Gleam - perfect lang actually. Its on the same level of simplicity that I want. It was released after I started to work on niva. Erlang ecosystem has no GUI or game-related frameworks. JS is only for browser.

I can write a book on every thingy that I dont like in some langs, but I will finish here

1

u/UnCoreM Oct 23 '26

Thanks for posting this detail.