Pragmas

# Peter Hall (18 years ago)

What is the scope of a pragma such as that? Is it just the current lexical scope, like a "use namespace" statement, or does it change the behaviour for the entire program? If it's the latter, isn't there a compatibility problem between libraries? If it's the former, do you anticipate that es4 programs will be littered with "use strict" pragmas? Think Fortran and "implicit none"....

I assume this has been previously discussed, but I couldn't find it, so apologies if that is the case.

Peter

# Lars T Hansen (18 years ago)

Pragmas are invariably lexically scoped.

Some pragmas are probably more useful at the top level, "use strict" is among these. One pattern we think might develop is "use strict" at the top level, followed by "use standard" inside some blocks where strict mode gets in the way (if only temporarily during program development).

# Peter Hall (18 years ago)

Also, there is a minor bug [1] with the pragma syntax:

Pragma : UsePragma SemicolonFull ImportPragma SemicolonFull

UsePragma : use PragmaItems SemicolonFull

resulting in two semicolons being required after a "use" pragma.

Peter

[1] proposals:syntax_for_pragmas

# Jeff Dyer (18 years ago)

Got it.

# Peter Hall (18 years ago)

On the surface, that sounds like it makes sense. But if I'm writing an application in strict mode, that uses a pre-existing library, will I have to edit that library to add "use standard" to every file?

"Inheriting" the pragma is not straightforward unless you inherit only from the program entry point. After that, it doesn't seem possible to derive a well-defined ancestry tree, since source code may be referenced from many different locations, often cyclically.

Peter