Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » system facilities » autoload
next | previous | forward | backward | up | index | toc

# autoload -- arrange for a function to be loaded automatically

- Usage:
    `autoload(f,x)`
- Inputs:
  - f
  - x
- Consequences:
  - arranges for a function named f to be automatically loaded from the file x the first time it is used. This is accomplished by creating a suitable function that will load the file and assigning the function to f.

## Description

    i1 : fn = temporaryFileName()

    o1 = /tmp/M2-3102637-0/0

    i2 : fn << "f = x -> x+1\n" << close

    o2 = /tmp/M2-3102637-0/0

    o2 : File

    i3 : autoload(f,fn)

    i4 : code f

    o4 = /usr/share/Macaulay2/Core/autoload.m2:8:19-12:22: --source code:
              sym <- f := x -> (
                   load filename;
                   if f === value sym
                   then error("symbol '", toString sym, "' didn't acquire a new value in file '", filename, "'");
                   (value sym) x
                   );
              )
         | symbol    class            value                                                    location of symbol
         | ------    -----            -----                                                    ------------------
         | f         FunctionClosure  -*Function[/usr/share/Macaulay2/Core/autoload.m2:8:19-.  /usr/share/Macaulay2/Core/autoload.m2:8:12-8:13
         | sym       Symbol           f                                                        /usr/share/Macaulay2/Core/autoload.m2:6:28-6:31
         | filename  String           "/tmp/M2-3102637-0/0"                                    /usr/share/Macaulay2/Core/autoload.m2:6:32-6:40

    i5 : f 4

    o5 = 5

    i6 : removeFile fn

## Ways to use autoload:

- `autoload(Symbol,String)`

## For the programmer

The object autoload is a method function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Macaulay2Doc/ov_system.m2:138:0.