Hi,
after having followed SICP, I have been irremediably hooked on Scheme's let, so I added it to my macros. IIRC, I borrowed this implementation form SBCL's NAMED-LET (it's so short, it's hard to tell).
I also heavily use a cataphoric IF, which I will now replace by the single-binding IF-LET, now that I know it exists.
I thought it would be nice if LET@ was available in Alexandria with the other binding macros.
Regards, Pierre
--- binding.lisp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/binding.lisp b/binding.lisp index 36d92bc..19c3750 100644 --- a/binding.lisp +++ b/binding.lisp @@ -91,3 +91,19 @@ PROGN." (when ,(caar binding-list) ,@(bind (cdr binding-list) forms))))))
+(defmacro let@ (name bindings &body body) + "LET@ is RnRS' LET. + +BINDINGS is a list of bindings of the form: + + ((argument-1 initial-form-1) + (argument-2 initial-form-2) + ... + (argument-n initial-form-n)) + +LET@ creates a local function named NAME with lambda-list +(argument-1 argument-2 ... argument-n) and body BODY. This +function is then called with the evaluations of the intitial +forms as arguments." + `(labels ((,name ,(mapcar #'first bindings) ,@body)) + (,name ,@(mapcar #'second bindings))))
On 2 August 2012 05:41, Pierre Thierry pierre@nothos.net wrote:
+(defmacro let@ (name bindings &body body)
- "LET@ is RnRS' LET.
I'm OK with a named-let in principle, I think. Maybe. But I'm dead-set against calling it let@.
Rename into something descriptive, add test-cases, add to documentation, and this can probably be merged.
(Most of the time when I see code written with named let I want to rewrite it into something more readable, but I'm willing to believe that it doesn't have to be always bad...)
Cheers,
-- Nikodemus
Scribit Nikodemus Siivola dies 26/01/2013 hora 16:21:
I'm OK with a named-let in principle, I think. Maybe. But I'm dead-set against calling it let@.
The thing is, if you want to code with a scheme style, you'll use named lets very often, so it ought to have a rather short name. Why the issue with let@, for my curiosity's sake? (for me, @ looks a lot like a spiral or something like an ongoing loop)
(Most of the time when I see code written with named let I want to rewrite it into something more readable, but I'm willing to believe that it doesn't have to be always bad...)
Ever since I understood recursion, I've always found this way more readable than anything else, to what would you usually rewrite a named let?
Curiously, Pierre
On Sunday, January 27, 2013, Pierre Thierry wrote:
Scribit Nikodemus Siivola dies 26/01/2013 hora 16:21:
I'm OK with a named-let in principle, I think. Maybe. But I'm dead-set against calling it let@.
The thing is, if you want to code with a scheme style, you'll use named lets very often, so it ought to have a rather short name. Why
Here's the thing: I think if you want to code Scheme style you should use Scheme - or at least a library that tries to integrate schemey idioms into CL. I do not believe Alexandria should try to incorporate scheme idioms - not because they're bad, but because they're not CL idioms.
I find named-let mostly useful for quick initial ports of code written in Scheme.
the issue with let@, for my curiosity's sake? (for me, @ looks a lot like a spiral or something like an ongoing loop)
I don't really care if people think it a matter of taste or objective truth. The fact remains that I'm opposed to single-character suffixes or prefixes denoting variants of standard operators in general purpose libraries. (I'm much more lenient about special purpose libs.)
(Most of the time when I see code written with named let I want to rewrite it into something more readable, but I'm willing to believe that it doesn't have to be always bad...)
Ever since I understood recursion, I've always found this way more readable than anything else, to what would you usually rewrite a named let?
Depends. Labels, do, dolist, do*, loop, tagbody, mutually recursive toplevel defuns, dotimes, prog, y-combinator. Whatever seems most appropriate for the task at hand.
Curiously, Pierre -- pierre@nothos.net javascript:; OpenPGP 0xD9D50D8A
Hello:
Note that RECUR is a part of Quicklisp, which is a library I wrote whose only purpose is to provide a canonical named-LET macro.
You can see the code/example/README here:
https://bitbucket.org/tarballs_are_good/recur
On a related note, another thing I've applied to have added to Quicklisp is LETREC, which allows mutually recursive function-valued bindings, but the functions can be produced at runtime as opposed to the lambda being known at compile-time. That is here:
https://bitbucket.org/tarballs_are_good/letrec
Cheers,
Robert
On Wed, Aug 1, 2012 at 9:41 PM, Pierre Thierry pierre@nothos.net wrote:
Hi,
after having followed SICP, I have been irremediably hooked on Scheme's let, so I added it to my macros. IIRC, I borrowed this implementation form SBCL's NAMED-LET (it's so short, it's hard to tell).
I also heavily use a cataphoric IF, which I will now replace by the single-binding IF-LET, now that I know it exists.
I thought it would be nice if LET@ was available in Alexandria with the other binding macros.
Regards, Pierre
alexandria-devel mailing list alexandria-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/alexandria-devel
Scribit Robert Smith dies 02/08/2012 hora 11:49:
Note that RECUR is a part of Quicklisp, which is a library I wrote whose only purpose is to provide a canonical named-LET macro.
Why not integrate either RECUR or LET@ in Alexandria?
Curiously, Pierre
Pierre Thierry pierre@nothos.net writes:
Scribit Robert Smith dies 02/08/2012 hora 11:49:
Note that RECUR is a part of Quicklisp, which is a library I wrote whose only purpose is to provide a canonical named-LET macro.
Why not integrate either RECUR or LET@ in Alexandria?
For one thing, LET@ is a very bad name.
Scribit Stas Boukarev dies 03/08/2012 hora 06:08:
Why not integrate either RECUR or LET@ in Alexandria?
For one thing, LET@ is a very bad name.
Hey, it's a sensitive name, go easy on it. I must say, I like it a lot but I just picked a character to append to LET. What's the problem with it?
Curiously, Pierre
Pierre Thierry pierre@nothos.net writes:
Scribit Stas Boukarev dies 03/08/2012 hora 06:08:
Why not integrate either RECUR or LET@ in Alexandria?
For one thing, LET@ is a very bad name.
Hey, it's a sensitive name, go easy on it. I must say, I like it a lot but I just picked a character to append to LET. What's the problem with it?
Exactly because of this: it's just a character. It doesn't describe what it's actually doing, so it's hard to remember.
alexandria-devel@common-lisp.net