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:
- You create a cool program and name it
- You go to the terminal and type
moon publish coolProgram.moon.
- The source of
coolProgramis sent to Swarm, a decentralized storage.
- Tha SwarmHash is registered on Ethereum using the
- Someone attempts to use
coolPrograminside their own Moon code.
- Moon follows the reverse path and recovers your source code.
- 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!
Suppose you've written a Moon program that computes someone's Body Mass Index. You name it
(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
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
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!