Stepping through code?

Discussion of Common Lisp
ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Stepping through code?

Post by ramarren » Sat Feb 27, 2010 10:42 am

speech impediment wrote:Well, I was learning about order of evaluation; Normal order vs. Applicative order.
Common Lisp has strict, left to right order of evaluation of arguments, that is, applicative order. All major Lisps have strict evalution, although I believe Scheme does not specify the order in which arguments are processed.
speech impediment wrote:Forgive my ignorance again, but I can't seem to find type dispatch in the hyperspec. What is that?
I meant dynamic dispatch on type of arguments. Since addition function, like all arithmetic functions, in Common Lisp works on many numeric types (fixnums, bignums, floats, ratios, complex numbers and so on) the system must determine which primitive addition operation to execute promoting the arguments as necessary. Which means that unless full types can be determined at compile time addition is not a primitive operation. But this is internal to the implementation and something one should worry about unless doing microoptimization, which done prematurely is, of course root of all evil.

speech impediment
Posts: 36
Joined: Mon May 04, 2009 5:19 pm

Re: Stepping through code?

Post by speech impediment » Sat Feb 27, 2010 11:02 am

Ramarren wrote: Common Lisp has strict, left to right order of evaluation of arguments, that is, applicative order. All major Lisps have strict evalution, although I believe Scheme does not specify the order in which arguments are processed.
Hmm... that's odd. I was reading about evaluation order in Structure and Interpretation of Computer Programs and it says:
In section 1.1, where we began our discussion of models of evaluation, we noted that Scheme is an
applicative-order language, namely, that all the arguments to Scheme procedures are evaluated when the
procedure is applied.

(define (try a b)
(if (= a 0) 1 b))

Evaluating (try 0 (/ 1 0)) generates an error in Scheme.
From reading this, it implies that Scheme also have strict evaluation... (At least for the implementation used in the book.)

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Stepping through code?

Post by ramarren » Sat Feb 27, 2010 11:12 am

speech impediment wrote:From reading this, it implies that Scheme also have strict evaluation... (At least for the implementation used in the book.)
It is strict, but it is not applicative, that is, the order is unspecified. See this note. Maybe SICP is using different definition of applicative. It doesn't really matter all that much, side effects buried in function arguments are rarely a good idea, and depending on order of evaluation of those is even worse.

speech impediment
Posts: 36
Joined: Mon May 04, 2009 5:19 pm

Re: Stepping through code?

Post by speech impediment » Sat Feb 27, 2010 12:01 pm

Well, dadgum, you're right. I'm not even going try to find out what definition of "applicative" the book is using. Thanks again Rammaren.

Post Reply