Acorn is a golden love child who inherits valuable features from many languages, such as:
- Ruby's class- and multiple-inheritance, control clauses, implied returns, explicit symbol type, and type-based core library.
- Javascript's prototypical inheritance and easily-propertied objects.
- Lua's gift at packing advanced features (e.g., first-class closures, co-routines, and tail-calls) into a lightweight grammar and architecture.
- Python's off-side rule and context manager.
- YAML's indented, readable format for describing ready-to-use content
Acorn is more than the sum of its borrowed features. It contributes a number of useful improvements:
- parts as internet resources. Every type and part in a world is a distinct program, stored as an internet resource. They are easily snapped together by reference, using the @ operator and a url address. This simple modularity ensures that a world can source its parts from many Internet domains.
- this and self as distinct identifiers. self represents the value a Method is acting on. this represents a value being focused on by a 'this' block within a Method. 'this' blocks are particularly useful for building and manipulating content collections, aided by fundamental operators (such as '.', ':', '<<') which use this for context.
- get/set closures, a closure may bind two methods to the same set of values, one used when getting its 'value' and the other when setting its 'value'. These are invaluable for defining a type's "calculated" (rather than stored) properties. They can also be useful for state hiding and triggering property change events.
- computed properties, that automatically trigger method behavior whenever a value is retrieved or changed.
- pattern matching and decoding, a simple but flexible mechanism (using ~~ and match) which can not only match a value against one or more patterns, but can also select and extract desired values from the source. Since patterns are custom types, countless types of patterns can be defined, each able to intelligently decode, translate or search for elements within a source value whose internal structure matches its criteria.
- generic iterator. A simple, flexible each mechanism for iterating through not only ordered and indexed collections, but also ranges, splats, lazily calculated methods, and custom types.
- Unicode character support. Acorn assumes that characters are Unicode (rather than Ascii). Text and symbol values are collections of properly-indexed Unicode characters. Acorn programs (encoded using UTF-8) permit Unicode characters within variable names.
Acorn is no franken-language, whose dissimilar limbs have been crudely sewn together. Its concise, consistent grammar is more like a pleasing cordial whose excess water has been boiled away, leaving behind a bouquet of flavors that mingle together in sweet harmony.
if you know its heritage languages, Acorn should feel conceptually and grammatically familiar. However, it does vary from their terms and grammar conventions here and there. For example:
- Acorn refers to strings as text. Other core types are similarly given more intuitive english names.
- Single quotes signify a symbol literal, e.g.: 'New'. Double quotes are for text literals.
- The + operator creates a new instance of a type.
- Square brackets are used to declare variable names for an anonymous method or match.
Feature Comparison Chart
The following chart compares Acorn's features with equivalent features from Lua, Javascript and Ruby.
Acorn | Lua | Javascript | Ruby |
Core types - Null - Bool - Integer - Float - Range - Symbol - Text - List - Index - Type - Method - Closure - Yielder |
- nil (Nil) - Boolean - Number - Number (missing) - String - String - Table - Table - Table (metatable) - Function - Closure - Co-routine (thread) |
- null / undefined - Boolean - Number - Number (missing) - Symbol (ES6) - String - Array - Map - Object - Function - Closure - Generator |
- nil (NilClass) - TrueClass / FalseClass - Integer - Float - Range - Symbol - String - Array - Hash - Class - Method - Proc - Fiber |
Text - mutable - Unicode indexing |
- immutable (no) |
- immutable - partial (16-bit) |
- mutable (no) |
Dynamic Types - classical inheritance - prototypical inheritance - multiple inheritance |
(missing) - prototypical inheritance (missing) |
(missing) - prototypical inheritance (missing) |
- classical inheritance (missing) - multiple inheritance |
Variables - global: explicit - local: explicit/implicit - closure: explicit/implicit - instance: explicit - class: namespaced |
- implicit - explicit - implicit (missing) (missing) |
- implicit - explicit/implicit - implicit - this. - namespaced |
- explicit - implicit - implicit - explicit - explicit |
Assignment - embedded/sequential - parallel - arithmetic |
(missing) - parallel (missing) |
- embedded/sequential - parallel - arithmetic/shift/logic |
- embedded/sequential - parallel - arithmetic/logic |
Property and Method Use - [] indexing - property get/set - function call - arithmetic methods - method get/set - calculated method call - new constructor: + - method chain/cascade |
- [] (__index/__newindex) property get/set - function call - arith/shift/bit methods - method get (missing) - .new - method chaining |
- [] (arrays only) - property get/set - function call - built-in arith/shift/bit - method get - computed property names - 'new' constructor - method chain |
- [] method - property get/set - function call - arithmetic/shift methods - method get/set - .method(name).call() - 'new' constructor - method chain |
Method Definition - first-class methods - parameter defaults - ... variable parameters - block scope for locals - multiple return values - implicit return |
first-class functions (missing) - ... - block scope - multiple return values - explicit return |
- first-class functions - parameter defaults - ... - function scope (missing) - explicit return |
- first-class methods - parameter defaults - *variable parameters - method scope - multiple return values - implicit return |
Closures - bind by value - explicit/implicit closures - get/set capability |
- bind by reference - implicit closures (missing) |
- bind by reference - implicit closures (missing) |
- bind by reference - implicit closures (missing) |
Conditional Control - <=> comparisons - if block - while block - ~~ matching - match block - each block - if/while/each clauses |
- __eq, __lt, __le - if block - while block (missing) (missing) - for block (missing) |
(missing) - if block - while block (missing) - switch block - for block (missing) |
- <=> comparisons - if block - while block - ~~ matching - case block - for block - if/while modifiers |
Content Handling - this blocks - build blocks - this operators - @ resource inclusion |
(missing) (missing) (missing) (missing) |
(missing) (missing) (missing) (missing) |
(missing) (missing) (missing) (missing) |