From 2390d46a6323394adbafa630b54b9bd50aca9229 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 19 Dec 2016 19:35:38 +0100 Subject: [PATCH] Closure is not a pair. * module/mes/base.mes (closure_p, mes_car, mes_cdr): New function. (pair_p): Closure is not a pair. * NEWS: Mention it. * psyntax-0.mes (self-evaluating?): Add closure?. --- NEWS | 2 ++ module/mes/base.mes | 2 +- module/mes/psyntax-0.mes | 2 +- tests/closure.test | 6 ++++++ type.c | 20 +++++++++++++++++++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 0495be8f..621578b3 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ block-comments are all handled by the Scheme reader later. *** Lambda* and define* are now supported. *** #;-comment is now supported. *** Non-nested #| |#-comment is now supported. +** Noteworthy bug fixes +*** Closure is not a pair. * Changes in 0.3 since 0.2 ** Core *** Number-based rather than pointer-based cells. diff --git a/module/mes/base.mes b/module/mes/base.mes index 7ac4b4d9..e3510000 100644 --- a/module/mes/base.mes +++ b/module/mes/base.mes @@ -59,5 +59,5 @@ (define (procedure? p) (cond ((builtin? p) #t) ((and (pair? p) (eq? (car p) 'lambda))) - ((and (pair? p) (eq? (car p) '*closure*))) + ((closure? p) #t) (#t #f))) diff --git a/module/mes/psyntax-0.mes b/module/mes/psyntax-0.mes index 04bb1d6d..350dc6c9 100644 --- a/module/mes/psyntax-0.mes +++ b/module/mes/psyntax-0.mes @@ -33,7 +33,7 @@ (define annotation? (lambda (x) #f)) (define (self-evaluating? x) - (or (boolean? x) (number? x) (string? x) (char? x) (null? x))) + (or (boolean? x) (number? x) (string? x) (char? x) (null? x) (closure? x))) (define (void) (if #f #f)) diff --git a/tests/closure.test b/tests/closure.test index 494daca8..80987192 100755 --- a/tests/closure.test +++ b/tests/closure.test @@ -95,4 +95,10 @@ exit $? "noexpand") (pass-if "closure 9" (sc-expand)))) +(pass-if "closure is procedure" + (procedure? (lambda () #t))) + +(pass-if-not "closure is not a pair" + (pair? (lambda () #t))) + (result 'report) diff --git a/type.c b/type.c index ca28387a..c8d5933b 100644 --- a/type.c +++ b/type.c @@ -26,6 +26,24 @@ char_p (SCM x) return TYPE (x) == CHAR ? cell_t : cell_f; } +SCM +closure_p (SCM x) +{ + return (TYPE (x) == PAIR && CAR (x) == cell_closure) ? cell_t : cell_f; +} + +SCM +mes_car (SCM x) +{ + return CAR (x); +} + +SCM +mes_cdr (SCM x) +{ + return CDR (x); +} + SCM keyword_p (SCM x) { @@ -47,7 +65,7 @@ number_p (SCM x) SCM pair_p (SCM x) { - return TYPE (x) == PAIR ? cell_t : cell_f; + return (TYPE (x) == PAIR && CAR (x) != cell_closure) ? cell_t : cell_f; } SCM