Skip to content

Version 6.2: FOREACH doesn't handle STOP #226

@PammyBA

Description

@PammyBA

Here's a short example:

Welcome to Berkeley Logo version 6.2
loading startup file
? foreach [a b 7 c] [if numberp ? [stop] print ?]
foreach defined
foreach1 defined
foreach.done defined
?rest defined
a
b
c
? 

This should not print 'c', it should cause an error because stop is used outside of a procedure.

It also prevents Dr. Harvey's MULTIFOR from running properly (it enters an infinite loop). See the comments in multiforloop.

to multifor :values.list :instr
localmake "vars firsts :values.list
local :vars
localmake "initials map "run firsts butfirsts :values.list
localmake "finals map [run item 3 ?] :values.list
localmake "steps (map "multiforstep :values.list :initials :finals)
localmake "testers map [ifelse ? < 0 [[?1 < ?2]] [[?1 > ?2]]] :steps
multiforloop :initials
end

to multiforstep :values :initial :final
if (count :values)=4 [output run last :values]
if :initial > :final [output -1]
output 1
end

to multiforloop :values
local "foo
make "foo "false
(foreach :vars :values [make ?1 ?2])
;(foreach :values :finals :testers [if run ?3 [print "stop]])
;-- Changes to work around FOREACH STOP bug
(foreach :values :finals :testers [if run ?3 [make "foo "true]])
if :foo [stop]
;-- End Changes
run :instr
multiforloop (map [?1+?2] :values :steps)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions