Everything that makes Harding special
Harding preserves the essence of Smalltalk:
^ return3 + 4 # binary message
obj size # unary message
dict at: key put: value # keyword message
# Blocks with non-local return
findPositive := [:arr |
arr do: [:n |
(n > 0) ifTrue: [^ n]
].
^ nil
]
Optional periods, hash comments, double-quoted strings:
# for comments# This is a comment
x := 1 # No period needed
y := 2
z := x + y # But periods work too
"Double quotes for strings"
Create classes dynamically with slots and methods:
derive:# Create a new class with two instance variables
Point := Object derive: #(x y)
# Add methods
Point extend: [
self >> x: anX y: aY [
x := anX
y := aY
]
self >> moveBy: dx and: dy [
x := x + dx
y := y + dy
]
self >> distanceFromOrigin [
^ ((x * x) + (y * y)) sqrt
]
]
# Use it
p := Point new
p x: 3 y: 4
p distanceFromOrigin println # 5.0
Cooperative multitasking with first-class Process objects:
worker := Processor fork: [
1 to: 10 do: [:i |
i println
Processor yield
]
]
worker suspend
worker resume
worker terminate
Each Process runs in its own stackless VM, enabling lightweight processes and a path to true parallelism.
Interactive development with immediate feedback:
$ harding
Harding REPL (:help for commands, :quit to exit)
harding> 3 + 4
7
> Point := Object derive: #(x y)
Point
> p := Point new
Point instance
> p x: 10
10
> p x
10
Arrays, Tables, and all the classic Smalltalk collection methods:
#(1 2 3)#{"key" -> "value"}do:, collect:, select:inject:into:, detect:# Array literal
numbers := #(1 2 3 4 5)
# Table literal
scores := #{"Alice" -> 95, "Bob" -> 87}
# Collection methods
numbers do: [:n | n println]
squares := numbers collect: [:n | n * n]
evens := numbers select: [:n | (n \ 2) = 0]
sum := numbers inject: 0 into: [:acc :n | acc + n]