REBOL3 tracker
  0.9.12 beta
Ticket #0001751 User: anonymous

Project:



rss
TypeIssue Statusreviewed Date8-Nov-2010 11:50
Versionalpha 110 CategoryNative Submitted byLadislav
PlatformAll Severityminor Prioritynormal

Summary FOREACH and its WORD argument
Description If the WORD argument of the FOREACH function is a block containing only set-words, FOREACH becomes an infinite loop.

While it is usually trivial to not supply an "only set words" block as the WORD argument, sometimes the caller does not know what the contents of the WORD block are. In such a case it would be preferable if the loop did not become infinite.

The example below illustrates such a case.
Example code
use: func [
    "Defines words local to a block."
    vars [block! word!] "Local word(s) to the block"
    body [block!] "Block to evaluate"
] [
    do foreach (vars) reduce [none] reduce [body]
]

Assigned ton/a Fixed in- Last Update7-Mar-2015 02:22


Comments
(0003226)
BrianH
19-Feb-2012 19:33

FOREACH with just a set-word can be used for interesting tricks, but those are not very common, and WHILE does a better job of doing those same tricks. We changed PARSE's ANY and SOME to require forward motion, so it would be consistent to require FOREACH's word block to include at least one word! in it.
(0004563)
szeng
27-Jan-2015 22:50

Fixed by: https://github.com/zsx/r3/commit/63115b1f6260b91b053737e698ff3b8c028b2980
(0004601)
szeng
7-Mar-2015 01:54

The above "fix" changes the semantics and breaks the code in r3-gui.r3:

unless foreach [here: hand] sys-hand [
if handler/priority > hand/priority [
insert here handler
break/return true
]
] [
append sys-hand handler
]
(0004602)
szeng
7-Mar-2015 02:22

Another try:

https://github.com/zsx/r3/commit/d4b51635983cb093774b7212c76671aaf3616f82

Date User Field Action Change
7-Mar-2015 02:22 szeng Comment : 0004602 Added -
7-Mar-2015 01:54 szeng Comment : 0004601 Modified -
7-Mar-2015 01:54 szeng Comment : 0004601 Added -
27-Jan-2015 22:50 szeng Comment : 0004563 Added -
19-Feb-2012 23:35 Ladislav Summary Modified FOREACH, and its WORD argument => FOREACH and its WORD argument
19-Feb-2012 23:35 Ladislav Description Modified -
19-Feb-2012 19:34 BrianH Category Modified Unspecified => Native
19-Feb-2012 19:33 BrianH Comment : 0003226 Added -
12-Nov-2010 05:26 carl Description Modified -
12-Nov-2010 05:26 carl Code Modified -
12-Nov-2010 05:26 carl Status Modified submitted => reviewed
8-Nov-2010 11:50 Ladislav Ticket Added -