Evaluation Order in Function Forms

| | TrackBacks (0)

In this blog post Ingvar Mattsson was wondering about the printed line resulting from evaluating:

(defun frob (x) (format t 'Frob: ~a~%' x))
(frob (defun frob (x) (format t 'New frob: ~a~%' x))

This provides an example where I think the ANSI Common Lisp standard is actually very helpful, since it often tries to go out of its way to point out things that are explicitly left undefined, instead of simply leaving them left undefined by not defining them, as many other standards (out of fear of being ambiguous) do. Quoting from the HyperSpec, Section 3.1.2.1.2.3 Function Forms:

Although the order of evaluation of the argument subforms themselves is strictly left-to-right, it is not specified whether the definition of the operator in a function form is looked up before the evaluation of the argument subforms, after the evaluation of the argument subforms, or between the evaluation of any two argument subforms if there is more than one such argument subform. For example, the following might return 23 or 24.

(defun foo (x) (+ x 3))
(defun bar () (setf (symbol-function 'foo) #'(lambda (x) (+ x 4))))
(foo (progn (bar) 20))

Thus we can see that the effect of evaluating the orginal two forms is indeed undefined (as already suspected by Ingvar Mattsson) as to which function definition is called in the second form, without going to the trouble of trying to take into account possible differences between evaluation and compilation, compile-time effects of defun, etc.

Which is my long-winded way of saying a big thank you to the people involved in creating the ANSI Common Lisp standards document (with special thanks to all involved in creating, releasing and maintaining the HyperSpec online text equivalent thereof, especially of course Kent Pitman), which is one of the nicest language standards I have had the pleasure of working with and against.

0 TrackBacks

Listed below are links to blogs that reference this entry: Evaluation Order in Function Forms.

TrackBack URL for this entry: http://mt.pierre-mai.de/mt/mt-tb.cgi/24

Pages

Categories

Recent Activity

2010-03-26

  • Pierre tweeted, "Note to self: Don't underestimate the pleasure of a hot steam bath after bike practice... Add episode of The Pipeline for maximum enjoyment."

2010-03-11

  • Pierre tweeted, "Ob #Lisp: anyone know why SBCL would not start up on Windows Server 2008? Is Data Execution Prevention the culprit? Is it a known Problem?"
  • Pierre tweeted, "FWIW the unbelievably heavy snow-fall regularly causing havoc again in MUC is something on the order of 3cm over 6h. Siberia is laughing."
  • Pierre tweeted, "Knowing when Winter has dragged on for too long: When you have come to expect not to be able to fly home same day. http://gdzl.la/7JZ3aw"
  • Pierre posted Knowing when Winter has dragged on for too long: When you have come to expect not to be able to fly home same day.

2010-02-21

  • Pierre tweeted, "Seem to have missed the release of Dr. Strangelove on Blu-ray! Enjoy Ken Adam's set designs in HD: http://bit.ly/bJe6iS /via @gruber"
  • Pierre tweeted, "Relistening of Massive Attack collection prompted by The New Yorker review of Heligoland: http://j.mp/aBKpk1 #lazysundays"

2010-01-26

  • Pierre tweeted, "Debugging SSL/TLS session handshake buffering issues between Apache/mod_ssl/openssl and Safari 4: Lots of fun..."

2010-01-24

2010-01-07

  • Pierre tweeted, "Ingenious use of CG by Alex Roman: http://vimeo.com/7809605 (via @chockenberry)"