From 5e5d4892b56463d4b22c747755100849e9ba053d Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Tue, 4 Jun 2019 14:28:55 +0200 Subject: [PATCH] guile, scheme: fix fn? when metadata contains "ismacro" Let `with-meta f m` create a function even if f is a macro, instead of setting an "ismacro" metadata that is never used again (and breaks self-hosting). Also move the test for fn? from Optional to Deferrable, the function is used for self-hosting. --- guile/core.scm | 2 +- scheme/lib/core.sld | 2 +- tests/stepA_mal.mal | 25 +++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/guile/core.scm b/guile/core.scm index fca20dbe..5831bc7d 100644 --- a/guile/core.scm +++ b/guile/core.scm @@ -150,7 +150,7 @@ ((callable? c) (let ((cc (make-callable ht (callable-unbox c) - (and (hash-table? ht) (hash-ref ht "ismacro")) + #f (callable-closure c)))) cc)) (else diff --git a/scheme/lib/core.sld b/scheme/lib/core.sld index 4d615b8d..8d533fdc 100644 --- a/scheme/lib/core.sld +++ b/scheme/lib/core.sld @@ -275,7 +275,7 @@ ((func? x) (let ((func (make-func (func-ast x) (func-params x) (func-env x) (func-fn x)))) - (func-macro?-set! func (func-macro? x)) + (func-macro?-set! #f) (func-meta-set! func meta) func)) (else diff --git a/tests/stepA_mal.mal b/tests/stepA_mal.mal index 70da5ea8..8771074c 100644 --- a/tests/stepA_mal.mal +++ b/tests/stepA_mal.mal @@ -64,6 +64,19 @@ (meta +) ;=>nil +;; Testing fn? function +(fn? +) +;=>true +(fn? (fn* () 0)) +;=>true +(fn? cond) +;=>false +(fn? "+") +;=>false +(fn? :+) +;=>false +(fn? ^{"ismacro" true} (fn* () 0)) +;=>true ;; ;; Make sure closures and metadata co-exist @@ -139,18 +152,6 @@ (def! add1 (fn* (x) (+ x 1))) -;; Testing fn? function -(fn? +) -;=>true -(fn? add1) -;=>true -(fn? cond) -;=>false -(fn? "+") -;=>false -(fn? :+) -;=>false - ;; Testing macro? function (macro? cond) ;=>true