~technomancy/fennel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH fennel v2 0/1] Re: Clojure-like loop/recur or Scheme named-let in Fennel?

Details
Message ID
<168531148550.8714.17287182809706159522-0@git.sr.ht>
DKIM signature
missing
Download raw message
> >I remember seeing these limitations the last time I referenced the
> >library to talk about this in #fennel~
> >
> >I wonder if there's a better way to implement it? (Or maybe even a
> >better place?)
> >(Actually, where would I even need to look if there was?)
>
> Well, IIRC I was sitting and thinking of a different way, and the only
one that
> comes to mind is literally using GOTO labels. This will turn named let
into a
> simple jump + rebind, and it will probably be possible to support
> multiple-value binding. Probably. (Un)fortunately, lua escape hatch
doesn't
> allow defining goto labels.

I figured out a way to bypass these limitations in a way that doesn't
involve introducing GOTO, doesn't break with the caveats that the cljlib
implementation has (afaict), and changes no existing syntax at all (and
validates in the same way as existing let!)

Archenoth (1):
  add named let!

 src/fennel/specials.fnl | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

-- 
2.38.4

[PATCH fennel v2 1/1] add named let!

Details
Message ID
<168531148550.8714.17287182809706159522-1@git.sr.ht>
In-Reply-To
<168531148550.8714.17287182809706159522-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
Patch: +16 -4
From: Archenoth <archenoth@gmail.com>

This commit will allow for `let` bindings to optionally specify a name
in the same way that `fn` can in order to restart its body with new
bindings (Like how Scheme does it!)
---
 src/fennel/specials.fnl | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/fennel/specials.fnl b/src/fennel/specials.fnl
index 503ddd9..ef75de5 100644
--- a/src/fennel/specials.fnl
+++ b/src/fennel/specials.fnl
@@ -451,8 +451,18 @@ and lacking args will be nil, use lambda for arity-checked functions." true)

(fn kv? [t] (. (icollect [k (pairs t)] (if (not= :number (type k)) k)) 1))

(fn compile-named-let-fn [ast scope parent name bindings]
  (let [args (icollect [i v (ipairs bindings)]
               (when (= 1 (% i 2)) v))
        body (icollect [i l (ipairs ast)]
               (when (> i 2) l))
        declaration [:fn name args (table.unpack body)]]
    (SPECIALS.fn (utils.list (table.unpack declaration)) scope parent)))

(fn SPECIALS.let [ast scope parent opts]
  (let [bindings (. ast 2)
  (let [name (when (and (utils.sym? (. ast 2)) (utils.table? (. ast 3)))
               (table.remove ast 2))
        bindings (. ast 2)
        pre-syms []]
    (compiler.assert (and (utils.table? bindings) (not (kv? bindings)))
                     "expected binding sequence" bindings)
@@ -469,11 +479,13 @@ and lacking args will be nil, use lambda for arity-checked functions." true)
        (compiler.destructure (. bindings i) (. bindings (+ i 1)) ast sub-scope
                              sub-chunk
                              {:declaration true :nomulti true :symtype :let}))
      (when name
        (table.insert ast 3 (compile-named-let-fn ast scope parent name bindings)))
      (SPECIALS.do ast scope parent opts 3 sub-chunk sub-scope pre-syms))))

(doc-special :let ["[name1 val1 ... nameN valN]" "..."]
             "Introduces a new scope in which a given set of local bindings are used."
             true)
(doc-special :let [:name? "[name1 val1 ... nameN valN]" "..."]
             "Introduces a new scope in which a given set of local bindings are used.
Optionally allowing for a name to restart the body with new bindings" true)

(fn get-prev-line [parent]
  (if (= :table (type parent))
-- 
2.38.4

[fennel/patches/.build.yml] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CSY92YL9L0S2.34LTXW5HIMN3U@cirno2>
In-Reply-To
<168531148550.8714.17287182809706159522-1@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
fennel/patches/.build.yml: SUCCESS in 56s

[Re: Clojure-like loop/recur or Scheme named-let in Fennel?][0] v2 from [~archenoth][1]

[0]: https://lists.sr.ht/~technomancy/fennel/patches/41464
[1]: archenoth@gmail.com

✓ #997589 SUCCESS fennel/patches/.build.yml https://builds.sr.ht/~technomancy/job/997589
Details
Message ID
<CA+GZiYr0+qN9aNaz3o4_O9Wf3SpkH6f8QNS24kf1qd6vg0Kt_A@mail.gmail.com>
In-Reply-To
<168531148550.8714.17287182809706159522-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
So uh, it seems like I have No Idea how to send patches to a mailing
list while also having them be a part of the main thread, but I've
sent a patch to https://lists.sr.ht/~technomancy/fennel/patches/41464
that should basically do all of those things, and should be usable to
get around the limitations of the implementation in cljlib without the
need for GOTO labels

(Speaking of which, sorry about the double post! I ran `make test` to
make sure that I didn't break anything with my patch, but didn't
notice that there was also a linter that would break the build)

I tried pretty hard to not affect any existing code, and to make it
have as minimal a footprint as possible too, so hopefully it doesn't
seem too wild of a proposed patch

On Sun, May 28, 2023 at 4:05 PM ~archenoth <archenoth@git.sr.ht> wrote:
>
> > >I remember seeing these limitations the last time I referenced the
> > >library to talk about this in #fennel~
> > >
> > >I wonder if there's a better way to implement it? (Or maybe even a
> > >better place?)
> > >(Actually, where would I even need to look if there was?)
> >
> > Well, IIRC I was sitting and thinking of a different way, and the only
> one that
> > comes to mind is literally using GOTO labels. This will turn named let
> into a
> > simple jump + rebind, and it will probably be possible to support
> > multiple-value binding. Probably. (Un)fortunately, lua escape hatch
> doesn't
> > allow defining goto labels.
>
> I figured out a way to bypass these limitations in a way that doesn't
> involve introducing GOTO, doesn't break with the caveats that the cljlib
> implementation has (afaict), and changes no existing syntax at all (and
> validates in the same way as existing let!)
>
> Archenoth (1):
>   add named let!
>
>  src/fennel/specials.fnl | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
>
> --
> 2.38.4
Reply to thread Export thread (mbox)