* Small enhancement to options interface
@ 2002-10-29 0:31 Neil Jerram
2002-11-04 19:00 ` Neil Jerram
0 siblings, 1 reply; 2+ messages in thread
From: Neil Jerram @ 2002-10-29 0:31 UTC (permalink / raw)
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
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Small enhancement to options interface
2002-10-29 0:31 Small enhancement to options interface Neil Jerram
@ 2002-11-04 19:00 ` Neil Jerram
0 siblings, 0 replies; 2+ messages in thread
From: Neil Jerram @ 2002-11-04 19:00 UTC (permalink / raw)
>>>>> "Neil" == Neil Jerram <neil@ossau.uklinux.net> writes:
Neil> A strange thing about Guile's options interface is that
Neil> xxx-options, xxx-enable and xxx-disable all want a quoted
Neil> option symbol as their argument, whereas xxx-set! wants an
Neil> _unquoted_ symbol. [...]
Further^2 thoughts on this: actually it's a can of worms. Allowing
xxx-set! to take a quoted symbol makes it look like it does
evaluation (which we can't make it do because that would be
non-back-compatible), and then someone will get very confused by code
like this:
(define stack depth)
(debug-set! stack 400) ; intending to set the 'depth option
I'll just apply the deobfuscation part of this patch, and hope that a
better approach to options in general comes along soon ...
Neil
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-11-04 19:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-29 0:31 Small enhancement to options interface Neil Jerram
2002-11-04 19:00 ` Neil Jerram
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).