## 6.9 Unit: eval

This unit has support for evaluation and macro-handling. This unit is used by default, unless the program is compiled with the `-explicit-use` option.

### 6.9.1 Loading code

[procedure] (load FILE [EVALPROC])
  Loads and evaluates expressions from the given source file, which may be either a string or an input port. Each expression read is passed to `EVALPROC` (which defaults to `eval`). On platforms that support it (currently Linux ELF and Solaris), `load` can be used to load compiled programs:

      % cat x.scm
      (define (hello) (print "Hello!"))
      % chicken x.scm -quiet
      % gcc x.c -shared -fPIC `chicken-config -cflags -shared -libs` -o x.so
      % csi -quiet
      >>> (load "x.so")
      ; loading x.so ...
      >>> (hello)
      Hello!
      >>>

  The second argument to `load` is ignored when loading compiled code. The same compiled object file can not be loading more than once. If source code is loaded from a port, then that port is closed after all expressions have been read.

[procedure] (visit FILENAME)
  Reads the source file `FILENAME`, but performs only macro-expansion. This is mainly useful to make the macro-/syntax-, constant- and inline-function -definitions in `FILENAME` available.

[procedure] (load-library UNIT [LIBRARYFILE])
  On platforms that support dynamic loading, `load-library` loads the compiled library unit `UNIT` (which should be a symbol). If the string `LIBRARYFILE` is given, then the given shared library will be loaded and the toplevel code of the contained unit will be executed. If no `LIBRARYFILE` argument is given, then the following libraries are checked for the required unit:

  - a file named ```<UNIT>.so`''

  - the files given in the parameter `dynamic-load-libraries`.

  If the unit is not found, an error is signaled. When the library unit can be successfully loaded, a feature-identifier named `UNIT` is registered. If the feature is already registered before loading, the `load-library` does nothing.

[procedure] (load-noisily FILE [EVALPROC])
  As `load` but the result(s) of each evaluated toplevel-expression is written to standard output.

[procedure] (load-srfi-7-program FILE [EVALPROC])
  Loads and evaluates expressions that are specified as a SRFI-7 configuration language program.

[procedure] (require UNIT [LIBRARYFILE])
  Similar to `load-library`, but when the loading fails (either because dynamic loading is not supported, or when the library-unit is not available), then an attempt is made to load the file `UNIT.so` or `UNIT.scm` (int that order) from the current include path, wich defaults to the pathnames given in `CHICKEN_INCLUDE_PATH` and `CHICKEN_HOME`. `UNIT` may be a symbol, a string or a list of symbols or strings.

### 6.9.2 Read-eval-print loop

[procedure] (read-eval-print-loop)
  Start a new read-eval-print loop. Sets the `reset-handler` so that any invocation of `reset` restarts the read-eval-print loop. Also changes the current `error-handler` to display a message, write any arguments to the value of `(current-error-port)` and reset.

### 6.9.3 Macros

[procedure] (get-line-number EXPR)
  If `EXPR` is a pair with the car being a symbol, and line-number information is available for this expression, then this procedure returns the associated line number. If line-number information is not available, then `#f` is returned. Note that line-number information for expressions is only available in the compiler.

[procedure] (macro? SYMBOL)
  Returns `#t` if there exists a macro-definition for `SYMBOL`.

[procedure] (macroexpand X)
  If `X` is a macro-form, expand the macro (and repeat expansion until expression is a non-macro form). Returns the resulting expression.

[procedure] (macroexpand-1 X)
  If `X` is a macro-form, expand the macro. Returns the resulting expression.

[procedure] (undefine-macro! SYMBOL)
  Remove the current macro-definition of the macro named `SYMBOL`.

### 6.9.4 Extensions

This functionality is only available on platforms that support dynamic loading of compiled code. Currently Linux, FreeBSD, Solaris, Windows (Cygwin) and HP/UX are supported.

Note: You have to set up the extension-registry before you can use this stuff. The easiest way is to create a directory called `.chicken-registry` in your `$HOME` directory and run `csi -setup`:

    % cd $HOME
    % mkdir .chicken-registry
    % csi -setup

[procedure] (package ID)
  Sets the current package prefix to `ID`. All references to extension IDs (as in `provide, provided?` and `require`) are relative to this prefix.

  So

      (package 'foo)
      (require 'bar)

  is identical to

      (require '(foo bar))

[procedure] (provide ID ...)
  Registers the extension IDs `ID ...` as loaded. This is mainly intended to provide aliases for certain extension identifiers.

[procedure] (provided? ID ...)
  Returns `#t` if the extension with the IDs `ID `...`` are currently loaded, or `#f` otherwise. Works also for feature-ids.

[procedure] (require ID ...)
  If the extension library `ID` is not already loaded into the system, then `require` will lookup the location of the shared extension libary and load it. If `ID` names a library-unit of the base system, then it is loaded via `load-library`. If no extension library is available for the given ID, then an attempt is made to load the file `ID.so` or `ID.scm` (int that order) from one of the following locations:

  1. the current directory

  2. the current include path, which defaults to the pathnames given in `CHICKEN_INCLUDE_PATH` and `CHICKEN_HOME`.

  `ID` may be a symbol, or a list of symbols. See also: `require-for-syntax`

### 6.9.5 Miscellaneous

[procedure] (define-reader-ctor SYMBOL PROC)
  Define new read-time constructor for `#,` read syntax. For further information, see the documentation for SRFI-10 14.

[procedure] (eval EXP [ENVIRONMENT])
  Evaluates `EXP` and returns the result of the evaluation. The second argument is optional and defaults to the value of `(interaction-environment)`.

14 http://srfi.schemers.org/srfi-10/srfi-10.html