From Esolang
Jump to: navigation, search

Magic, created by User:GOMADWarrior in 2013, and still in development, is a language where you summon spirits, which are objects with a list of instructions, to do your bidding, with spells which are the recipes of the spirits. It is also meant to be kinda concurrent, as in, one instruction per time, then jump to the next spirit.


In Magic, there are builtin functions, which can return values immediately, and spirits, which must first execute and then after they die you can 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, then enchant it, i.e. 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 a instruction list. Spells are just the instruction list, without it being 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, usually inside an if statement. The main program is itself an spirit, which only 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



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)


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