(2.1.7) evil use of 'eval' in Canvitem.stk

From: Lars Thomas Hansen <lth_at_cs.uoregon.edu>
Date: Tue, 18 Jul 1995 15:39:44 -0700

(This may have been fixed in 2.2, but I haven't had the opportunity to

The following code is typical for a construct used extensively in
Canvitem.stk but nowhere else in the libraries:

  (define-method initialize-item ((self <Line>) canvas coords args)
    (eval `(,canvas 'create 'line ,_at_coords
                                  ,_at_(get-keyword :tk-options args '()))))

In order to use this at all, you have to call it in a manner along the lines
of this:

  (let ((l (make <Line> :coords '('1c '1c '1c '2c) :width ''2m)))

where the double quotes are required to account for the behaviour of
eval. This creates the line, but you'll receive an error message later
on when the (quote 1c) is determined as being a "bad screen distance".

Instead, the method can be rewritten as:

  (define-method initialize-item ((self <Line>) canvas coords args)
    (apply canvas 'create 'line (append coords
                                        (get-keyword :tk-options args '()))))

which allows the obvious call

  (let ((l (make <Line> :coords '(1c 1c 1c 2c) :width '2m)))

to work just fine. In addition it's cleaner and probably also faster, as
apply (in general) does less work than eval.

Is there any good reason why the code is written using eval?
 If so, how is one supposed to create a <Line>?
 If not, can the next distribution please use apply here?

Received on Wed Jul 19 1995 - 00:45:14 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST