MARGARET
An object oriented language system based on ruby and smalltalk.
Margaret is a modern programming language focused around objects and
messages. It offers powerful literals, easy to use objects and
smalltalk-like message structures.
Every value in Margaret is treated as an object.
(1 + 1) print,
comment: "`1` is an object, `+` is a message",
comment: "comment: is a method to the $Margaret object (yes it
was intentional)",
There are no reserved words and no explicit syntax apart from message sends.
$TrueProto = $Margaret clone,
$true = $TrueProto clone, $TrueProto -- [
#& a_boolean => a_boolean,
#and: alternate_block => alternate_block
value,
#as_bit => 1,
#if_false: alternate_block => $nil,
#if_false: false_alternate_block if_true:
true_alternate_block => true_alternate_block value,
#if_true: alternate_block => alternate_block
value,
#if_true: true_alternate_block if_false:
false_alternate_block => true_alternate_block value,
#not => $false,
#or: alternate_block => @self,
#xor: a_block => a_block value if_true:
$false if_false: $true,
#| a_boolean => $true,
],
$true freeze!,
comment: "That defines `$true` and inserts it into the object
system".
comment: "You guessed it, there exists a similar one for `false`".
Uses prototypal inheritance based on Self or JavaScript.
{ argc, argv |
$Point = $Margaret clone,
$Point attr_reader: [:x, :y],
$Point bind:
#x: xparam y:
yparam => {
@x
= xparam,
@y
= yparam,
@self
},
},
comment: "We bind new methods to existing objects",
Uses C-style literals like int, float, string.
2 + 3 print,
4.2 * 0.1 / 0.01 print,
res = "concat" + "me" + "to" + "something" print,
res get_first_character print,
Implements tensors, tuples, tables and bitstrings as array-like data structures.
['a', "a", 1, 1.0, %{ "k1": 42, k2: 43 }] each:
{ elem |
elem print
}
Runs on a portable, lightweight, embeddable, register based VM inspired by Lua.
$Margaret -- #ultimate_answer: x => {
$true && !false not not && ($nil is_nil?)
if_false: { exit: 0 },
y = @self methods size + @super to_string
length * 42,
[:symbol, ::label, 42, 42.2, "str", 0b0110,
0xbeef, 0o741, %[y, 42, "val"],
%{"k1": 42, k2: 43},
%(42, 1::1, 0::1)] each: { elem | (
puts: elem object_id,
},
if: x < y then: { x }
else: { y },
puts: (ultimate_answer: 42),
Technologies used
................................................................................................................................................................................................
MAIN LANGUAGE
................................................................................................................................................................................................
TESTING
................................................................................................................................................................................................
MEMORY MANAGEMENT
................................................................................................................................................................................................
TERMINAL EMULATION