Getting Started

Installation

git clone https://github.com/gokr/harding.git
cd harding
nimble harding

Requires Nim 2.2.6+

Quick Start

harding              # Interactive REPL
harding script.hrd   # Run a script
harding script.hrd -- one two  # Run with runtime args
harding -e "3 + 4"   # Evaluate expression
harding -e "System arguments size" -- red blue green  # Eval with args
harding --ast script.hrd  # Show AST then execute
harding --loglevel DEBUG script.hrd  # Debug output

Use --loglevel DEBUG for verbose output

Granite Compiler

granite compile myapp.hrd -o myapp
granite build myapp.hrd --release
granite run myapp.hrd

Compile to native binaries with no runtime dependencies

Examples

Hello World

"Hello, World!" println

Factorial

# Extend Number with a factorial method
Number >> factorial [
    (self <= 1) ifTrue: [^ 1].
    ^ self * ((self - 1) factorial)
]

5 factorial println   # 120
10 factorial println  # 3628800

Counter Class

| c |
Counter := Object derive: #(count)
Counter >> initialize [ count := 0 ]
Counter >> value [ ^count ]
Counter >> increment [ ^count := count + 1]

c := Counter new
c initialize
c increment
c value println   # 1

Collections

numbers := #(1 2 3 4 5)
squares := numbers collect: [:n | n * n]
evens := numbers select: [:n | (n % 2) = 0]
sum := numbers inject: 0 into: [:a :n | a + n]

Exception Handling

[
    10 / 0
] on: DivisionByZero do: [:ex |
    Transcript showCr: "Cannot divide by zero!".
    ex resume: 0
]

result println   # 0

New in Current Runtime

Reference Documentation

Language Reference

Project

For Smalltalk Programmers

What feels familiar

  • Message syntax: unary obj size, binary 3 + 4, keyword dict at: key put: value
  • Cascade messages with ;
  • Blocks are proper lexical closures with non-local returns
  • Everything is an object, everything happens via message sends
  • Collection messages: do:, select:, collect:, inject:into:

What's different

  • Optional periods - newlines also separate statements
  • Hash # for comments (not double quotes)
  • Double quotes for strings (not single quotes)
  • Class creation: Point := Object derive: #(x y)
  • File-based, git-friendly source

Key Differences from Smalltalk-80

Feature Smalltalk Harding
Comments "comment" # comment
Strings 'string' "string"
Statement separator Period . only Period or newline
Class creation Class definition Object derive: #(vars)
Persistence Image-based File-based, git-friendly
Execution VM VM or Native compilation (Granite)
Inheritance Single Multiple

No Metaclasses

# Instance method
Person >> greet [ ^ "Hello" ]

# Class method - defined on the class itself
Person class >> newPerson [ ^ self new ]

Bona GTK IDE

Installation

nimble bona    # Build the IDE
./bona         # Launch

Features:

  • Launcher - Start tools and workflows from one place
  • Workspace - Code editor with Do It / Print It / Inspect It
  • Transcript - Output console

Next up: System Browser and Inspector (in progress), with a Debugger planned.

Bona GTK IDE screenshot with Launcher, Workspace, and Transcript
Current Bona build with Launcher, Workspace, and Transcript. Browser and Inspector are next, with Debugger planned.

VSCode Extension

Installation

nimble vsix    # Build the extension
code --install-extension harding-lang-*.vsix

Features:

  • Syntax highlighting with TextMate grammar
  • Language Server Protocol (LSP) - Completions, hover info, go to definition, document/workspace symbols
  • Debug Adapter Protocol (DAP) - Breakpoints, stepping (over/into/out), call stack, variable inspection, watch expressions
  • Comment toggling, bracket matching, code folding

Getting Help

GitHub Issues

Bug reports and feature requests

Open Issues

Discord

Live chat and community support

Join Discord

Discussions

Questions, ideas, and community

Join Discussion

Contributing

Development guidelines and setup

Read Guide