unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* macro syntax-error works in prefix but not curly-infix
@ 2021-09-04 14:41 Damien Mattei
  2021-09-19  6:23 ` adriano
  2021-09-19 12:34 ` Zelphir Kaltstahl
  0 siblings, 2 replies; 5+ messages in thread
From: Damien Mattei @ 2021-09-04 14:41 UTC (permalink / raw)
  To: guile-user

hi,

i have this macro:

(define-syntax <+
  (syntax-rules ()
    ((_ var expr) (define var expr))
    ((_ err ...) (syntax-error "Bad <- form")) ;; does not work in infix !
    ))

why my syntax-error pattern never reach in infix:

scheme@(guile-user)> {x <+ 7 8}
While compiling expression:
Syntax error:
unknown file:3:3: source expression failed to match any pattern in form <+

but ok in prefix:

scheme@(guile-user)> (<+ x 9 10)
While compiling expression:
Syntax error:
unknown location: <+: Bad <- form in form (<+ x 9 10)

why?
Regards,
Damien


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

* Re: macro syntax-error works in prefix but not curly-infix
  2021-09-04 14:41 macro syntax-error works in prefix but not curly-infix Damien Mattei
@ 2021-09-19  6:23 ` adriano
  2021-09-19  7:48   ` Damien Mattei
  2021-09-19 12:34 ` Zelphir Kaltstahl
  1 sibling, 1 reply; 5+ messages in thread
From: adriano @ 2021-09-19  6:23 UTC (permalink / raw)
  To: guile-user

Il giorno sab, 04/09/2021 alle 16.41 +0200, Damien Mattei ha scritto:
> hi,
> 
> i have this macro:
> 
> (define-syntax <+
>   (syntax-rules ()
>     ((_ var expr) (define var expr))
>     ((_ err ...) (syntax-error "Bad <- form")) ;; does not work in
> infix !
>     ))
> 
> why my syntax-error pattern never reach in infix:
> 
> scheme@(guile-user)> {x <+ 7 8}
> While compiling expression:
> Syntax error:
> unknown file:3:3: source expression failed to match any pattern in
> form <+
> 
> but ok in prefix:
> 
> scheme@(guile-user)> (<+ x 9 10)
> While compiling expression:
> Syntax error:
> unknown location: <+: Bad <- form in form (<+ x 9 10)
> 
> why?
> Regards,
> Damien


As far as I understand, infix syntax can't be achieved through macros

You'd need a custom reader for that

I might be wrong, but at least I offered something




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

* Re: macro syntax-error works in prefix but not curly-infix
  2021-09-19  6:23 ` adriano
@ 2021-09-19  7:48   ` Damien Mattei
  0 siblings, 0 replies; 5+ messages in thread
From: Damien Mattei @ 2021-09-19  7:48 UTC (permalink / raw)
  To: adriano; +Cc: guile-user

thank for your help
i do not understand why, infix is implemented at READER level in the REPL
(READ EVAL PRINT LOOP) and MACRO are expansed at a later level , so my
operator the infix operator should be converted do prefix before macro
expansion in my opinion.
Damien

On Sun, Sep 19, 2021 at 8:23 AM adriano <randomlooser@riseup.net> wrote:

> Il giorno sab, 04/09/2021 alle 16.41 +0200, Damien Mattei ha scritto:
> > hi,
> >
> > i have this macro:
> >
> > (define-syntax <+
> >   (syntax-rules ()
> >     ((_ var expr) (define var expr))
> >     ((_ err ...) (syntax-error "Bad <- form")) ;; does not work in
> > infix !
> >     ))
> >
> > why my syntax-error pattern never reach in infix:
> >
> > scheme@(guile-user)> {x <+ 7 8}
> > While compiling expression:
> > Syntax error:
> > unknown file:3:3: source expression failed to match any pattern in
> > form <+
> >
> > but ok in prefix:
> >
> > scheme@(guile-user)> (<+ x 9 10)
> > While compiling expression:
> > Syntax error:
> > unknown location: <+: Bad <- form in form (<+ x 9 10)
> >
> > why?
> > Regards,
> > Damien
>
>
> As far as I understand, infix syntax can't be achieved through macros
>
> You'd need a custom reader for that
>
> I might be wrong, but at least I offered something
>
>


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

* Re: macro syntax-error works in prefix but not curly-infix
  2021-09-04 14:41 macro syntax-error works in prefix but not curly-infix Damien Mattei
  2021-09-19  6:23 ` adriano
@ 2021-09-19 12:34 ` Zelphir Kaltstahl
  2021-09-20  9:16   ` Damien Mattei
  1 sibling, 1 reply; 5+ messages in thread
From: Zelphir Kaltstahl @ 2021-09-19 12:34 UTC (permalink / raw)
  To: Damien Mattei; +Cc: Guile User

Hi Damien!

I think there might be too few expressions matched in the first case: (_ var
expr). Wouldn't it have to be:

~~~~
(_ var expr1 expr2)
;; or
(_ var exprs ...)
~~~~

for

~~~~
(<+ var expr1 expr2)
~~~~

to work, simply because of the number of expressions there?

But then you might need to use ellipsis in the resulting syntax somewhere,
otherwise you get:

~~~~
syntax: missing ellipsis in form (syntax (define var expr))
~~~~

I don't know where that would go, but I also do not understand yet the goal. I
think it is best to always describe, what you want to achieve, when you write a
macro.

Regards,
Zelphir

On 9/4/21 4:41 PM, Damien Mattei wrote:
> hi,
>
> i have this macro:
>
> (define-syntax <+
>   (syntax-rules ()
>     ((_ var expr) (define var expr))
>     ((_ err ...) (syntax-error "Bad <- form")) ;; does not work in infix !
>     ))
>
> why my syntax-error pattern never reach in infix:
>
> scheme@(guile-user)> {x <+ 7 8}
> While compiling expression:
> Syntax error:
> unknown file:3:3: source expression failed to match any pattern in form <+
>
> but ok in prefix:
>
> scheme@(guile-user)> (<+ x 9 10)
> While compiling expression:
> Syntax error:
> unknown location: <+: Bad <- form in form (<+ x 9 10)
>
> why?
> Regards,
> Damien

-- 
repositories: https://notabug.org/ZelphirKaltstahl



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

* Re: macro syntax-error works in prefix but not curly-infix
  2021-09-19 12:34 ` Zelphir Kaltstahl
@ 2021-09-20  9:16   ` Damien Mattei
  0 siblings, 0 replies; 5+ messages in thread
From: Damien Mattei @ 2021-09-20  9:16 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: Guile User

hello Zelphir,

i understood my error, all was ok is just that  it convert this way:
'{x <+ 2 3}
($nfx$ x <+ 2 3)

in general the prefix notation of  {1 <+ 2 3 4 ...} is not (<+ 1 2 3 4 ...)
because (<+ 1 2 3 4 ...) in infix is {1 <+ 2 <+ 3 <+ 4 <+ ...}

it a stupid error of mine

i will drop the error case in macro and let Scheme deal with the error
itself ,he do it fine...
we message like that:

Syntax error:
unknown location: source expression failed to match any pattern in form <+

i find the error because thinking to ellipsis make me thiink to multiple
expressions in my <+ operator,anyway you help me, thank you

<+ is just in this case a define:

scheme@(guile-user)> {x <+ 7}
scheme@(guile-user)> x
7
he must be an unary operator , it does not allow multiple arity, but that
could be an idea like in C or as far as i remember one can writ x=y=7,
anyway in scheme it would be harder because SRFI 105 does not deal with
precedence... well i will do that in the future  and such writing as x=y=7
is not often used....
thank you


damien


On Sun, Sep 19, 2021 at 2:34 PM Zelphir Kaltstahl <
zelphirkaltstahl@posteo.de> wrote:

> Hi Damien!
>
> I think there might be too few expressions matched in the first case: (_
> var expr). Wouldn't it have to be:
>
> ~~~~
> (_ var expr1 expr2)
> ;; or
> (_ var exprs ...)
> ~~~~
>
> for
>
> ~~~~
> (<+ var expr1 expr2)
> ~~~~
>
> to work, simply because of the number of expressions there?
>
> But then you might need to use ellipsis in the resulting syntax somewhere,
> otherwise you get:
>
> ~~~~
> syntax: missing ellipsis in form (syntax (define var expr))
> ~~~~
>
> I don't know where that would go, but I also do not understand yet the
> goal. I think it is best to always describe, what you want to achieve, when
> you write a macro.
>
> Regards,
> Zelphir
> On 9/4/21 4:41 PM, Damien Mattei wrote:
>
> hi,
>
> i have this macro:
>
> (define-syntax <+
>   (syntax-rules ()
>     ((_ var expr) (define var expr))
>     ((_ err ...) (syntax-error "Bad <- form")) ;; does not work in infix !
>     ))
>
> why my syntax-error pattern never reach in infix:
>
> scheme@(guile-user)> {x <+ 7 8}
> While compiling expression:
> Syntax error:
> unknown file:3:3: source expression failed to match any pattern in form <+
>
> but ok in prefix:
>
> scheme@(guile-user)> (<+ x 9 10)
> While compiling expression:
> Syntax error:
> unknown location: <+: Bad <- form in form (<+ x 9 10)
>
> why?
> Regards,
> Damien
>
> --
> repositories: https://notabug.org/ZelphirKaltstahl
>
>


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

end of thread, other threads:[~2021-09-20  9:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-04 14:41 macro syntax-error works in prefix but not curly-infix Damien Mattei
2021-09-19  6:23 ` adriano
2021-09-19  7:48   ` Damien Mattei
2021-09-19 12:34 ` Zelphir Kaltstahl
2021-09-20  9:16   ` Damien Mattei

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).