home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / lisp / lispnews / text0272.txt < prev    next >
Encoding:
Text File  |  1985-11-10  |  2.7 KB  |  58 lines

  1. I too was bothered by fasl's insistence on using the standard readtable
  2. to process literals in liszt-compiled files until I realized the reason
  3. for this limitation:
  4.  
  5. All source input to liszt is processed by `read' -- that is, the
  6. compiler reads only forms, never ascii strings.  In order to place a
  7. literal form in an object file, liszt must essentially convert the form
  8. back into ASCII via `print'.  (Actually, a somewhat modified version
  9. which knows how to wrap an assembler `.asciz' directive around the
  10. printed representation of the form, etc.)  Unfortunately, liszt can make
  11. no easy assumption about what strange readtable is likely to be active
  12. at load time, so the only sane choice is to use the standard readtable.
  13.  
  14. In other words, you shouldn't think of literal forms stored in a fasl
  15. object file as external (ASCII) representation of lisp data.  Rather,
  16. liszt/fasl use ASCII as a convenient "position-independent" encoding of
  17. a form which has already been processed by read at compile time.  This
  18. is entirely analogous to what traditional compilers and assemblers do
  19. with numeric constants represented in ASCII inside a program, except
  20. their compiler-to-loader data format uses the native binary number
  21. representation of the object machine.
  22.  
  23. One could argue that this isn't really a limitation provided one is
  24. willing and able to provide the desired readtable at compile time.
  25. Usually this isn't a problem, although I once I had a macro which wanted
  26. to insert into a form a particular uninterned symbol which (obviously)
  27. couldn't even exist until execution time.  I was forced to wrap the form
  28. inside another function which would accomplish the substitution at load
  29. time.
  30.  
  31. There is no reason liszt could not be made to copy ASCII forms into the
  32. fasl file without read->print translation, but this would require
  33. changes to the compiler and to fasl format, things not to be done
  34. lightly.  If you *really* need the facility, and don't need to read huge
  35. volumes of data, you could include ASCII forms inside a fasl file by
  36. encoding them as lisp strings, and seeing that they get processed by an
  37. appropriate function at load time, something like:
  38.  
  39.     (defun strange-read (str)
  40.            (let ((readtable strange-readtable))
  41.             (readlist (explodec str))))
  42.  
  43. Then you can do things like:
  44.     (setq foo (strange-read ") a b )c d( e (")
  45.  
  46. [What?  You don't like my readtable with the parens reversed?]  The
  47. invocation of `strange-read' can, of course, be conveniently macrofied.
  48. If appropriate, automatic printing of literal strings can also be
  49. performed by compile time macros.  You will have to deal with the
  50. problem of escaping quotes inside these forms, and you might want to
  51. enable string garbage collection if you do a lot of this sort of thing.
  52.  
  53. I know it's ugly, but...
  54.  
  55. Steve Haflich
  56.  
  57.  
  58.