home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / lisp / mcl / 2112 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  3.2 KB

  1. Path: sparky!uunet!crdgw1!rpi!gatech!udel!bogus.sura.net!howland.reston.ans.net!spool.mu.edu!agate!stanford.edu!apple!cambridge.apple.com!bill@cambridge.apple.com
  2. From: bill@cambridge.apple.com (Bill St. Clair)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: shiftf
  5. Message-ID: <9301271850.AA22730@cambridge.apple.com>
  6. Date: 27 Jan 93 19:51:42 GMT
  7. Sender: owner-info-mcl@cambridge.apple.com
  8. Lines: 55
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. At 11:31 1/27/93 +0017, Kim Barrett wrote:
  12. >> MCL's shiftf macro produces unneccesary complicated form in the simple
  13. >> cases.  The most frequent use of shift, is probably for simple pointer
  14. >> switching in list structures: Replacing a value while saving the old
  15. >> value.  (The two-argument (place, newvalue) special case of shiftf used
  16. >> to have its own name, swapf)
  17. >> 
  18. >> Here's what MCL's shiftf produces:
  19. >> ? (macroexpand '(shiftf (cddr liste) nil))
  20. >> (LET* ((#:G91 LISTE) 
  21. >>        (#:G89 (MULTIPLE-VALUE-LIST (CDDR #:G91)))) 
  22. >>   (DECLARE (DYNAMIC-EXTENT #:G89)) 
  23. >>   (MULTIPLE-VALUE-BIND (#:G90) NIL 
  24. >>     (PROGN (CCL::SET-CDDR #:G91 #:G90))) 
  25. >>   (VALUES-LIST #:G89))
  26. >> 
  27. >> Here's a simpler expansion suggestion (Allegro 4.1 produces something
  28. >> similar to this):
  29. >> (LET* ((#:G91 LISTE) 
  30. >>        (#:G89 (CDDR #:G91))
  31. >>        (#:G90 NIL))
  32. >>   (CCL::SET-CDDR #:G91 #:G90)
  33. >>   #:G89)
  34. >
  35. >You didn't mention which version of MCL you are using.  SETF and related macros 
  36. >had a lot of work done on them not too long ago.  In MCL2.0p2 (and probably in 
  37. >MCL2.0, but p2 is what I've got in front of me right now) the expansion is
  38. >
  39. >(LET* ((#:G30466 LISTE))
  40. >  (MULTIPLE-VALUE-PROG1 (CDDR #:G30466)
  41. >    (MULTIPLE-VALUE-BIND (#:G30465)
  42. >        NIL
  43. >      (PROGN (SET-CDDR #:G30466 #:G30465)))))
  44. >
  45. >The MULTIPLE-VALUE-BIND with a single variable is trivially transformed into a 
  46. >LET.  If the compiler handling for MULTIPLE-VALUE-PROG! recognizes that CDDR 
  47. >always returns one value and makes the obvious transformation, then compiling 
  48. >this expansion should produce the same code as your simpler expansion, without 
  49. >requiring that the SHIFTF macro (and presumably lots of other similar macros) 
  50. >itself try to optimize the expansion.  The reason for all the 
  51. >multiple-value-mumbles in the expansion is to support multiple-valued place 
  52. >forms (see X3J13 issue SETF-MULTIPLE-STORE-VARIABLES).  Rather than try to make 
  53. >the macros optimize this stuff, its much better to make the compiler smart 
  54. >about some of these special cases where multiple value forms can be transformed 
  55. >into single value forms.  Unfortunately, the compiler doesn't currently seem to 
  56. >know about CDDR being single valued, so things could be a bit better.  But the 
  57. >"bug" is there, not in SHIFTF.
  58.  
  59. Unpatched MCL 2.0 produces the expansion to which Espen referred. Patch 2
  60. modifies SHIFTF & ROTATEF to produce Kim's better code. Mark announced how to
  61. get patch 2 about a month ago. Ask and I'll resend. I have prepared a patch that
  62. makes the compiler a little bit smarter about turning MULTIPLE-VALUE-PROG1 into
  63. PROG1. In particular, it makes the patch 2 expansion for (shift (cddr liste) nil)
  64. compile into the same code as the Allegro 4.1 expansion. Ask for
  65. "single-value-prog1-patch".
  66.