TYPE-ERROR with special variable
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
When using cl-ledger (https:/
If I enter the following:
(ql:quickload "cl-ledger")
(ledger:
I get the following error:
debugger invoked on a TYPE-ERROR in thread
#<THREAD "main thread" RUNNING {10005505B3}>:
The value
#<unknown immediate object, lowtag=#b1, widetag=#x61 {61}>
is not of type
NUMBER
when binding SB-KERNEL::X
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-
0: [ABORT] Exit debugger, returning to top level.
(SB-KERNEL:
0]
Apparently the problem comes from the CALCULATE-TOTALS function in transforms/
(defun calculate-totals (xact-series &key (set-amount nil) (set-total nil)
...some forms...
(let ((running-total 0)
(map-fn
'transaction
#'(lambda (xact)
(incf *value-
...some forms...
(setf *value-
xact-series)))
According to the backtrace, the (incf *value-
Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {10005505B3}>
0: (SB-KERNEL:
The *value-
(defvar *value-
I noticed that adding a SPECIAL declaration in CALCULATE-TOTALS makes the error disappear:
(defun calculate-totals (xact-series &key (set-amount nil) (set-total nil)
...some forms...
(let ((running-total 0)
(declare (special *value-
(map-fn
'transaction
#'(lambda (xact)
(incf *value-
...some forms...
(setf *value-
xact-series)))
The other special variable (*value-
Changed in sbcl: | |
status: | Fix Committed → Fix Released |
I'm not entirely familiar with SERIES, but map-fn returns an object that has calls to that lambda in it, right? If so, that binding of the special variable will have long since been lost.
* (declaim (special *s*))
(*S*)
* (setf *s* :bad)
:BAD
* (funcall (let ((*s* :good)) (lambda () *s*)))
:BAD
This is different from lexical bindings:
* (funcall (let ((s :good)) (lambda () s)))
:GOOD