1

In scheme when defined

(define f (lambda (a b c d) d))

(define l (list 'a 'b 'c 'd))

Why it does not do argument destructuring? I mean arguments should evaluate first, why destructuring is not part of that?

(f . l)

What are reasons that this expression is not equal with following?

(apply f l)
  • Edited to make it clearer, according suggestions in comments
  • 3
    Are you asking why scheme doesn't do argument destructuring, or why it doesn't allow the syntax which looks like a dotted pair to apply functions? – Alan Shutko Sep 3 '14 at 18:01
  • Why it does not do argument destructuring? I mean arguments should evaluate first, why destructuring is not part of that? Sorry for ambiguity. – stralep Sep 3 '14 at 18:10
  • 1
    You should edit the question to make it more clear rather than reply to the comment – Daenyth Sep 3 '14 at 19:12
5

The main reason is, (f . l) can only work if l is an identifier (or some other atomic literal), and not if it's a more complicated expression. Consider a function for calculating the sum-of-squares:

(define (sum-of-squares . nums)
  (apply + (map square nums)))

Here, you cannot rewrite the (apply + (map square nums)) into (+ . (map square nums)), because that is equivalent (at read-time, way before evaluation happens) to (+ map square nums). And map, square, and nums are not numbers. ;-)

Therefore, implementations have to supply an apply procedure. And once you do, there's no real point to supporting a dotted procedure-application expression that only works some of the time, when apply works correctly all the time.

(Many thanks to Brian Mastenbrook for explaining this to me years ago, back when I had a similar question myself.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.