red / REP

Red Enhancement Process
BSD 3-Clause "New" or "Revised" License
11 stars 4 forks source link

WISH: ability to prematurely stop foreach-face #78

Closed hiiamboris closed 4 years ago

hiiamboris commented 4 years ago

it does not react to break/return or return and continues to process the whole tree

greggirwin commented 4 years ago

This seems to work for me:

view [
    text "A"
    text "B"
    button "C1" [foreach-face face/parent [print face/text break]]
    button "C2" [foreach-face face/parent [print face/text break/return "break/return"]]
    button "C3" [foreach-face face/parent [print face/text return "return"]]
]
hiiamboris commented 4 years ago

Try this:

v: view/no-wait [
    text "A"
    panel [text "B"] "X"
    panel [text "C"] "Y"
]

foreach-face v [
    print face/text
    if face/text = "B" [print "STOPPING..." break]
]
greggirwin commented 4 years ago
v: view/no-wait [
    text "A"
    text "B"
    button "C1" [foreach-face face/parent [print face/text break]]
    button "C2" [foreach-face face/parent [print face/text break/return "break/return"]]
    button "C3" [foreach-face face/parent [print face/text return "return"]]
]
foreach-face v [
    print face/text
    if face/text = "B" [print "STOPPING..." break]
]

Results in

A
B
STOPPING...
== [make object! [
    type: 'button
    offset: 190x9
    size: 62x27
    text: "C1"
    image: none
    color: none
    m...

But

v: view/no-wait [
    text "A"
    panel [text "B"] "X"
    button "C1" [foreach-face face/parent [print face/text break]]
    button "C2" [foreach-face face/parent [print face/text break/return "break/return"]]
    button "C3" [foreach-face face/parent [print face/text return "return"]]
]
foreach-face v [
    print face/text
    if face/text = "B" [print "STOPPING..." break]
]

Results in

A
X
B
STOPPING...
C1
C2
C3
== []

Panel handling (/sub) appears to be the culprit.

hiiamboris commented 4 years ago

Should I repost this to https://github.com/red/red/issues/ ?

greggirwin commented 4 years ago

I think so. It's a good subject for an article, as well as figuring out how best to design things (including HOF-esque stuff like this), without making it an advanced topic that only a non-local-flow-control continuation-passing mother could love.

hiiamboris commented 4 years ago

There's a solution