Red 红色循环结构何时需要解释

Red 红色循环结构何时需要解释,red,Red,在什么情况下,循环构造需要解释器以红色进行评估?哪些循环构造不需要 更新(2015年4月20日): 下面是我写的一个小程序,向一些学生演示这种语言。其中两个函数“list”和“find”中都有foreach循环。但是foreach循环将不会运行,除非它们被包装在do块中。特别是这个场景引发了最初的问题,因为foreach循环的主体不是间接指定的 型号。红色 Red [ Title: "Model" Author: "Thomas Royko" Version: 0.0.1

在什么情况下,循环构造需要解释器以红色进行评估?哪些循环构造不需要

更新(2015年4月20日):

下面是我写的一个小程序,向一些学生演示这种语言。其中两个函数“list”和“find”中都有foreach循环。但是foreach循环将不会运行,除非它们被包装在do块中。特别是这个场景引发了最初的问题,因为foreach循环的主体不是间接指定的

型号。红色

Red [
    Title: "Model"
    Author: "Thomas Royko"
    Version: 0.0.1
]

entry!: make object! [
    name: ""
    quantity: 0
    notes: ""
    display: does [
        print ["-- " name]
        print ["-- " quantity]
        print ["-- " notes newline]
    ]
]

enter: func [
    entries value
    /local quantity notes
] [
    qt: load ask "Enter quantity: "
    nt: ask "Enter notes: "
    append entries make entry! copy [
        name: value
        quantity: qt
        notes: nt
    ]
    print ""
]

find: func [
    entries value
    /local found entry
] [
    found: false
    do [
        foreach entry entries [
            if entry/name = value [
                entry/display
                found: true
                break
            ]
        ]
    ]
    if not found [
        print ["** No entry with code" value newline]
    ]
]

list: func [
    entries
] [
    do [
        foreach entry entries [
            entry/display
        ]
    ]
]

finish: func [
    entries
] [
    save %inventory.db entries
    quit
]
Red [
    Title: "Console"
    Author: "Thomas Royko"
    Version: 0.0.1
]

#include %Bindings.red
#include %Model.red

entries: either exists? %inventory.db [
    reduce load %inventory.db
] [
    copy []
]

rule: [
    (value: "")
    1 [
        ["e" space copy value to end (enter entries value)] |
        ["f" space copy value to end (find entries value)] |
        ["l" to end (list entries)] |
        ["q" to end (finish entries)] |
        [(print ["** Code not recognized" newline])]
    ]
]

forever [
    parse ask "Command: " rule
]
控制台。红色

Red [
    Title: "Model"
    Author: "Thomas Royko"
    Version: 0.0.1
]

entry!: make object! [
    name: ""
    quantity: 0
    notes: ""
    display: does [
        print ["-- " name]
        print ["-- " quantity]
        print ["-- " notes newline]
    ]
]

enter: func [
    entries value
    /local quantity notes
] [
    qt: load ask "Enter quantity: "
    nt: ask "Enter notes: "
    append entries make entry! copy [
        name: value
        quantity: qt
        notes: nt
    ]
    print ""
]

find: func [
    entries value
    /local found entry
] [
    found: false
    do [
        foreach entry entries [
            if entry/name = value [
                entry/display
                found: true
                break
            ]
        ]
    ]
    if not found [
        print ["** No entry with code" value newline]
    ]
]

list: func [
    entries
] [
    do [
        foreach entry entries [
            entry/display
        ]
    ]
]

finish: func [
    entries
] [
    save %inventory.db entries
    quit
]
Red [
    Title: "Console"
    Author: "Thomas Royko"
    Version: 0.0.1
]

#include %Bindings.red
#include %Model.red

entries: either exists? %inventory.db [
    reduce load %inventory.db
] [
    copy []
]

rule: [
    (value: "")
    1 [
        ["e" space copy value to end (enter entries value)] |
        ["f" space copy value to end (find entries value)] |
        ["l" to end (list entries)] |
        ["q" to end (finish entries)] |
        [(print ["** Code not recognized" newline])]
    ]
]

forever [
    parse ask "Command: " rule
]

它不依赖于循环构造,而是取决于指定循环体块和(应用时)条件块的方式。如果这些块不是直接指定的,而是使用单词间接指定的,那么它将被解释,因为编译器无法静态地确定它们。例如:

n: 3 until [print n n = 0]
是可编译的,而:

body: [print n n = 0]
n: 3 until body
事实并非如此