~andreyorst

Moscow

https://andreyorst.gitlab.io/

I love Lisp and text editors!

Recent activity

[PATCH] compiler: allow strings at call position 6 days ago

From Andrey Listopadov to ~technomancy/fennel

Strings can possibly have a __call metamethod, and it's actually
possible to call strings in Lua with the following notation:
`("str")(...)`.  This patch adds a check if AST element at call
position is a string, and if it is, it is wrapped in parentheses to
ensure correct Lua syntax.

I wonder if we can wrap every literal into parentheses, as
something like this is valid lua:

local function foo(bar) return bar end
(foo)(42)

Also if __call metamethod for strings is not restored in the test, the
test-empty-values test breaks:
[message trimmed]

Re: Chained failure handling a month ago

From Andrey Listopadov to ~technomancy/fennel

> The Fennel equivalent might look like this:
>
> ```fennel
> (-match-> (might-fail data)
>   data2 (pcall also-might-fail data2 x)
>   data3 (finalize foo data3))
> ```
>
> Where each of the functions `transform`, `second-step`, and `finalize`
> can return either a successful value or nil, msg. In the case of a
> failure at any point, the entire form evaluates to nil, msg.

This also reminds me of Clojure's `cond->`, but instead of conditions,
we do pattern matching. Maybe just `match->` :) (without the `-` at

Re: Termination conditions for loops a month ago

From Andrey Listopadov to ~technomancy/fennel

> * Is `while` the right way to frame this? It certainly has the advantage
>   that it parallels the existing `while` form and is very easy to
>   understand what it does. We could do `until` instead though, which
>   might map more closely with how it's likely to be used. Is it more
>   common to look for a condition to become true in order to terminate,
>   or false?

I think `:until` can resemble the intentions very clearly. We loop
/until/ certain condition is met.

As for notation, I feel that keyword-string is the best way to express
this. As you've already mentioned on IRC, another alternative would be
`&while`, and while this syntax is convenient in terms that it is
forbidden to use anywhere, it is also used for binding forms, which

[PATCH v2] fix ?. behavior introduced in 18c6fcf and fix tests not being ran 2 months ago

From Andrey Listopadov to ~technomancy/fennel

The change introduced in 18c6fcf made ?. behave the same as .
This was not caught by the tests, because tests were not ran at all,
because "expected" result was nil, and assigning nil to table key
effectively removes that key from the table, thus making tests
completely ignored. I've noticed this and fixed in some other tests in
core.fnl as well.
---
 src/fennel/macros.fnl |  8 +++---
 test/core.fnl         | 30 +++++++++----------
 test/macro.fnl        | 67 ++++++++++++++++++++++---------------------
 3 files changed, 53 insertions(+), 52 deletions(-)

diff --git a/src/fennel/macros.fnl b/src/fennel/macros.fnl
index fd59a05..5f35919 100644
[message trimmed]

[PATCH] fix ?. behavior introduced in 18c6fcf and fix tests not being ran 2 months ago

From Andrey Listopadov to ~technomancy/fennel

The change introduced in 18c6fcf made ?. behave the same as .
This was not caught by the tests, because tests were not ran at all,
because "expected" result was nil, and assigning nil to table key
effectively removes that key from the table, thus making tests
completely ignored.

I've updated the tests to use `type` special around the ones that
expect `nil` as a result, and changed `nil` to `:nil` thus ensuring
that tests still return exactly `nil`. Maybe test suite should use
sequential table of sequential tables instead of associative table
with tests as keys? This will give deterministic order for tests and
will also make the change above irrelevant?
---
 src/fennel/macros.fnl |  8 ++++----
[message trimmed]

[PATCH] ensure that __fennelview has higher priority than :prefer-colon? 2 months ago

From Andrey Listopadov to ~technomancy/fennel

When __fennelview calls view function with last argument set to true
the string is printed as colon string, when possible.  When the last
argument is false, string is always printed in double quotes.  When
the last argument is omitted, value of :prefer-colon? key is used.

I've also used forward declaration for internal pp function instead of
defining it in a table, and fixed docstring, as per 0e8efe6 the
docstring mentions :colon-strings? instead of :prefer-colon?  option.
---
 fennelview.lua      | 64 ++++++++++++++++++++++----------------
 src/fennel/view.fnl | 76 +++++++++++++++++++++++++--------------------
 test/core.fnl       | 13 +++++++-
 3 files changed, 91 insertions(+), 62 deletions(-)
[message trimmed]

[PATCH] fix match not handling false pattern correctly 2 months ago

From Andrey Listopadov to ~technomancy/fennel

---
 src/fennel/macros.fnl | 6 ++++--
 test/macro.fnl        | 7 ++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/fennel/macros.fnl b/src/fennel/macros.fnl
index b78dad0..ec9f4c7 100644
--- a/src/fennel/macros.fnl
+++ b/src/fennel/macros.fnl
@@ -369,8 +369,10 @@ introduce for the duration of the body if it does match."
        seconds []
        res []]
    (for [i 1 (length seq) 2]
      (table.insert firsts (or (. seq i) 'nil))
[message trimmed]

[PATCH] add nil-safe table lookup operator 2 months ago

From Andrey Listopadov to ~technomancy/fennel

This patch adds new ?. operator. This operator can be used to do
nested table lookup in a nil-safe manner of -?> and -?>>
operators. This means that if any of subsequent keys do not exist,
this operator will short-circuit to nil value:

(local t {:a {:b [:c :d {:e {:f 42}} :g]}})

(?. t :a :b 3 :e :f) ; 42
(?. t :a :b 5 :e :f) ; nil, because there's only 4 elements in vector

Note that the implementation is not what we've discussed
before. Instead I've chosen mostly the same approach as for -?>>
macro, which does repeated recursion expansion for each key lookup
until amount of keys exhausts. This way there's no iteration, and we
[message trimmed]

Re: [PATCH v2] implement new prefix syntax for match macro 2 months ago

From Andrey Listopadov to ~technomancy/fennel

> After I applied this I realized we can't use table.pack here because it
> doesn't exist in older Lua versions.

oh, wasn't aware that table.pack is a new thing.

> When they look like they have nil in them,
> they actually have a symbol named nil.

BTW I've saw (= :nil (tostring pattern)) in the code of
src/fennel/macros.fnl at line 294. AST nils can't be compared to `nil
or is it just an oversight?


-Andrey

[PATCH v2] implement new prefix syntax for match macro 2 months ago

From Andrey Listopadov to ~technomancy/fennel

New syntax replaces and extend old question mark `?' based guards with
prefix `where' guards and optional pattern ORing with `or' special
form.

Current implementation uses transformation from new syntax into old
match syntax, and passes the result to an old implementation of match*
macro.  I've found this way much easier to integrate and also maintain
new syntax (like if we will decide to allow `or' outside of where we
will need to add one additional line to current implementation).
Incorporating new syntax into old macro implementation proven to
result in quite ugly code, that IMO will be hard to understand and
maintain in the future.

I've added tests for the new syntax, and ensured that all old tests
[message trimmed]