http:www//maths.tcd.ie/~odunlain/slides/101101/text.html
What does
.
.
.
.
.
.
.
.
.
Contents.
Berry's Paradox
Example Program A
Example Program B
Example Program C
Program to check for loops
Loop program self-applied
Berry's Paradox
Every positive integer can be defined by a sentence in English.
What is the smallest positive integer whose definition requires
more than 13 words of English?
Example Program A
class A
creation
go
feature
go is
local
list : DLIST [ STRING ]
p : DLIST_PLACE [ STRING ]
do
!! list . make
list . add_last ( "1" )
list . add_last ( "/" )
list . add_last ( "0" )
list . add_last ( "1" )
from
p := list . first_place
until
p = Void
loop
list . add_first ( list . item ( p ) )
p := list . succ ( p )
end
io . put_string ( "Finally... " )
from
p := list . first_place
until
p = Void
loop
io . put_string ( list . item ( p ) )
io . put_string ( " " )
p := list . succ ( p )
end
io . put_new_line
end
end -- class A
Example Program B
class B
creation
go
feature
go is
local
list : DLIST [ STRING ]
p : DLIST_PLACE [ STRING ]
do
!! list . make
list . add_last ( "1" )
list . add_last ( "/" )
list . add_last ( "0" )
list . add_last ( "1" )
from
p := list . first_place
until
p = Void
loop
list . add_last ( list . item ( p ) )
p := list . succ ( p )
end
io . put_string ( "Finally... " )
from
p := list . first_place
until
p = Void
loop
io . put_string ( list . item ( p ) )
io . put_string ( " " )
p := list . succ ( p )
end
io . put_new_line
end
end -- class B
Example Program C
The only difference between this and program A is in the
list of strings (or words). The point is that the words themselves
could come from another program.
class C
creation
go
feature
go is
local
list : DLIST [ STRING ]
p : DLIST_PLACE [ STRING ]
do
!! list . make
list . add_last ( "from" )
list . add_last ( "p" )
list . add_last ( ":=" )
list . add_last ( "list" )
list . add_last ( "." )
list . add_last ( "first_place" )
list . add_last ( "until" )
from
p := list . first_place
until
p = Void
........etcetera
end -- class C
Program to check for loops
Consider
sample_program ( data : DLIST [ STRING ] ) is
if 12th string in data is "if" then
halt
otherwise
go into an infinite loop..
loop_check ( program, data : DLIST [ STRING ] ) is
... check to see whether the program
goes into an infinite loop with the
given data
how_about ( program : DLIST [ STRING ] ) is
run loop_check ( program, program )
if loop_check says the program loops,
then halt,
otherwise go into an infinite loop.
how_about ( text of sample_program )
do?
Loop program self-applied
What does
how_about ( text of how_about )
do?
how_about ( program : DLIST [ STRING ] ) is
run loop_check ( program, program )
if result says `loops,' then halt,
otherwise go into an infinite loop.