Ethereum + Swarm + λ = Moon, a universal code-interchange format

I just published the first version of moon-lang. I’ve still not written a proper introduction to it, but, before I do, I’ll talk a little bit about one of its coolest features: decentralized imports.

Moon doesn’t have a “package manager” like most languages, and Moon apps aren’t meant to be hosted in normal servers. Instead, whenever you want to publish a library, program or application, you use the Ethereum/Swarm network. Here is how it works:

  1. You create a cool program and name it coolProgram.moon.
  2. You go to the terminal and type moon publish coolProgram.moon.
  3. The source of coolProgram is sent to Swarm, a decentralized storage.
  4. Tha SwarmHash is registered on Ethereum using the coolProgram name.
  5. Someone attempts to use coolProgram inside their own Moon code.
  6. Moon follows the reverse path and recovers your source code.
  7. …?
  8. Decentralized imports!

This is cool for many reasons. Not only it allows people to share code and apps as frictionless as ever, but it also gives those codes/apps the same great properties of decentralized networks. If coolProgram is, for example, a web-application, people will immediately be able to access it on DApp browsers such as Mist. No need to worry about hosting costs, DDOS attacks, censure and so on: as long as there are people using coolProgram, it will be kept alive on the network!

Example

Suppose you've written a Moon program that computes someone's Body Mass Index. You name it personBMI.moon:

(Don't mind the syntax for now, that is still being thought.)

Now you’re very proud of your creation and wants the world to see it, but you know nothing about hosting. No worries, Moon is here for you. But, first, you need to check if your CLI has Ether:

If its balance is zero, don’t worry. Publishing is very cheap, so you can just ask a friend to send a few cents to your CLI’s address:

Once you have it, you can publish your code with moon publish:

You’ll see a few hacky messages detailing the process:

And done! Now, anyone else in the world can use personBMI by either referencing it inside a Moon program, or by calling it directly on the terminal:

Now, suppose a friend has just called you to ask if he is overweight. You could be downright honest about it… or you could write a (terminal) DApp for that!

Save it as whatsMyBMI.moon and type moon publish whatMyBMI. Now you can just tell him to ask Moon directly:

Your (terminal) DApp will be resolved on Ethereum, downloaded from Swarm and then run on your friend's console. Cool, isn't it? Try running it!

Note: if you’re confused about the fact we’re using prints and getLines in a self-proclaimed "pure" language, don’t worry: that is just an adaptation of Idris's bang-notation for monadic computations. But that’s subject for another post. Check out Moon's repository for more cool stuff!