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

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