Here is a snippet of code, which I expect to produce the same result
with both eval and compile, but the results are different.

When compile is used (define a a) sets a to #<undefined>.

Is it a bug?

--8<---------------cut here---------------start------------->8---
(define-module (2024-06-18-define-bug))

(use-modules (system base compile))

(define (peval e)
  (compile
   e
   #:to 'value
   #:env (resolve-module
          '(2024-06-18-define-bug))))

(define (test-eval teval)
  (teval '(define a 1))
  (teval '(define a a))
  (format #t "a value with ~a is ~a\n" teval (teval 'a)))

(test-eval peval)
(test-eval primitive-eval)

(exit 0)

;; guile -l 2024-06-18-define-bug.scm # output is:
;; a value with #<procedure peval (e)> is #<unspecified>
;; a value with #<procedure primitive-eval (exp)> is 1
--8<---------------cut here---------------end--------------->8---

-- 
Best regards,
Andrew Tropin

Attachment: signature.asc
Description: PGP signature

Reply via email to