unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Anaphoric macros like when-let
@ 2017-08-26 19:47 Arun Isaac
  2017-08-26 19:50 ` Matt Wette
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Arun Isaac @ 2017-08-26 19:47 UTC (permalink / raw)
  To: Guile User


Is there a Scheme or Guile equivalent to Emacs Lisp's `when-let' ?

Basically, I'm looking for a shorthand to express this:

(let ((x (foo))
  (when x
    (bar x))))

as this:

(when-let (x (foo))
  (bar x))



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Anaphoric macros like when-let
  2017-08-26 19:47 Anaphoric macros like when-let Arun Isaac
@ 2017-08-26 19:50 ` Matt Wette
  2017-08-26 19:54   ` Matt Wette
  2017-08-27 12:28   ` Arun Isaac
  2017-08-26 22:40 ` Kyle Siehl
  2017-08-27 20:24 ` Mark H Weaver
  2 siblings, 2 replies; 7+ messages in thread
From: Matt Wette @ 2017-08-26 19:50 UTC (permalink / raw)
  To: Arun Isaac; +Cc: Guile User


> On Aug 26, 2017, at 12:47 PM, Arun Isaac <arunisaac@systemreboot.net> wrote:
> 
> 
> Is there a Scheme or Guile equivalent to Emacs Lisp's `when-let' ?
> 
> Basically, I'm looking for a shorthand to express this:
> 
> (let ((x (foo))
>  (when x
>    (bar x))))
> 
> as this:
> 
> (when-let (x (foo))
>  (bar x))
> 

(use-modules (srfi srfi-2))

(and-let* ((x foo))
  (bar x))






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Anaphoric macros like when-let
  2017-08-26 19:50 ` Matt Wette
@ 2017-08-26 19:54   ` Matt Wette
  2017-08-27 12:28   ` Arun Isaac
  1 sibling, 0 replies; 7+ messages in thread
From: Matt Wette @ 2017-08-26 19:54 UTC (permalink / raw)
  To: Matt Wette; +Cc: Guile User


> On Aug 26, 2017, at 12:50 PM, Matt Wette <matt.wette@gmail.com> wrote:
> 
> 
>> On Aug 26, 2017, at 12:47 PM, Arun Isaac <arunisaac@systemreboot.net> wrote:
>> 
>> 
>> Is there a Scheme or Guile equivalent to Emacs Lisp's `when-let' ?
>> 
>> Basically, I'm looking for a shorthand to express this:
>> 
>> (let ((x (foo))
>> (when x
>>   (bar x))))
>> 
>> as this:
>> 
>> (when-let (x (foo))
>> (bar x))
>> 
> 
> (use-modules (srfi srfi-2))
> 
> (and-let* ((x foo))
>  (bar x))

(and-let* ((x (foo)))
  (bar x))




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Anaphoric macros like when-let
  2017-08-26 19:47 Anaphoric macros like when-let Arun Isaac
  2017-08-26 19:50 ` Matt Wette
@ 2017-08-26 22:40 ` Kyle Siehl
  2017-08-27 20:24 ` Mark H Weaver
  2 siblings, 0 replies; 7+ messages in thread
From: Kyle Siehl @ 2017-08-26 22:40 UTC (permalink / raw)
  To: Arun Isaac; +Cc: Guile User

On Sun, Aug 27, 2017 at 01:17:13AM +0530, Arun Isaac wrote:
> 
> Is there a Scheme or Guile equivalent to Emacs Lisp's `when-let' ?
> 
> Basically, I'm looking for a shorthand to express this:
> 
> (let ((x (foo))
>   (when x
>     (bar x))))
> 
> as this:
> 
> (when-let (x (foo))
>   (bar x))

(cond
 ((foo) => bar))

Or, in general:

(cond
 ((foo)
  => (lambda (x)
       (bar x))))



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Anaphoric macros like when-let
  2017-08-26 19:50 ` Matt Wette
  2017-08-26 19:54   ` Matt Wette
@ 2017-08-27 12:28   ` Arun Isaac
  1 sibling, 0 replies; 7+ messages in thread
From: Arun Isaac @ 2017-08-27 12:28 UTC (permalink / raw)
  To: Guile User


Thank you, Kyle and Matt!



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Anaphoric macros like when-let
  2017-08-26 19:47 Anaphoric macros like when-let Arun Isaac
  2017-08-26 19:50 ` Matt Wette
  2017-08-26 22:40 ` Kyle Siehl
@ 2017-08-27 20:24 ` Mark H Weaver
  2017-08-28  9:41   ` Arun Isaac
  2 siblings, 1 reply; 7+ messages in thread
From: Mark H Weaver @ 2017-08-27 20:24 UTC (permalink / raw)
  To: Arun Isaac; +Cc: Guile User

Arun Isaac <arunisaac@systemreboot.net> writes:
> Is there a Scheme or Guile equivalent to Emacs Lisp's `when-let' ?

I have nothing to add to Matt and Kyle's answers, except to mention that
'when-let' is not actually an anaphoric macro.  Anaphoric macros are
those that introduce a binding that is not named by the user, e.g. 'it',
which is called an anaphor.  For more, see:

  https://en.wikipedia.org/wiki/Anaphoric_macro

      Mark



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Anaphoric macros like when-let
  2017-08-27 20:24 ` Mark H Weaver
@ 2017-08-28  9:41   ` Arun Isaac
  0 siblings, 0 replies; 7+ messages in thread
From: Arun Isaac @ 2017-08-28  9:41 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: Guile User


Mark H Weaver writes:

> mention that 'when-let' is not actually an anaphoric macro.  Anaphoric
> macros are those that introduce a binding that is not named by the
> user, e.g. 'it', which is called an anaphor.

Yes, you're right, of course! aif, awhen, etc. are the anaphoric
macros. I switched to if-let, when-let, etc. when they became available
in emacs lisp, and somehow wrongly continued to call them anaphoric
macros.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-08-28  9:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-26 19:47 Anaphoric macros like when-let Arun Isaac
2017-08-26 19:50 ` Matt Wette
2017-08-26 19:54   ` Matt Wette
2017-08-27 12:28   ` Arun Isaac
2017-08-26 22:40 ` Kyle Siehl
2017-08-27 20:24 ` Mark H Weaver
2017-08-28  9:41   ` Arun Isaac

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).