---
abstract: The Next Generation Programming Language
lastupdated: 2012
---

# MagicNG

*2012.*


# Chapter 1: The Future of Yesterday

*Software.*

*Magic.*

Two seemingly unrelated words. Yet together they form the essentials of the new
programming language which has already changed how computers and humans interact
with each other: *MagicNG* (short for Magic: The Next Generation).

**MagicNG** is not your common programming language; it is not biased towards one
 or two paradigms, in fact it uses none of the existing ways of programming:

+ Functional programming is, naturally, much too functional for any magic-based
  programming language, as magic is not *functional*, but
  *magical*. Magic-based software does not require functionality as in something
  being able to do something else, because it depends on magic which *does*
  stuff instead of making sure that *stuff* can be done; this makes using a
  computer much faster.
+ Object-oriented programming does not fit very well with the ideas behind
  **MagicNG** either. While the magic-oriented approach *is* able to properly
  emulate object-oriented ways of doing things, such emulations will often
  require CMU-expensive ('Central Magical Unit') conversions from spell
  scrolls to object-based representations.
+ Procedural programming conflicts with the nature of magic; since in the case
  of magic, advanced heuristics are used run a program, the simple approach of
  procedurally executing commands pales in comparison to the magical
  approach. The same is true for assembly programming and machine programming.
+ Logic programming is mute. Magic is always above logic. Logic is based on
  magic. Everyone knows that.
+ Declarative programming is actually the only one of the existing widespread
  paradigms which is even slightly like *magical programming*. Declarative
  programming languages do, however, still base their entire existence on
  deduction and knowledge, both of which are infinitely long below the
  standards of magical programming languages. Deduction and knowledge are for
  programming languages that do not *see* how everything works, whose authors
  do not understand the connectionabilities of everything.

In short, **MagicNG** employs the *magical programming* paradigm because it is
superior to non-magical approaches.


## But how do I program in it?

The reader should now be comfortable thinking about programming in terms of
magic and be able to see what a big mistake it was to learn all those outdated,
logic-based programming languages. The reader might also be a little
overwhelmed and perhaps confused; but fear not, we will soon take a look at an
example of MagicNG programming.

Before we get to that, we will go over a few (yes, there are many more) of the
applications of magical programming, to pique the reader's curiosity.

1. First, there is the temporal improvement. Since magic is independent of the
   flow of time, a program can be run not just everywhere, but
   every*when*. This is the sole reason MagicNG is already so popular ---
   someone spread its use many years ago, through several temporal-offset
   MagicNG runs.
2. Speed. The Central Magical Unit runs programs magically many times faster
   than any CPU in existence. This is possible due both to the previously
   explained effects of magic in programming *and* what we will come to refer
   as "magic downleveling" in later chapters (since magic cannot be optimized,
   other approaches such as the downleveling approach have been developed).
3. Code maintenance also becomes much easier, as you will see in the examples
   and excercises.

Now, to our first example. We wish to print to a computer console (on a magical
computer) the magical string "Hello, world!". This is often accomplished in
anything from 1 to 100 conventional lines in conventional programming
languages; in MagicNG, it is not *that* simple. It's another kind of simple,
namely the *magic simple* way, from now on referred to as the *magple* way.

To write the magple MagicNG code for this example, we first fire up our MagicNG
interactive interpreter:

```
MagicNG vX
?
```

(MagicNG is not being developed because it relies on magic for updates, hence
the 'X' version.)

(The correct way to program in MagicNG is to write on pergament scrolls, but
for the beginner it is often easier to write the magical expressions on one's
computer and then print afterwards.)

The `?` at the prompt means we can type something. Let us try typing the
following:

```
? one frog eye
```

What this tells the MagicNG interpreter is that if *it is not the case* that no
frog eyes exist in the programmer's vicinity, it will print "Hello,
world!". The frog-eye detection is only a formality, included in MagicNG to
make the proofs of magical truth be magically true, and so the sentence can be
excluded if the programmer wishes so. That is, you could write

```
t
```

which is short for "one frog eye", and it would have the same effects.

MagicNG programs can be compiled (printed) to scrolls, which can then be used
independently of a running magical computer.

(Trivia: This was in fact one of the major reasons why the text-based nature of
MagicNG was chosen over the two other proposed ways of programming: speech and
jumping. While speech had the advantage that it worked well for people who had
difficulties writing, history had shown that the human memory was not a good
place to store information not meant to be changed. And while jumping was good
for people who were only good at jumping, it was too radical an approach for
many of the language designers.)

