Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000314Core InformPhrases and functional programmingpublic2010-09-30 22:512010-10-28 00:30
ReporterRon Newcomb 
Assigned Tograham 
PrioritynormalSeveritymildReproducibilityalways
StatusclosedResolutionfixed 
PlatformPPCOSMac OS XOS Version10.4
Product Version6E72 
Target VersionFixed in Version6F95 
Summary0000314: "let" can be used on Repeat's variable, without Problem message
DescriptionIn the code below, the "let" phrase changes the repeat loop's index value, rather than throwing a Problem message that "x" isn't a previously un-created variable.

Minimal Source Text To Reproduce
When play begins:
	repeat with x running from 1 to 10:
		let x be 1000;
		say "[x]."

Place is room.
Additional Information
I know of the indexed text exception in which Let needs to act on a preexisting variable:

    let X be indexed text;
    let X be "Change me.";

... but surely the Standard Rules needn't allow let to assign *any* "existing variable" to *any* "value". Could it be a bit more discerning?

To let (t - existing variable) be (u - value)
(assignment operation)
(documented at ph_let):
(- {-assignment}; -).
TagsNo tags attached.
Effect(mild) Compiler accepts invalid code
Attached Files

- Relationships

-  Notes
(0000642)
jmcgrew (administrator)
2010-10-01 01:20

"let" is meant to operate on existing variables as well as new ones: see the "A Haughty Spirit" example, for one.

The manual doesn't explicitly say that it's illegal to change a loop variable. However, it does say "[repeat] causes the block of phrases following it to be repeated once for each value in the given range", and the only way to guarantee that is to prevent the loop variable from being changed.
(0000644)
graham (administrator)
2010-10-01 07:36

Ron and Jesse are both right, I think. The language can only be safer if we protect loop invariants. Inform now produces the problem message:

Problem. In 'let x be 1000', it looks as if you want to use 'let' to change the value of the temporary variable 'x'. Ordinarily that would be fine, but it's not allowed when the variable is used as the counter in a 'repeat' loop, or has some other do-not-disturb purpose - this could cause chaotic effects. The rule is: you can only change an existing value with 'let' if it was created by 'let' in the first place.

- Issue History
Date Modified Username Field Change
2010-09-30 22:51 Ron Newcomb New Issue
2010-10-01 01:20 jmcgrew Note Added: 0000642
2010-10-01 01:20 jmcgrew Status new => confirmed
2010-10-01 07:36 graham Note Added: 0000644
2010-10-01 07:36 graham Status confirmed => resolved
2010-10-01 07:36 graham Resolution open => fixed
2010-10-01 07:36 graham Assigned To => graham
2010-10-25 21:14 jmcgrew Fixed in Version => 6F95
2010-10-28 00:30 jmcgrew Status resolved => closed


Copyright © 2000 - 2010 MantisBT Group
Powered by Mantis Bugtracker