Next: , Previous: , Up: Iteration Control   [Contents][Index]


15.25.6.8 ’for-as-package’

This is the last of seven ‘for/as’ syntaxes.

for var [type-spec] being {each | the}
    {symbol | present-symbol | external-symbol |
     symbols | present-symbols | external-symbols}
    {in | of} package
as var [type-spec] being {each | the}
    {symbol | present-symbol | external-symbol |
     symbols | present-symbols | external-symbols}
    {in | of} package

This construct iterates over the symbols in a package. The variable var takes on the value of each symbol in the specified package. Iteration stops when there are no more symbols to be referenced in the specified package.

The following loop keywords serve as valid prepositions within this syntax.

being

marks the loop method to be used:

  • symbol’,
  • present-symbol’, or
  • external-symbol’.
each’, ‘the

For purposes of readability, the loop keyword ‘each’ should follow the loop keyword ‘being’ when ‘symbol’, ‘present-symbol’, or ‘external-symbol’ is used.

The loop keyword ‘the’ is used with ‘symbols’, ‘present-symbols’, and ‘external-symbols’.

present-symbol’, ‘present-symbols

These loop methods iterate over the symbols that are present but not external in a package. The package to be iterated over is specified in the same way that package arguments to the Common Lisp function find-package are specified. If you do not specify the package for the iteration, the current package is used. If you specify a package that does not exist, an error is signaled.

symbol’, ‘symbols

These loop methods iterate over symbols that are accessible from a given package. The package to be iterated over is specified in the same way that package arguments to the Common Lisp function find-package are specified. If you do not specify the package for the iteration, the current package is used. If you specify a package that does not exist, an error is signaled.

external-symbol’, ‘external-symbol

These loop methods iterate over the external symbols of a package. The package to be iterated over is specified in the same way that package arguments to the Common Lisp function find-package are specified. If you do not specify the package for the iteration, the current package is used. If you specify a package that does not exist, an error is signaled.

in’, ‘of

These loop prepositions mark the package package.

(loop for x being each present-symbol of "COMMON-LISP-USER"
      do (print x)) ;Prints 7 lines in this example

Next: ’repeat’, Previous: ’for-as-hash’, Up: Iteration Control   [Contents][Index]