From: Timothy J. H. <tim...@ma...> - 2004-03-29 02:12:24
|
On Mar 28, 2004, at 8:33 PM, Borislav Iordanov wrote: > Hi all, > > In a program, I'm trying to construct and store an expression for later > evaluation. Consider: > > (define l (LinkedList.)) > (define point (java.awt.Point. 50 50)) > (.add l point) > (define expr `(.remove l ,point)) > > Then: > > (eval expr) > > properly removes the point from the linked list. This is fine. But > after > replacing the point with a pair: > > (define l (LinkedList.)) > (define line (cons (java.awt.Point. 100 100) (java.awt.Point. 10 10))) > (.add l line) > (define expr `(.remove l ,line)) > > Trying to evaluate the expression produces an error: > > (eval expr) > => SchemeException: expected object of type list (i.e. pair or empty), > but got: , "java.awt.Point[x=10,y=10]" > > Why and what to do? The problem is that eval expects to try an evaluate an s-expression constructed from lists, atoms, and other objects. When it encounters the cons-cell of line it interprets it as part of the syntax of the expression, not as part of the value of the object. The simple theoretical fix is to not allow any "values" in expressions that are being evaluated, i.e., only allow expressions that would result from reading input from a string. In practice, we allow the expression to be evaluated to contain any values whatsoever with the proviso that any cons cells are considered part of the expression to be evaluated. You can solve this particular problem by evaluating expr2 defined by (define expr2 `(.remove l line)) or by quoting the lin (define expr5 `(.remove l ',line)) where the quote here is similarly extended to create an expression which the eval procedure will leave as is... Hope this helps.... ---Tim--- > > Thanks a lot in advance, > Boris > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Jscheme-user mailing list > Jsc...@li... > https://lists.sourceforge.net/lists/listinfo/jscheme-user |