From: Robert Klemme Date: 2004-07-31T19:51:40+09:00 Subject: Re: Forward references? "Lloyd Zusman" schrieb im Newsbeitrag news:1xit1d8o.fsf@asfast.com... > "Robert Klemme" writes: > > > "Lloyd Zusman" schrieb im Newsbeitrag > > news:d62dd0tu.fsf@asfast.com... > >> Is there a way to define forward references to functions? Due to my own > >> personal eccentricities, I like to have the main body of a program > >> appear at the top of its source file, and the functions it uses at the > >> end. > >> > >> [ ... ] > > > > Just define them duplicately, the first time with an empty body: > > > > # "prototypes" > > def foo;end > > def bar(name)end > > > > # main stuff > > x = foo() > > y = bar() > > puts x > > puts y > > exit 0 > > > > # "functions" > > def foo > > # foodoo > > end > > > > def bar(name) > > # bardo > > end > > > > Thank you very much, but this doesn't appear to work. Here's what I > tried: > > def foo;puts "forward ref of foo";end > def bar(arg);puts "forward ref of bar(#{arg})";end > > foo() > bar('abc') > exit(0); > > def foo > puts "foo" > end > > def bar(arg) > puts "bar: #{arg}" > end > > When I ran it, it produced the following output: > > forward ref of foo > forward ref of bar(abc) > > In other words, the second function definitions did not override the > first ones. Indeed. Darn, should've done a real test - and not just a mental test. I'm sorry. I guess the lession to learn here is, just don't do it. Or use comments as prototypes. Regards robert