| Paste number 50513: | make-load-form with a hash-table. how is this supposed to work? |
| Pasted by: | baggito |
| 9 months, 2 weeks ago | |
| #lispcafe | Context in IRC logs | |
| Paste contents: |
(let ((saved (with-output-to-string (out) (let ((a (make-hash-table))) (loop for key across "abcdef" for val from 1 do (setf (gethash key a) val)) (multiple-value-bind (create initialize) (make-load-form a) (with-standard-io-syntax (print create out) (print initialize out))))))) (format t "Wrote output:~%~a~&--END--~%" saved) (with-input-from-string (in saved) (let ((create-form (read in)) (init-form (read in))) (format t "Eval from create form:~%~2t~A~%and init form:~%~2t~a~%" create-form init-form) (let ((created (multiple-value-list (eval create-form))) (initialized (multiple-value-list (eval init-form)))) (format t "Create form returned values:~%~2t~a~%and init form returned values:~%~2t~a~%" created initialized))))) #| Wrote output: (MAKE-HASH-TABLE :TEST (QUOTE EQL) :SIZE (QUOTE 16) :REHASH-SIZE (QUOTE 1.5) :REHASH-THRESHOLD (QUOTE 1.0) :WEAKNESS (QUOTE NIL)) (SB-IMPL::%STUFF-HASH-TABLE #.(SB-IMPL::%STUFF-HASH-TABLE (MAKE-HASH-TABLE :TEST (QUOTE EQL) :SIZE (QUOTE 16) :REHASH-SIZE (QUOTE 1.5) :REHASH-THRESHOLD (QUOTE 1.0) :WEAKNESS (QUOTE NIL)) (QUOTE ((#\f . 6) (#\e . 5) (#\d . 4) (#\c . 3) (#\b . 2) (#\a . 1)))) (QUOTE ((#\f . 6) (#\e . 5) (#\d . 4) (#\c . 3) (#\b . 2) (#\a . 1)))) --END-- Eval from create form: (MAKE-HASH-TABLE TEST 'EQL SIZE '16 REHASH-SIZE '1.5 REHASH-THRESHOLD '1.0 WEAKNESS 'NIL) and init form: (%STUFF-HASH-TABLE #<HASH-TABLE :TEST EQL :COUNT 6 {A7A9851}> '((f . 6) (e . 5) (d . 4) (c . 3) (b . 2) (a . 1))) Create form returned values: (#<HASH-TABLE :TEST EQL :COUNT 0 {A7AB8C1}>) and init form returned values: (#<HASH-TABLE :TEST EQL :COUNT 6 {A7A9851}>) |# |
Annotations for this paste:
| Annotation number 1: | can you do it this way? |
| Pasted by: | faxathisia |
| 9 months, 2 weeks ago | |
| Context in IRC logs | |
| Paste contents: |
| CL-USER> (defun temp-hash-table () (let ((h (make-hash-table))) (setf (gethash 0 h) 'a) (setf (gethash 1 h) 'b) (setf (gethash 2 h) 'c) h)) STYLE-WARNING: redefining TEMP-HASH-TABLE in DEFUN TEMP-HASH-TABLE CL-USER> (temp-hash-table) #<HASH-TABLE :TEST EQL :COUNT 3 {1190F461}> CL-USER> (multiple-value-bind (create init) (make-load-form *) (eval create) (eval init)) #<HASH-TABLE :TEST EQL :COUNT 3 {1190F461}> |