Now, it may not be obvious to the casual non-magician why and how both "one
frog eye" and "t" eventually prints "Hello, world!". In fact, these two
expressions are not at all the only ways to print "Hello, world!" --- one can
also write "traveller with seven legs", "spider queen", or something
similar. The thing to remember is that it is *the intention* that counts. If
you *feel* that the expression "bonsai of Norway" prints the sum of all
prime numbers below 4012, then *that is what it does*.

In essence, MagicNG is an *intention-based programming language*. This might at
first sound like all other programming languages: You have an intention on
which you base your programming. The difference here is that the intention *is*
the programming and not just part of it. Once you have figured out what you
want and written it down in your inner language, magic takes care of the boring
stuff.

This has the side-effect that all magic is somewhat personal; a scroll written
by an individual A might yield different results if used by an individual B
with different intentions than A.

This means that MagicNG has *built-in encryption*.

At this point some might note that this is not good for interoperability. At
the core of MagicNG, this is true. However, one extraordinary extension has
been made to MagicNG that makes interoperability both possible and easy:
MagicIS (short for Magic Intention Serializer).

MagicIS encodes your intention in a magical format, after which the intention
is compiled along with your program. With MagicIS, a compiled program that
prints "My name is Niels" might look like this (imagine it compiled on a
scroll):

```
Holy oak of honey
,si:pmnin34_=UUe
```

where the `,si:` part denotes the start of the serialized intention.

The MagicIS extension can be enabled on most MagicNG compilers with a
command-line option. Note that it will need to be connected to your brain with
a special magical interface to work.


# Chapter 2: Real World Examples

"This is all very nice," you might think, "but what is it any good for?"

MagicNG can be used for everything a typical, non-magical language can be used
for, the major differences being that MagicNG is per definition faster, better
and easier to program in. This has been magically proven.

## cat

Consider the UNIX `cat` program. If written in C (even if you look at the Plan
9 version), there are many lines of source code. If written in Python 3, there
are 2 lines:

```
for line in open(filename):
    print(line)
```

If written in MagicNG, there is _one_ line (*and* it is magical):

```
cauldron of candy
```

(without MagicIS enabled.)


## Finding a value when a key is known

In a non-magical programming language, you could use a hash map. Or you could
sort the elements by their keys and use binary search. Or you could look
through every element one by one.

In MagicNG, no such algorithms are used; *magic* finds the value. In fact, this
reveals a large, fascinating and unavoidable part of MagicNG: it does not
support algorithms.

"No algorithms? But how, then, can I program?" you think. The answer is simple,
and it has been explained before, but to stress it one last time: *magic*.

This leads us to another important part of MagicNG: its use of the *black box
model*. The *black box model* has been revered all over the known universe for
its unchangeability (it is absolute), unworsenability (since you cannot change
it, you cannot make it worse), high surprise factor ("who knew my program could
do *that*?!"), and lack of meaningful error messages (no errors, no worries).


## Calculating the sum of a list of numbers

In C:

```
int sum(int xs[], int xs_len) {
  int fin_sum = 0;
  int i;
  for (i = 0; i < xs_len; i++) {
    fin_sum += xs[i];
  }
  return fin_sum;
}

[...]

sum({1, 3, -2, 9}, 4);
```

In Python:

```
sum([1, 3, -2, 9])
```

In MagicNG:

```
head of Macbeth
```


## A flight simulator

Up until now, we have only looked at MagicNG programs spanning single
lines. One can create a very powerful MagicNG program in one line, but
sometimes it can be necessary to use two, or even three lines.

As a flight operator, you may wish to have a very durable and efficient 3D
flight simulator; in MagicNG such a system can be written concisely in just
three lines of magical code (four lines with MagicIS enabled).

```
dragon claw polished with golden mead
  mead in cauldron
tastebuds of 23 pigs
,si:3=)uUUn!2aa
```

(Notice the indentation and the explicit number.)


*[Chapters 3 through 88 have been excluded in this preview. Only members of
the Magically Magical Magic Community (MMMC) have access to these chapters.]*


# Chapter 89: How to Learn More

To recap: MagicNG is an easy language to learn, since not only does it not
require the user to learn about algorithms, data structures and related wastes
of time, but actually discourages that; MagicNG encourages its users to *not
think* which *reduces errors*.

To expand your knowledge of MagicNG, both in theory and practice, do not look
at the examples of other MagicNG programmers, unless you are *absolutely sure*
that their intentions are the same as yours. You can of course deduce the
intention from a MagicIS line, but then, if you wish to base a new program on
the old program, you will have to convert that intention to your own along with
the actual program, which can be tedious and very difficult (MagicNG is
actually a very complex language).

What you should do is lean back in a comfy chair and look into nothingness and
not strain your mind. That way, everything you need to know will come to you
eventually. That's how this book was written.
