Re: with-syntax return error in Guile, not in Kawa or Racket

Jean Abou Samra <[email protected]>
Newsgroups gmane.lisp.guile.user
Message-ID <[email protected]>
> sorry, but this can not works because my macro is defined this way:
> (define-syntax <-
>   (lambda (stx)
>     (syntax-case stx ()
>       ;; silly case
>       ((_ ( ) expr)
>        #'(void)) ;; void is not portable ;'())
>       ;; one value in values !
>       ;; > {(x) <- (values 7)}
>       ;; > x
>       ;; 7
>       ((_ (var) expr)
>        #'(set!-values-plus (var) expr))
> 
> etc... other case continues
> 
> so my arguments are not put in a list as in your definition.


That has no influence whatsoever. The macro ← just replaces
itself with <- and then <- does its job as usual.

For example, this works perfectly:

(define-syntax <-
  (syntax-rules ()
    ((<- foo bar) (set! foo bar))
    ((<- foo) (set! foo #f))))

(define-syntax-rule (← . args) (<- . args))

(define a 5)
(← a 7)
(display a) (newline)
(← a)
(display a) (newline)


It is similar to how you can alias a procedure with

(define alias (lambda args (apply old-procedure args)))


> 
> ok i see it is not define-syntax but define-syntax-rules, first not in R6RS,
> so not portable ,does not exist in Kawa:
> #|kawa:1|# define-syntax-rules
> /dev/tty:1:1: warning - no declaration seen for define-syntax-rules
> /dev/tty:1:1: unbound location: define-syntax-rules


OK, make that

(define-syntax ←
  (syntax-rules ()
    ((← . args)
     (<- . args))))

define-syntax-rule is merely a shortcut for syntax-rules
macros with just one rule like this (but it's indeed no
standard).


> but i test it with my guile code,fails too at run-time:
> scheme@(guile-user)> (logic-test)
> test 1
> (or (and (not a) (not b) (not c) (not d)) (and (not a) (not b) (not c) d)
> (and
> (not a) (not b) c (not d)) (and (not a) b (not c) d) (and (not a) b c (not
> d))
> (and (not a) b c d) (and a (not b) (not c) (not d)) (and a (not b) (not c)
> d)
> (and a (not b) c (not d)) (and c (not d))) = ice-9/boot-9.scm:1685:16: In
> procedure raise-exception:
> Unbound variable: lin
> 
> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]> ,bt
> In /Users/mattei/library-FunctProg/guile/logiki+.scm:
>   2848:18  5 (_ #<continuation 101c6a500>)
>    743:23  4 (infix-symb-min-dnf _)
>   1777:41  3 (minimal-dnf _)
>   2707:38  2 (_ _)
>   2526:19  1 (identify-essential-prime-implicants _ _)
> In ice-9/boot-9.scm:
>   1685:16  0 (raise-exception _ #:continuable? _)
> 
> the offending code is here:
> 
> ;; construction of the array
>   ;; set the left column containing prime implicants
>   (for-basic (lin 0 {lgt-pi - 1})
>      ;;(display "lin=") (display lin) (newline)
>      ;;(display "{vct-prime-implicants[lin]}=") (display
> {vct-prime-implicants[lin]}) (newline)
>      ;;(display "{iepi[{lin + 1} 0]}=") (display {iepi[{lin + 1} 0]})
> (newline)
>      {iepi[{lin + 1} 0] ← vct-prime-implicants[lin]})
>      ;;{iepi[{lin + 1} 0] <- vct-prime-implicants[lin]})
> 
>   ;(display "iepi after") (newline)
> 
> exactly here, just in the macro:
> {iepi[{lin + 1} 0] ← vct-prime-implicants[lin]})
> in the macro lin is not more binded, so i suppose there is a problem of
> hygiene, the macro wipe out the binding of lin
> 
> but it works at REPL,strange ... :
> 
>   1685:16  0 (raise-exception _ #:continuable? _)
> scheme@(guile-user) [1]> ,q
> scheme@(guile-user)> {v <+ (vector 1 2 3 4)}
> scheme@(guile-user)> {v[1 : 3] <- #(-1 -2 -3 -4 -5 -6 -7)[2 : 4]}
> <- : #'(index ...) = (#<syntax:unknown file:6:3 1> #<syntax:unknown file:6:5
> :> #<syntax:unknown file:6:7 3>)
> <- : (syntax->datum #'(index ...)) = (1 : 3)
> <- : #'parsed-args=#<syntax (#<syntax:assignment.scm:116:64 list> 1 : 3)>
> <- :  (syntax->datum #'parsed-args)=(list 1 : 3)
> $bracket-apply$ : parsed-args=#<syntax
> (#<syntax:apply-square-brackets.scm:107:57 list> 2 : 4)>
> scheme@(guile-user)> v
> $1 = #(1 -3 -4 4)
> scheme@(guile-user)> {v[1 : 3] ← #(-1 -2 -3 -4 -5 -6 -7)[2 : 4]}
> <- : #'(index ...) = (#<syntax:unknown file:8:3 1> #<syntax:unknown file:8:5
> :> #<syntax:unknown file:8:7 3>)
> <- : (syntax->datum #'(index ...)) = (1 : 3)
> <- : #'parsed-args=#<syntax (#<syntax:assignment.scm:116:64 list> 1 : 3)>
> <- :  (syntax->datum #'parsed-args)=(list 1 : 3)
> $bracket-apply$ : parsed-args=#<syntax
> (#<syntax:apply-square-brackets.scm:107:57 list> 2 : 4)>
> scheme@(guile-user)> v
> $2 = #(1 -3 -4 4)
> scheme@(guile-user)> (define lin 1)
> scheme@(guile-user)> {v[lin : 3] ← #(-1 -2 -3 -4 -5 -6 -7)[2 : 4]}
> <- : #'(index ...) = (#<syntax:unknown file:11:3 lin> #<syntax:unknown
> file:11:7 :> #<syntax:unknown file:11:9 3>)
> <- : (syntax->datum #'(index ...)) = (lin : 3)
> <- : #'parsed-args=#<syntax (#<syntax:assignment.scm:116:64 list> lin : 3)>
> <- :  (syntax->datum #'parsed-args)=(list lin : 3)
> $bracket-apply$ : parsed-args=#<syntax
> (#<syntax:apply-square-brackets.scm:107:57 list> 2 : 4)>
> scheme@(guile-user)> v
> $3 = #(1 -3 -4 4)
> 
> and even with a variable ,i defined lin in the example


Hard to tell with so much code and without context on what
you're trying to do, but this might be caused precisely by
stripping identifier annotations. Consider:

(define-syntax mac
  (lambda (sintax)
    (syntax-case sintax ()
      ((mac arg)
       (datum->syntax #f (syntax->datum #'arg))))))

;; Works:
;; (define lin 6)
;; (display (mac lin))

;; Fails (as expected):
(let ((lin 5))
  (display (mac lin)))
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQSZ7TKxnKGyBvBjzBmj8PYLiTOX/gUCZj33+gAKCRCj8PYLiTOX
/hzgAP45SQdlF4T1CxVt9/AKoxi1wnGCTKsMoScb2oXZ6OdORwD+MGxJTIY5/mEs
Esqwj4IFWdDkgg6x1aAisIsXNI8aKgQ=
=u1z+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.