unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#14537: defect in guile with syntax transformation
@ 2013-06-02  8:14 Dr. M. Luedde
  2013-06-02 21:48 ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Dr. M. Luedde @ 2013-06-02  8:14 UTC (permalink / raw)
  To: 14537; +Cc: mirko.luedde

;; I think the below code exhibits a defect with guile 1.8.7.
;;
;; The `defrec' syntax transformer (defined below) does not behave
;; correctly within an imbedding `let' expression.
;;
;; The system is CYGWIN_NT-6.1-WOW64 WDFN00305859A 1.7.18(0.263/5/3)
;; 2013-04-19 10:39 i686 Cygwin
;;
;; Guile runs in GNU bash, version 4.1.10(4)-release (i686-pc-cygwin)

;; enable `define-syntax' functionality
(use-modules (ice-9 syncase))
;; OK

(let ( (n 99) )
  (begin
    (define
      ev.OK? (lambda (x) (if (zero? x) #t
			     (od.OK? (- x 1)))))
    (define
      od.OK? (lambda (x) (if (zero? x) #f
			     (ev.OK? (- x 1))))))
  (od.OK? 99))
;; OK, evaluates to #t

(define-syntax defrec
  ;; TYPE: syntax transformer.
  ;;
  ;; REQUIRES: (defrec . X) requires that X := ((S_1 V_1) ... (S_N
  ;; V_N)). The S_I are mutually distinct symbols. The V_J may contain
  ;; references to the S_I. On evaluation of any V_J the value bound
  ;; to a referenced S_I must not be needed.
  ;;
  ;; RETURNS: The value of the expression (begin (define S_1 #f)
  ;; ... (define S_N #f) (set! S_1 V_1) ... (set! S_N V_N)).
  (syntax-rules ()
    ((_ (S V) ...)
     (begin (define S #f) ...
	    (set! S V) ...))))
;; OK

(defrec
  (ev.broken? (lambda (x) (if (zero? x) #t
			      (od.broken? (- x 1)))))
  (od.broken? (lambda (x) (if (zero? x) #f
			      (ev.broken? (- x 1))))))
(od.broken? 99)
;; OK, evaluates to #t

(let ( (n 99) )
  (defrec
    (ev.broken? (lambda (x) (if (zero? x) #t
				(od.broken? (- x 1)))))
    (od.broken? (lambda (x) (if (zero? x) #f
				(ev.broken? (- x 1))))))
  (od.broken? n))
;; Produces an error message: 
;; In standard input:
;;   14: 0* (let* ((n 99)) (defrec (ev.broken? #) (od.broken? #)) (od.broken? n))

;; standard input:14:1: In procedure memoization in expression (let* (#) (defrec # #) ...):
;; standard input:14:1: In file "standard input", line 14: Mixed definitions and expressions in (defrec (ev.broken? (lambda (x) (if (zero? x) #t (od.broken? (- x 1))))) (od.broken? (lambda (x) (if (zero? x) #f (ev.broken? (- x 1)))))).
;; Backtrace:
;; ABORT: (syntax-error)
--
Dr. M. Luedde, Rheinblick 26A, D-69226 Nussloch, Germany
+49-175-2779708, Skype: MirkoLuedde





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

end of thread, other threads:[~2013-06-03 22:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-02  8:14 bug#14537: defect in guile with syntax transformation Dr. M. Luedde
2013-06-02 21:48 ` Ludovic Courtès
2013-06-03 22:27   ` Dr. M. Luedde
2013-06-03 22:38     ` Ludovic Courtès

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