~technomancy/fennel

a80fa71a446969d941bd27b74ab9e0b44886fc87 — Phil Hagelberg a month ago 0f7e499
A few clarifications.
3 files changed, 21 insertions(+), 16 deletions(-)

M rationale.md
M reference.md
M src/linter.fnl
M rationale.md => rationale.md +11 -10
@@ 15,22 15,22 @@ in other programs to make them reprogrammable by the end user.
The conceptual simplicity of Lua stands in stark contrast to other "easy to
learn" languages like JavaScript or Python--Lua contains very close to the
minimum number of ideas needed to get the job done; only Forth and Scheme
offer a comparable simplicity. When you combine this aggressive simplicity
offer a comparable simplicity. When you combine this meticulous simplicity
with the emphasis on making programs reprogrammable, the result is a powerful
antidote to prevailing trends in technology of treating programs as black
boxes out of the control of the user.

## And yet...

So if Lua is so great, why not just use Lua? In many cases you should! But
So if Lua is so great, why not just use Lua? In many cases you should!  But
there are a handful of shortcomings in Lua which over time have shown to be
error-prone or unclear. Fennel runs on Lua, and the runtime semantics of
Fennel are a subset of Lua's, but you can think of Fennel as an alternate
notation you can use to write Lua programs which helps you avoid common
pitfalls. This allows Fennel to focus on doing one thing very well and not
get dragged down with things like implementing a virtual machine, a standard
library, or profilers and debuggers. Any tool that already works for Lua will
work just as well for Fennel.
pitfalls. This allows Fennel to focus on doing one thing very well and not get
dragged down with things like implementing a virtual machine, a standard
library, or profilers and debuggers. Any library or tool that already works
for Lua will work just as well for Fennel.

The most obvious difference between Lua and Fennel is the parens-first
syntax; Fennel belongs to the Lisp family of programming languages. You could


@@ 52,9 52,10 @@ case they are necessary but makes it very difficult to use them by accident.
Fennel also removes the ability to reassign normal locals. If you declare a
variable that will be reassigned, you must introduce it with `var`
instead. This encourages cleaner code and makes it obvious at a glance when
reassignment is going to happen. Note that Lua 5.4 introduced a similar
idea with `<const>` variables, but since Fennel started from a clean slate it
was able to make the cleaner choice be the default rather than opt-in.
reassignment is going to happen. Note that Lua 5.4 introduced a similar idea
with `<const>` variables, but since Fennel did not have to keep decades of
existing code like Lua it was able to make the cleaner choice be the default
rather than opt-in.

## Tables and Loops



@@ 81,7 82,7 @@ which check for the arguments they expect using `lambda`.
If you've been programming in newer languages, you are likely to be spoiled
by pervasive destructuring of data structures when binding variables, as well
as by pattern matching to write more declarative conditionals. Both these are
missing from Lua and included in Fennel.
absent from Lua and included in Fennel.

Finally Fennel includes a macro system so that you can easily extend the
language to include new syntactic forms. This feature is intentionally listed

M reference.md => reference.md +7 -3
@@ 309,6 309,10 @@ pattern/body clauses to find one where the pattern matches the value,
and evaluates the corresponding body. Pattern matching can be thought
of as a combination of destructuring and conditionals.

**Note**: Lua also has "patterns" which are matched against strings
similar to how regular expressions work in other languages; these are
two distinct concepts with similar names.

Example:

```fennel


@@ 383,9 387,9 @@ matching against multiple values) but the second thing in the parens
is the `?` symbol. Each form following this marker is a condition;
all the conditions must evaluate to true for that pattern to match.

(Note that Lua also has "patterns" which are matched against strings
similar to how regular expressions work in other languages; these are
two distinct concepts with similar names.)
**Note:**: The `match` macro can be used in place of the `if-let` macro
from Clojure. The reason Fennel doesn't have `if-let` is that `match`
makes it redundant.

### `global` set global variable


M src/linter.fnl => src/linter.fnl +3 -3
@@ 1,8 1,8 @@
;; An example of some possible linters using Fennel's --plugin option.

;; The linters here can only function on static module use. For instance, this
;; code can be checked because they use static field access on a local directly
;; bound to a require call:
;; The first two linters here can only function on static module
;; use. For instance, this code can be checked because they use static
;; field access on a local directly bound to a require call:

;; (local m (require :mymodule))
;; (print m.field) ; fails if mymodule lacks a :field field