This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home.
Source for ticket #382
cc
changetime
2012-10-12 03:07:14
component
WG1 - Core
description
Submitter's name: John Boyle
Submitter's email: johnthescavenger at gmail.com
Relevant draft: r7rs-small-current
Type: enhancement
Priority: major
Relevant section of draft: Conditionals
Summary: Allow `if` to accept arbitrarily many if-then pairs.
Description:
The conditional operator `if` should be made to accept arbitrarily many
if-then pairs, so that:
{{{
(if (blip)
(blop)
(flip)
(flop)
(floop))
}}}
is equivalent to:
{{{
(cond ((blip)
(blop))
((flip)
(flop))
(else (floop)))
}}}
This is more terse and provides for a better user experience. (In the case of 3 arguments, one who writes `if` and later discovers that he needs to add more cases must either write nested `if`s or go back and rewrite the whole expression with `cond`; either choice is unpleasant. For precisely this reason, there are people who preempt it by always using `cond` over `if` in the first place; these people pay a cost in extra parentheses, letters typed, and indentation.)
I anticipate reluctance to alter the syntax of a primitive operator. But this change is entirely backwards compatible with code that uses the previous `if`, and skeptical people are free to continue only writing `if`s with three arguments and using `cond` otherwise. The only thing they will lose is error-checking if they accidentally give four or more arguments to `if`. I point out that the same objection could be made to `map`, `+`, `-`, `*`, /, and other functions. I add that the Arc language has used this form of `if` without any `cond` at all, and I didn't find anyone complaining in any of 14,000 posts on the Arc Forum that they wanted `cond` back.
Here is an example implementation in terms of `cond`. (I see no reason not to allow ''zero'' or more arguments, rather than two or more, but I expect that is pushing it.)
{{{
(define-syntax my-if
(syntax-rules ()
((my-if a b c ...) ;at least two arguments
(expand-if a b c ...))))
(define-syntax expand-if
(syntax-rules ()
((expand-if) (cond (#f #f))) ;the unspecified fall-through result
((expand-if x) x)
((expand-if a b rest ...)
(cond (a b)
(else (expand-if rest ...))))))
}}}
This suggestion comes from the Arc language. Further discussion may be found [http://ycombinator.com/arc/tut.txt here], near the phrases "An if" and "cond operator":
id
382
keywords
milestone
owner
cowan
priority
major
reporter
cowan
resolution
wontfix
severity
status
closed
summary
Formal Comment: Allow "if" to accept arbitrarily many if-then pairs
time
2012-04-23 06:52:13
type
defect
Changes
Change at time 2012-10-12 03:07:14
author
cowan
field
comment
newvalue
oldvalue
2
raw-time
1349986034491786
ticket
382
time
2012-10-12 03:07:14
Change at time 2012-10-12 03:07:14
author
cowan
field
resolution
newvalue
wontfix
oldvalue
raw-time
1349986034491786
ticket
382
time
2012-10-12 03:07:14
Change at time 2012-10-12 03:07:14
author
cowan
field
status
newvalue
closed
oldvalue
accepted
raw-time
1349986034491786
ticket
382
time
2012-10-12 03:07:14
Change at time 2012-04-23 06:52:26
author
cowan
field
comment
newvalue
oldvalue
1
raw-time
1335138746863366
ticket
382
time
2012-04-23 06:52:26
Change at time 2012-04-23 06:52:26
author
cowan
field
owner
newvalue
cowan
oldvalue
alexshinn
raw-time
1335138746863366
ticket
382
time
2012-04-23 06:52:26
Change at time 2012-04-23 06:52:26
author
cowan
field
status
newvalue
accepted
oldvalue
new
raw-time
1335138746863366
ticket
382
time
2012-04-23 06:52:26