manpagez: man pages & more
info gawk
Home | html | info | man

File: gawk.info,  Node: Naming Rules,  Next: Internal Name Management,  Prev: Changing The Namespace,  Up: Namespaces

15.5 Namespace and Component Naming Rules
=========================================

A number of rules apply to the namespace and component names, as
follows.

   * It is a syntax error to use qualified names for function parameter
     names.

   * It is a syntax error to use any standard 'awk' reserved word (such
     as 'if' or 'for'), or the name of any standard built-in function
     (such as 'sin()' or 'gsub()') as either part of a qualified name.
     Thus, the following produces a syntax error:

          @namespace "example"

          function gsub(str, pat, result) { ... }

   * Outside the 'awk' namespace, the names of the additional 'gawk'
     built-in functions (such as 'gensub()' or 'strftime()') _may_ be
     used as component names.  The same set of names may be used as
     namespace names, although this has the potential to be confusing.

   * The additional 'gawk' built-in functions may still be called from
     outside the 'awk' namespace by qualifying them.  For example,
     'awk::systime()'.  Here is a somewhat silly example demonstrating
     this rule and the previous one:

          BEGIN {
              print "in awk namespace, systime() =", systime()
          }

          @namespace "testing"

          function systime()
          {
              print "in testing namespace, systime() =", awk::systime()
          }

          BEGIN {
              systime()
          }


     When run, it produces output like this:

          $ gawk -f systime.awk
          -| in awk namespace, systime() = 1500488503
          -| in testing namespace, systime() = 1500488503

   * 'gawk' pre-defined variable names may be used: 'NF::NR' is valid,
     if possibly not all that useful.

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.