chain: locals'
{{
  create locals
    6 allot
  variable #
  : local; ( a- )
    ` ;; ` ;; drop ` [[ &; :devector ;
  : rename ( $- )
    @# locals + @ over getLength 1+ copy ;
  : patch  ( aa$-a )
    drop [ here swap ! ] dip ;
  : next   ( - )
     # ++ ;
---reveal---
  : aaaaaaaaaaaa ( a-a ) dup 00 + .data ; immediate
  : bbbbbbbbbbbb ( a-a ) dup 01 + .data ; immediate
  : cccccccccccc ( a-a ) dup 02 + .data ; immediate
  : dddddddddddd ( a-a ) dup 03 + .data ; immediate
  : eeeeeeeeeeee ( a-a ) dup 04 + .data ; immediate
  : ffffffffffff ( a-a ) dup 05 + .data ; immediate
  &aaaaaaaaaaaa xt->d d->name locals 00 + !
  &bbbbbbbbbbbb xt->d d->name locals 01 + !
  &cccccccccccc xt->d d->name locals 02 + !
  &dddddddddddd xt->d d->name locals 03 + !
  &eeeeeeeeeeee xt->d d->name locals 04 + !
  &ffffffffffff xt->d d->name locals 05 + !
  : locals{ ( "n-a )
    0 !#
    ahead here [ getToken dup "}" compare [ patch 0 ] [ 0 , rename next -1 ] if ] while
    dup .data &local; &; :is @# 1- [ ` !+ ] times ` ! ; immediate
  here ]] locals{ a b c d e f } ; !heap
}}
;chain


doc{
===============
Local Variables
===============

--------
Overview
--------
This vocabulary provides an easy way to give functions access to local variables within
certain limitations.

* Variable names are limited to twelve characters
* Functions using local variables are not reentrant


-------
Example
-------
::

  : foo ( nos tos - result )  locals{ tos nos }  @nos @tos + @nos * ;

Note here that **locals{** will modify the temporary variable names to match the names
you specify.


---------
Functions
---------
+---------+-----------------+----------------------+-------------------------------------+
| Name    | Stack (Runtime) | Stack (Compile-Time) | Usage                               |
+=========+=================+======================+=====================================+
| locals{ | ``-``           | -a                   | Parse for and setup local variables.|
|         |                 |                      | The parsing ends when **}** is      |
|         |                 |                      | found. Local variables are created  |
|         |                 |                      | and initialized in reverse order of |
|         |                 |                      | stack comments.                     |
+---------+-----------------+----------------------+-------------------------------------+
| a       | -a              | a-a                  | First local variable                |
+---------+-----------------+----------------------+-------------------------------------+
| b       | -a              | a-a                  | Second local variable               |
+---------+-----------------+----------------------+-------------------------------------+
| c       | -a              | a-a                  | Third local variable                |
+---------+-----------------+----------------------+-------------------------------------+
| d       | -a              | a-a                  | Fourth local variable               |
+---------+-----------------+----------------------+-------------------------------------+
| e       | -a              | a-a                  | Fifth local variable                |
+---------+-----------------+----------------------+-------------------------------------+
| f       | -a              | a-a                  | Sixth local variable                |
+---------+-----------------+----------------------+-------------------------------------+

The initial variable names will be replaced by **locals{** each time it is used.
}doc
