Path: utzoo!utgpu!watmath!clyde!att!rutgers!gatech!purdue!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!inria!crin!stephan From: stephan@crin.crin.fr (Stephan BRUNESSAUX) Newsgroups: comp.lang.lisp Subject: Common Lisp Problems with Hash-table in Macros Message-ID: <698@crin.crin.fr> Date: 8 Dec 88 18:12:44 GMT Reply-To: stephan@crin.crin.fr (Stephan BRUNESSAUX) Organization: C.R.I.N Lines: 111 Hi, Is there anybody out there who can explain me what is wrong with this example which correctly runs in both interpreted and compiled mode on Symbolics 3620 (Genera 7.2) and correctly ONLY in interpreted mode on TI Explorer II and on VAX running KCL (June 3, 1987) but not in compiled mode !?... First Part: Here is the code of a macro-function (TEST) generating a list and a function (AUX) to manipulate it. Everything is okay. | >(defmacro test (a b) | (let ((my-list (list a b))) | `(defun aux () | (mapc #'print ',my-list)))) | TEST | | >(ed "test.lsp") | | (test c b) ; macro call to compile | | "test.lsp" [New file] 2 lines, 14 characters | | >(compile-file "test") | Compiling test.lsp. | End of Pass 1. | End of Pass 2. | OPTIMIZE levels: Safety=0 (No runtime error checking), Space=0, Speed=3 | Finished compiling test.lsp. | | >(load "test") | Loading test.o | Finished loading test.o | 276 | | >(aux) | | C | B | (C B) SECOND PART: Here come the problems. Now, we generate a hash-table instead of a list. | >(defmacro test (a b) | (let ((table (make-hash-table :size 1))) | (setf (gethash a table) b) | `(defun aux () | (maphash #'(lambda (key val) | (format t "key: ~a - val: ~a~%" key val)) | ',table)))) | TEST | Just try before compile. | >(test f e) | AUX | | >(aux) | key: F - val: E | NIL (aux) returns : NIL with KCL and with SYMBOLICS #on TI EXPLORER On kcl : | >(compile-file "test") | Compiling test.lsp. | End of Pass 1. | End of Pass 2. | OPTIMIZE levels: Safety=0 (No runtime error checking), Space=0, Speed=3 | Finished compiling test.lsp. | | >(load "test") | Loading test.o | | Error: The default dispatch macro signalled an error. | Error signalled by LOAD. | | Broken at LOAD. Type :H for Help. | >>:b | Backtrace: > eval > LOAD | | >>:q On Explorer II : | > (aux) | | >>Trap #o50151 (WRITE-READ-ONLY M-T) | There was an attempt to write into 3031065, which is a read-only address; | the code was probably trying to modify a program constant. On Symbolics : | >(aux)key: F - val: G | NIL