0.2.29 • Published 7 years ago

moon-tool v0.2.29

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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)'
0.2.29

7 years ago

0.2.28

7 years ago

0.2.27

7 years ago

0.2.26

7 years ago

0.2.25-c

7 years ago

0.2.25-b

7 years ago

0.2.25

7 years ago

0.2.24

7 years ago

0.2.23

7 years ago

0.2.22-g

7 years ago

0.2.22-f

7 years ago

0.2.22-e

7 years ago

0.2.22-d

7 years ago

0.2.22-c

7 years ago

0.2.22-b

7 years ago

0.2.22

7 years ago

0.2.21

7 years ago

0.2.20

7 years ago

0.2.19

7 years ago

0.2.18-c

7 years ago

0.2.18-b

7 years ago

0.2.18

7 years ago

0.2.17

7 years ago

0.2.16

7 years ago

0.2.15

7 years ago

0.2.14-b

7 years ago

0.2.14

7 years ago

0.2.13-b

7 years ago

0.2.13

7 years ago

0.2.12

7 years ago

0.2.11

7 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.1.35

7 years ago

0.1.34

7 years ago

0.1.32

7 years ago

0.1.31

7 years ago

0.1.28

7 years ago

0.1.27

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago