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

  1. <Mike@rice> wants to know how to make this function work:
  2.  
  3.     ; construct an identity transformation matrix.
  4.     (defun tm-new ()
  5.         (let ((name (gensym)))
  6.         (*array name 'flonum-block 4 4)
  7.         (do i 0 (1+ i) (= i 4) (store (name i i) 1.0))
  8.         name)
  9.     )
  10.  
  11. The problem is that send is a macro (see lisplib/array.l), and at
  12. compile time it is impossible for it to determine exactly the "data
  13. type" of name.  Therefore, it expands the function to:
  14.  
  15.     (defun tm-new ()
  16.         (let ((name (gensym)))
  17.         (*array name 'flonum-block 4 4)
  18.         (do i 0 (1+ i) (= i 4) (name 1.0 i i))
  19.         name)
  20.     )
  21.  
  22. Essentially, it just assumes 'name is a symbol which has an array in its
  23. function binding, or else which symevals (possibly recursively) to
  24. something that is either an array, or a symbol with an array in its
  25. function binding.  When the compiler compiles the expansion, it assumes
  26. that it wants to call the function-binding of name, not the
  27. function-binding of symeval of name.  In the interpreter it happens to
  28. work because eval of a list in the interpreter (but not the compiler) is
  29. defined to repetitively evaluate the car of the list until it finds a
  30. recognizable function or array.  (See chapter 4.)  But note!!  If 'name
  31. also has a function binding, the interpreter will find it instead of the
  32. array!
  33.  
  34. What you really want to do, then, is this:
  35.  
  36.     (defun tm-new ()
  37.         (let ((name (gensym)))
  38.         (*array name 'flonum-block 4 4)
  39.         (do i 0 (1+ i) (= i 4) (funcall name 1.0 i i))
  40.         name)
  41.     )
  42.  
  43. This guarantees that name gets symevaled once before the interpreter
  44. checks for function bindings, which also does the right thing in
  45. compiled code.  Unfortunately, you will have to write this out by hand.
  46. I don't see any way that the send macro can be fixed.  If it always
  47. returned the extra funcall, then this simple case wouldn't work
  48. compiled:
  49.  
  50.     (array foo ...)
  51.     (store foo ...)
  52.  
  53. Did anyone follow any of this?
  54.  
  55.  
  56.