Re: Forward reference to included function

new topic     » goto parent     » topic index » view thread      » older message » newer message

Traditional documentation uses defined or declared when describing scope.

For a variable you define atom x = 1, and thereafter x is "in scope" to the the end of the file; routines used to be the same. However, O[ has a bonus feature for routines; they are "in scope" for the entire file (start to end) even if the routine is defined in the last statement in the file. The advantage is the ability to perform "mutual recursion" where one routine calls another routine; without this bonus feature of full file scope it is like watching a dog chase its tail. (Python is not as friendly as O[ when it comes to mutual recursion.)

I propose a new term: we now say an identifier (variable or routine) is introduced. In a file a definition or declaration introduces a new identifier. The scope rules for a variable are from the point of introduction to the end of a file. The scope rules for a routine are for the entire file where the identifier is introduced. (Sounds much like the existing documentation.)

If we have an include statement, that statement is the point of introduction for identifiers (variables and routines) that are found in the included file. (The identifiers have to be export, public, or global to be visible.)

  • For a variable the scope is from the introduction (the include statement) to the end of the file. The actual definition is hidden in the include file.
  • For a routine the scope is from the introduction (the include statement) for the entire file. The actual definition is hidden in the include file.

The term introduction now explains why:

any_key("\nChoose a key and press it\n")  
include std/console.e  

works in O[:

  • The any_key routine is introduced by the include statement (any_key is actually defined somewhere, hidden, in the include file.)
  • The scope of any_key, as a routine, is for the entire file where there is an introduction.

_tom

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu