guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 2 macros in one expression


From: Damien Mattei
Subject: Re: 2 macros in one expression
Date: Sat, 15 Apr 2023 16:18:21 +0200

yes i tried it, i often get this answer :-) with this sort of problem i
recurrent have with macros and it never helps ,at the point i never
understood what is the use of this option in syntax-rules.

My error i think was to forget the expansion stage of macro expansion that
is always done for all the macros used in an expression at any level, even
if the code is not used in a branch of 'if ,'cond or other conditional the
macros will be expansed.

I will quote the <- in the opspecial and tried to eval it later, the
problem is with eval which is not really normalised between all
implementations of scheme concerning its environment of evaluation.
I will post the result.
The problem was also that in an infix evaluator i wanted to be able to
evaluate all procedure (that is ok) and all the macro too which is not
always possible with the evaluation technique i use ,it is hard to write an
infix evaluator with precedence in the language itself.But the problem
arise only with the special forms, so first i quoted them all but then i
can not find the difference in the language with '(sin 30) a procedure call
and '(1 2 3) a list when evealuating it is has sense  for (sin 30) but not
for (1 2 3)  then i removed all quotation and the macro problem arise...
just after i added some overloading functionalities in my Scheme+ when
using abstract types the evaluation of abstract object (list) with for
example the + operator overloaded became a problem.
Damien

On Sat, Apr 15, 2023 at 3:50 PM Matt Wette <matt.wette@gmail.com> wrote:

> Did you try using the following?
>
> (define-syntax $nfx$
>    (syntax-rules (<-)
>      ((...
>
>
> On 4/14/23 4:02 AM, Damien Mattei wrote:
> > hello,
> >
> > i have 2 macros used in one expression like this:
> > scheme@(guile-user)> (define i 2)
> > scheme@(guile-user)> {i <- i + 1}
> > and i got this error:
> > While compiling expression:
> > Syntax error:
> > unknown location: source expression failed to match any pattern in form
> <-
> >
> > i use SRFI-105 so :
> >   '{i <- i + 1} expand in:
> > ($nfx$ i <- i + 1)
> >
> > and i'm expecting $nfx$ to be called but none of this happens:
> > scheme@(guile-user)> ($nfx$ i <- i + 1)
> > While compiling expression:
> > Syntax error:
> > unknown location: source expression failed to match any pattern in form
> <-
> >
> > it seems to be the <- macro and i do not understand why?
> >
> > any idea?
> >
> > macros are defined like this for the beginning:
> > ;; from file assignment.scm
> > (define-syntax <-
> >
> >    (syntax-rules ()
> >      ;;  special form like : (<- ($bracket-apply$ T 3) ($bracket-apply$
> T 4))
> >
> >      ;; one dimension array, example: {a[4] <- 7}
> >      ;; $bracket-apply$ is from SRFI 105  bracket-apply is an argument of
> > the macro
> >      ((_ (bracket-apply container index) expr)
> >
> > ....
> >
> > ;; from file scheme-infix.scm
> > (define-syntax $nfx$
> >    (syntax-rules ()
> >
> >      ((_ ident opspecial term1 op term2) (cond ((or (equal? (quote
> > opspecial) (quote <-)) (equal? (quote opspecial) (quote ←)))
> >        (begin
> > (display "$nfx$") (newline)
> > (opspecial ident (op term1 term2)))) ;; {ident <- {term1 op term2}}
> >
> > ...
> >
> >
> > it is in a module like this:
> >
> > (define-module (Scheme+)
> >
> >    #:use-module (growable-vector)
> >    #:use-module (srfi srfi-69) ;; Basic hash tables
> >    #:use-module (srfi srfi-31) ;; rec
> >    #:export ($nfx$ def $bracket-apply$ <- ← -> → <+ ⥆ +> ⥅ declare $ &
> condx
> > <> ≠ ** <v v> ⇜ ⇝ repeat)
> >    #:replace (do when unless))
> >
> >
> >
> > (include-from-path "def.scm")
> > (include-from-path "array.scm")
> > (include-from-path "set-values-plus.scm")
> > (include-from-path "apply-square-brackets.scm")
> > (include-from-path "assignment.scm")
> > (include-from-path "declare.scm")
> > (include-from-path "condx.scm")
> > (include-from-path "block.scm")
> > (include-from-path "not-equal.scm")
> > (include-from-path "exponential.scm")
> > (include-from-path "while-do-when-unless.scm")
> > (include-from-path "repeat-until.scm")
> > (include-from-path "scheme-infix.scm")
> >
> > if it can help.
> >
> > Regards,
> > Damien
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]