4.15. kink/MOD

Mod to operate modules.

4.15.1. MOD.require(Mod_name ...[$config={}])

`require` produces the mod specified by `Mod_name`, initializing the mod if it is the first attempt for the mod.

Preconditions

• `Mod_name` must be a str

• $config, if given, must be a fun which takes a require_config val.

Result of `require`

• If the mod is successfully loaded, the success cont is tail-called with the mod. Subsequent attempts of `require` provide the same mod for the same mod name.

• If the mod is not found, the not found cont is tail-called with no args.

• If the program of the mod contains a compile error, the compile error cont is tail-called with (Msg, From_loc, To_loc) where `Msg` is the error message of the compile error, `From_loc` is the location of the beginning of the compile error, and `To_loc` is the location of the end of the compile error.

• If an exception is thrown while initializing the mod, the exception is propagated to the caller of `require`.

Examples

:MOD.require_from('kink/')

:FLAT_SET <- MOD.require('kink/container/FLAT_SET')
stdout.print_line(FLAT_SET.of('foo' 'bar' 'baz').repr) # => (flat_set "bar" "baz" "foo")

MOD.require('no/such/MOD'){(:C)
  C.on_not_found{ stdout.print_line('no such mod') }
} # => no such mod

If no conf option is needed, it is handier to use Varref.require_from.

:FLAT_SET.require_from('kink/container/')
stdout.print_line(FLAT_SET.of('foo' 'bar' 'baz').repr) # => (flat_set "bar" "baz" "foo")

4.15.2. type require_config

Conf val of MOD.require.

4.15.2.1. C.on_success($success_cont)

`on_success` specifies $success_cont as the success cont of `require`. If `on_success` is not called, VAL$identity is used as the default success cont.

Precondition:

• $success_cont must be a fun which takes the loaded mod.

4.15.2.2. C.on_not_found($not_found_cont)

`on_not_found` specifies $not_found_cont as the not found cont of `require`. If `on_not_found` is not called, a thunk which raises an exception is used as the default not found count.

Precondition:

• $not_found_cont must be a thunk.

4.15.2.3. C.on_compile_error($compile_error_cont)

`on_compile_error` specifies $compile_error_cont as the compile error cont of `require`. If `on_compile_error` is not called, a fun which raises an exception is used as the default compile error cont.

Precondition:

• $compile_error_cont must be a fun which takes (Msg, From_loc, To_loc), where `Msg` is the compile error message str, `From_loc` is the location of the beginning of the compile error, and `To_loc` is the location of the end of the compile error.

4.15.3. MOD.add_path(Path)

`add_path` inserts `Path` to the mod paths as the last path.

Precondition:

• `Path` must be a str