Search code examples
schemesicp

What is the name of the "=>" keyword in Scheme?


Excercise 4.5 of Structure and Interpetation of Computer Programs (SICP) introduces an alternative cond clause syntax of the form (<test> => <recipient>), e.g.:

(cond ((assoc 'b '((a 1) (b 2))) => cadr)
      (else false))

Is there a name for this keyword or for this alternate form of the cond clause?

A procedure to test for the presence of this keyword could be of the form (=>? <exp>) but I might prefer a more expressive name. Even if use the name =>? is there a recognised way to pronounce this, e.g., "is double arrow", "is altnernative cond clause", "is calling cond"?

I have scanned a couple of r*rs specs but I couldn't see the keyword referred to by a name.


Solution

  • Scheme supports an alternative clause syntax:

    (predicate => recipient)

    where recipient is an expression. If predicate evaluates to a true value, then recipient is evaluated. Its value must be a procedure of one argument; this procedure is then invoked on the value of the predicate.

    So you read it like in logic "If predicate then recipient". With the constraint that recipient is a function of 1 argument.

    UPDATE:

    I checked the mailing lists of scheme and I have never seens this syntactic sugar, which means, it is a recent addition to the syntax.