[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Small enhancement to options interface
From: |
Neil Jerram |
Subject: |
Small enhancement to options interface |
Date: |
29 Oct 2002 00:31:22 +0000 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
A strange thing about Guile's options interface is that xxx-options,
xxx-enable and xxx-disable all want a quoted option symbol as their
argument, whereas xxx-set! wants an _unquoted_ symbol.
What is worse, is that if you call xxx-set! with a _quoted_ symbol, as
in (debug-set! 'stack 500), it does nothing, but silently -- there is
no clear indication that what you asked for didn't work.
(It may be arguable that people should expect xxx-set! to take an
unquoted symbol by analogy with set! ... but personally I've always
found the current behaviour confusing, and I frequently get it wrong.)
The patch below enhances xxx-set! so that it accepts both an unquoted
and a quoted symbol, and also simplifies some of the rather obfuscated
definition of define-option-interface. With this enhancement, we keep
backwards compatibility, but we can document in future that the
options functions always take a quoted symbol.
What do you think?
(Further thought - if this enhancement is good, would it be even
better, if optexp is not a symbol, just to let it be evaluated? This
would make xxx-set! even more similar to xxx-enable and xxx-disable,
as the latter are procedures.)
Neil
cd /home/neil/Guile/cvs/guile-core/ice-9/
diff -Naur /home/neil/Guile/cvs/guile-core/ice-9/boot-9.scm.old
/home/neil/Guile/cvs/guile-core/ice-9/boot-9.scm
--- /home/neil/Guile/cvs/guile-core/ice-9/boot-9.scm.old Tue Oct 29
00:09:13 2002
+++ /home/neil/Guile/cvs/guile-core/ice-9/boot-9.scm Tue Oct 29 00:10:01 2002
@@ -2026,24 +2026,32 @@
(begin (,interface (append (,interface)
(list '(,'unquote name)
(,'unquote exp))))
- (,interface)))))))
+ (,interface))))))
+
+ (get-option-symbol (lambda (optexp)
+ (cond ((symbol? optexp)
+ optexp)
+ ((and (list? optexp)
+ (= (length optexp) 2)
+ (eq? (car optexp) 'quote))
+ (cadr optexp))
+ (else
+ (error "Option must be specified as a
symbol or quoted symbol"))))))
(procedure->memoizing-macro
(lambda (exp env)
- (cons 'begin
- (let* ((option-group (cadr exp))
- (interface (car option-group)))
- (append (map (lambda (name constructor)
- `(define ,name
- ,(constructor interface)))
- (cadr option-group)
- (list make-options
- make-enable
- make-disable))
- (map (lambda (name constructor)
- `(defmacro ,name
- ,@(constructor interface)))
- (caddr option-group)
- (list make-set!)))))))))
+ (let* ((option-group (cadr exp))
+ (interface (car option-group))
+ (options/enable/disable (cadr option-group)))
+ `(begin
+ (define ,(car options/enable/disable)
+ ,(make-options interface))
+ (define ,(cadr options/enable/disable)
+ ,(make-enable interface))
+ (define ,(caddr options/enable/disable)
+ ,(make-disable interface))
+ (defmacro ,(caaddr option-group) (opt val)
+ `(,,(car options/enable/disable)
+ (list ',(,get-option-symbol opt) ,val)))))))))
(define-option-interface
(eval-options-interface
Diff finished at Tue Oct 29 00:10:11
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Small enhancement to options interface,
Neil Jerram <=