Magic
Magic, created by User:GOMADWarrior in 2013, and still in development, is a language where you summon spirits, objects with a list of instructions, to do your bidding. You summon spirits with spells, the recipe of the spirits. It is also meant to be kind of concurrent, as in executing one instruction per time before jumping to the next spirit.
Syntax
In Magic, there are builtin functions, which can return values immediately, and spirits, which must first execute then die to take some values from it. It also uses prefix notation for the builtin functions/statements, and you can use parentheses with them to specify precedence. You first conjure an empty spell, enchant it, (add instructions to it), then use it as a recipe to summon a spirit, which is a running process. Spirits have bindings, which are its local variables, and an instruction list. Spells are just an instruction list that isn't running. To pass arguments to spirits when summoning them, you have to use the keyword with. Arguments have to be passed by name, e.g. summon [spiritname] with [varname] [value] and [var2name] [value2] and ... Spirits loop their instruction list, and only stop when unsummon is called. "unsummon" is usually inside an if statement. The main program is itself a spirit that loops once, because an automatic "unsummon self" is added at the end of it. If you had a "skip 1" at the end of your program you'd have some problems. Skip skips n instructions, it's useful for making if blocks, if (cond) {n instructions} is done here with:
if (not cond) skip n n instructions ... rest of the code
Examples
Fibonacci
bind self fib conjure empty enchant fib if (= n 0) unsummon self with a enchant fib set t b enchant fib set b + a b enchant fib set a t enchant fib set n - n 1 bind self result summon fib with a 0 and b 1 and n (read) print (return result)
FizzBuzz
bindself fizzbuzz conjure empty enchant fizzbuzz if (> n 100) unsummon self enchant fizzbuzz if (= (% n 15) 0) and (print "FizzBuzz") (skip 3) enchant fizzbuzz if (= (% n 5) 0) and (print "Buzz") (skip 2) enchant fizzbuzz if (= (% n 3) 0) and (print "Fizz") (skip 1) enchant fizzbuzz print n enchant fizzbuzz set n + n 1 summon fizzbuzz with n 1
External resources
- Magic interpreter in Lua
- Magic interpreter in Javascript (doesn't have (read))