Evaluation Order in Function Forms

| No TrackBacks

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.

No TrackBacks

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

About this Entry

This page contains a single entry by Pierre R. Mai published on June 17, 2009 4:38 PM.

WWDC 2009 Predictions was the previous entry in this blog.

New Font and Slight Layout Tweaks is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Pages

Recent Assets

  • Picture of PRM

Recent Activity

2011-02-17

  • Pierre tweeted, "Service-oriented Architecture (n.): What you do if you have no idea what service is, nor the any notion what software architecture is about."

2010-12-03

  • Pierre tweeted, "Again on the runway waiting for snow-delayed take-off. Quite the lifestyle..."

2010-11-29

  • Pierre tweeted, "The Future(tm): Uploading software releases and submitting policy input to the EU from a plane waiting 1h at the airport for its de-icing ,)"

2010-10-28

  • Pierre tweeted, "Achieved unbelievable win against Siedle, Siemens by connecting front gate intercom to PBX. Sad about the complexity involved though..."

2010-09-20

  • Pierre tweeted, "RT @jwz: Visual Transistor-level Simulation of the 6502 - in Javascript. http://j.mp/bWHK5F"

2010-09-17

  • Pierre tweeted, "Thanks to @mikeysan I'm playing with say -v "Cellos" on my Mac instead of configuring FreeBSD servers... say -v "Cellos" 'Thanks, mikeysan!'"

2010-08-04

  • Pierre tweeted, "Resurrecting my old Apple //e (yet again) lead to switching power-supply debugging (shorted rectifier dual diode) and soldering fun."

2010-07-25

  • Pierre tweeted, "Star Trek/iPad nostalgia/futurology cross-over: Reading the ST:TNG Technical Manual on the iPad, downloaded directly from subspace..."

2010-06-23

2010-06-02

  • Pierre tweeted, "RT @HansHuebner: U.v.d.Leyen als Bundespräsidentin? Ist das Amt nicht schon beschädigt genug?"