GithubHelp home page GithubHelp logo

moon-tool's Introduction

moon-tool

Command-line tool for Moon-lang. Allows you to:

  • Run expressions and files from the command-line;

  • Load/save expressions and files to IPFS;

  • Pack/unpack, compile to JS, etc...

Installing

npm i -g moon-tool

Usage

Inline execution:

moon run '(add 1 2)'        -- output: 3
moon run 'x=4 y=2 [x y]'    -- output: [4 2]
moon run '((x => [x x]) 3)' -- output: [3 3]

File execution:

echo '"Hello"' >> hi.moon
moon run hi -- output: "Hello"

Saving to IPFS:

moon save 'x => (add x 1)'
-- output: zb2rhoKHTgNBYJDnzaBn8uaCpKuX9iGpsc2hpLdE2k2YTD1jH

After you save an expression, you may use its hash inside other expressions: moon run recursively imports IPFS hashes.

Loading from IPFS:

moon load zb2rhoKHTgNBYJDnzaBn8uaCpKuX9iGpsc2hpLdE2k2YTD1jH
-- output: x => (add x 1)

Updating IPFS imports:

If you modify a file and save it to IPFS, all files that import it will keep using the old version, because Moon guarantees that a file's behavior doesn't change if its contents don't change. This can be very annoying when you just want to update a file which is imported in many places. To amend that, moon-tool provides the replace command, which allows you to change the contents of a file, save it to IPFS and recursivelly update all imports that refer to the old version. Example:

# creates a `helloworld.moon` file which imports a `hello.moon` file

$ echo "\"hello\"" > hello.moon

$ echo "[$(moon save hello) \"world\"]" > helloworld.moon

# Prints and runs both files

$ cat hello.moon
"hello"

$ moon run hello
"hello"

$ cat helloworld.moon
[zb2rhfsstEj5riwMdMpKep4h1MmCXTzKYrucQJ6TEqRCRRxAw "world"]

$ moon run helloworld
["hello" "world"]

# Rewrites `hello.moon`'s contents

$ moon replace hello.moon "\"hola\""
zb2rhfsstEj5riwMdMpKep4h1MmCXTzKYrucQJ6TEqRCRRxAw -> zb2rhf5uqM37QCXN8VMTXYPDA2XB2w1fwHzy91CjWovJmVGUW (hello.moon)
zb2rhiNoCanP5qCJeePx5zEyp8EBp9tBgGrEmQJ1K7ZKNSena -> zb2rhkikpZPfJGvJJ2wyUSTe9W4zeKBJHuaSrfpFBpbH18M3N (helloworld.moon)

# Prints and runs both files again

$ cat hello.moon
"hola"

$ moon run hello
"hola"

$ cat helloworld.moon
[zb2rhf5uqM37QCXN8VMTXYPDA2XB2w1fwHzy91CjWovJmVGUW "world"]

$ moon run helloworld
["hola" "world"]

# Notice `helloworld.moon` changed accourdingly.

You can also replace arbitrary expressions:

moon replace "some_regex" "new_value"

Note moon replace modifies your files, so use it carefully.

Running with side-effects:

moon runIO 'ask => end => (ask "prompt" "Hi!" then => (end 0))'

Moon is pure, but you can still peform side-effects by evaluating computations in a side-effective language. The runIO command does that with default side-effects.

Compiling to JavaScript:

moon compile 'x => (mul x 10)'

moon-tool's People

Contributors

victortaelin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.