unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#52112: Compilation of macro returning record type fails
@ 2021-11-25 17:45 Jean Abou Samra
  2021-11-26 18:54 ` Taylan Kammer
  0 siblings, 1 reply; 3+ messages in thread
From: Jean Abou Samra @ 2021-11-25 17:45 UTC (permalink / raw)
  To: 52112

Record types are self-evaluating:

scheme@(guile-user)> (eval (make-record-type 'my-record '()) 
(current-module))
$1 = #<record-type my-record>

Yet, when a macro returns a record type, Guile fails
to byte-compile the code, even though the execution
(via the evaluator) works fine. Here is a simple example:


(define-macro (my-macro)
   (make-record-type 'my-record-2 '()))

(display (my-macro))
(newline)


Execution log:


$ guile --no-auto-compile test.scm
#<record-type my-record-2>

$ guile test.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/jean/test.scm
;;; WARNING: compilation of /home/jean/test.scm failed:
;;; unhandled constant #<record-type my-record-2>
#<record-type my-record-2>

This is with Guile version 3.0.5.130-5a1e7.





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

* bug#52112: Compilation of macro returning record type fails
  2021-11-25 17:45 bug#52112: Compilation of macro returning record type fails Jean Abou Samra
@ 2021-11-26 18:54 ` Taylan Kammer
  2021-11-26 19:02   ` Jean Abou Samra
  0 siblings, 1 reply; 3+ messages in thread
From: Taylan Kammer @ 2021-11-26 18:54 UTC (permalink / raw)
  To: Jean Abou Samra, 52112

On 25.11.2021 18:45, Jean Abou Samra wrote:
> Record types are self-evaluating:
> 
> scheme@(guile-user)> (eval (make-record-type 'my-record '()) (current-module))
> $1 = #<record-type my-record>
> 
> Yet, when a macro returns a record type, Guile fails
> to byte-compile the code, even though the execution
> (via the evaluator) works fine. Here is a simple example:
> 
> 
> (define-macro (my-macro)
>   (make-record-type 'my-record-2 '()))
> 
> (display (my-macro))
> (newline)
> 
> 
> Execution log:
> 
> 
> $ guile --no-auto-compile test.scm
> #<record-type my-record-2>
> 
> $ guile test.scm
> ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
> ;;;       or pass the --no-auto-compile argument to disable.
> ;;; compiling /home/jean/test.scm
> ;;; WARNING: compilation of /home/jean/test.scm failed:
> ;;; unhandled constant #<record-type my-record-2>
> #<record-type my-record-2>
> 
> This is with Guile version 3.0.5.130-5a1e7.

I don't think that's supposed to work.  I find it surprising that
record-type objects are self-evaluating, and in any case they can't
be turned into bytecode.

Your macro could return code that evaluates to a record definition.
Would that solve your use-case?

-- 
Taylan





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

* bug#52112: Compilation of macro returning record type fails
  2021-11-26 18:54 ` Taylan Kammer
@ 2021-11-26 19:02   ` Jean Abou Samra
  0 siblings, 0 replies; 3+ messages in thread
From: Jean Abou Samra @ 2021-11-26 19:02 UTC (permalink / raw)
  To: Taylan Kammer, 52112

Thanks for your reply.

Le 26/11/2021 à 19:54, Taylan Kammer a écrit :
> I don't think that's supposed to work.  I find it surprising that
> record-type objects are self-evaluating, and in any case they can't
> be turned into bytecode.
>
> Your macro could return code that evaluates to a record definition.
> Would that solve your use-case?


Yes, that is how I solved it in LilyPond
(https://gitlab.com/lilypond/lilypond/-/merge_requests/1026).

I was also somewhat surprised to see that
record types are self-evaluating. I don't
know where to check in R6RS what the expected
behavior would be. At any rate, it seems that
there is an inconsistency between the interpreter
and the compiler that would warrant resolving
either way.





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

end of thread, other threads:[~2021-11-26 19:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25 17:45 bug#52112: Compilation of macro returning record type fails Jean Abou Samra
2021-11-26 18:54 ` Taylan Kammer
2021-11-26 19:02   ` Jean Abou Samra

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