Skip to content

Commit

Permalink
guile, scheme: fix fn? when metadata contains "ismacro"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
asarhaddon committed Jul 9, 2019
1 parent f528fab commit aac5cf7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion guile/core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scheme/lib/core.sld
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions tests/stepA_mal.mal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aac5cf7

Please sign in to comment.