Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bakpakin/Fennel
Browse files Browse the repository at this point in the history
  • Loading branch information
bakpakin committed Dec 6, 2018
2 parents 98d2b3b + 5faad28 commit 5c58b24
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 98 deletions.
36 changes: 10 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ each release.
(print (fib 10))
```

## Try it
## Usage

At [https://fennel-lang.org](https://fennel-lang.org) there's a live
in-browser repl you can use without installing anything.

Otherwise clone this repository, and run `./fennel --repl` to quickly
start a repl. Use `./fennel my-file.fnl` to run code or `./fennel
--compile my-file.fnl > my-file.lua` to perform ahead-of-time compilation.
Check your OS's package manager to see if Fennel is available
there. If you use [LuaRocks](https://luarocks.org/) you can run
`luarocks install fennel`.

Otherwise clone this repository, and run `./fennel` to start a
repl. Use `./fennel my-file.fnl` to run code or `./fennel --compile
my-file.fnl > my-file.lua` to perform ahead-of-time compilation.

See the [API documentation](api.md) for how to embed Fennel in your program.

## Differences from Lua

Expand All @@ -72,28 +78,6 @@ start a repl. Use `./fennel my-file.fnl` to run code or `./fennel

(Obviously not all these apply to every lisp you could compare Fennel to.)

## Install with Luarocks

You can install the dev package from luarocks via
```sh
luarocks install --server=http://luarocks.org/dev fennel
```

This will install both the fennel module, which can be required into via `local fennel = require 'fennel'`,
as well as the `fennel` executable which can be used to run a repl or compile Fennel to Lua.

To start a repl:
```sh
fennel --repl
```

To compile a file:
```sh
fennel --compile myscript.fnl > myscript.lua
```

When given a file without a flag, it will simply load and run the file.

## Resources

* [Mailing list](https://lists.sr.ht/%7Etechnomancy/fennel)
Expand Down
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Summary of user-visible changes

## 0.1.0 / ??
## ???

* Fix bug in the repl where locals-saving would fail for certain input
* Fix launcher to write errors to stderr, not stdout

## 0.1.0 / 2018-11-29

* Save locals in between chunks in the repl
* Allow destructuring in more places
Expand Down
20 changes: 16 additions & 4 deletions fennel
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ local unpack = unpack or table.unpack
local help = [[
Usage: fennel [FLAG] [FILE]
Run fennel, a lisp programming language for the Lua runtime.
--repl : Launch an interactive repl session
--compile FILES : Compile files and write their Lua to stdout
--no-searcher : Skip installing package.searchers entry when running code
--indent VAL : Indent compiler output with VAL
--help : Display this text
--no-searcher : Skip installing package.searchers entry
--version : Show version
When not given a flag, runs the file given as the first argument.
When given neither flag nor file, launches a repl.
Expand All @@ -27,7 +33,7 @@ local function dosafe(filename, opts, args)
return fennel.dofile(filename, opts, unpack(args))
end, fennel.traceback)
if not ok then
print(val)
io.stderr.write(val .. "\n")
os.exit(1)
end
return val
Expand Down Expand Up @@ -79,10 +85,16 @@ elseif arg[1] == "--compile" then
local ok, val = xpcall(function()
return fennel.compileString(f:read("*all"), options)
end, fennel.traceback)
print(val)
if not ok then os.exit(1) end
if ok then
print(val)
else
io.stderr:write(val .. "\n")
os.exit(1)
end
f:close()
end
elseif arg[1] == "--version" then
print("Fennel " .. fennel.version)
elseif #arg >= 1 and arg[1] ~= "--help" then
local filename = table.remove(arg, 1) -- let the script have remaining args
dosafe(filename, nil, arg)
Expand Down
11 changes: 7 additions & 4 deletions fennel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1720,9 +1720,11 @@ local function repl(options)
for name in pairs(env.___replLocals___) do
table.insert(splicedSource, 1, bind:format(name, name))
end
-- save off new locals at the end
if(#splicedSource > 1) then
table.insert(splicedSource, #splicedSource, saveSource)
-- save off new locals at the end - if safe to do so (i.e. last line is a return)
if (string.match(splicedSource[#splicedSource], "^ *return .*$")) then
if (#splicedSource > 1) then
table.insert(splicedSource, #splicedSource, saveSource)
end
end
return table.concat(splicedSource, "\n")
end
Expand Down Expand Up @@ -1794,7 +1796,8 @@ local module = {
dofile = dofile_fennel,
macroLoaded = macroLoaded,
path = "./?.fnl;./?/init.fnl",
traceback = traceback
traceback = traceback,
version = "0.1.1-dev",
}

local function searchModule(modulename)
Expand Down
2 changes: 1 addition & 1 deletion lua-primer.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ know where in the manual to look for further details, not to teach Lua.
* `type`: returns a string describing the type of its argument
* `pcall`: calls a function in protected mode so errors are not fatal
* `error`: halts execution and break to the nearest `pcall`
* `assert`: raises an error if a condition is nil or false
* `assert`: raises an error if a condition is nil/false, otherwise returns it
* `ipairs`: iterates over sequential tables
* `pairs`: iterates over any table, sequential or not, in undefined order
* `unpack`: turns a sequential table into multiple values
Expand Down
Loading

0 comments on commit 5c58b24

Please sign in to comment.