1. chibi-config
    1. Background
    2. Syntax
    3. Module: (chibi config)
      1. conf?
      2. assoc-get
      3. assoc-get-list
      4. conf-head
      5. conf-load
      6. conf-load-in-path
      7. conf-load-cascaded
      8. conf-get
      9. conf-get-list
      10. conf-get-cdr
      11. conf-get-multi
      12. conf-extend
      13. conf-append
      14. conf-unfold-key
      15. conf-set
      16. conf-specialize
      17. conf-verify
    4. Maintainer
    5. Author
    6. Version History
    7. License

chibi-config

Chibi Scheme's config library

This is a library for unified configuration management. Essentially it provides an abstract collection data type for looking up named values, two or more of which can be chained together. Values from more recent collections can be preferred as with an environment, or the values at multiple levels can be flattened together. Convenience routines are provided from loading these collections from files while allowing extensions such as configurations from command-line options.

Background

As any application grows to sufficient complexity, it acquires options and behaviors that one may want to modify at startup or runtime. The traditional approach is a combination of command-line options, config files, environment variables, and/or other specialized settings. These all have various pros and cons:

name pros cons
environment variables implicit - no need to retype; can share between applications unclear when set; unexpected differences between users; limited size
command-line options explicit - visible each tie a command is run verbose; limited size
config files implicit; preserved - can be shared and version controlled requires a parser

Environment variables are convenient for broad preferences, used by many different applications, and unlikely to change per user. Command-line options are best for settings that are likely to change between invocations of a program. Anything else is best stored in a config file. If there are settings that multiple users of a group or whole system are likely to want to share, then it makes sense to cascade multiple config files.

Syntax

With any other language there is a question of config file syntax,and a few popular choices exist such as .ini syntax. With Scheme the obvious choice is sexps, generally as an alist. We use a single alist for the whole file, with symbols for keys and arbitrary sexps for values. The alists are intended primarily for editing by hand and need not be dotted, but the interface allows dotted values. Disambiguation is handled as with two separate functions,(conf-get config key) and (conf-get-list config key),which both retrieve the value associated with key from config, in the latter case coercing to a list. The result is determined according to the structure of the alist cell as follows:

Cell conf-get result conf-get-list result
key () ()
(key . non-list-value) non-list-value (non-list-value)
(key non-list-value) non-list-value (non-list-value)
key (value1 value2 ...) (value1 value2 ...) (value1 value2 ...)
key value1 value2 ... (value1 value2 ...) (value1 value2 ...)

Thus writing the non-dotted value will always do what you want. Specifically, the only thing to be careful of is if you want a single-element list value, even with conf-get, you should write (key (value)).

Module: (chibi config)

conf?

[procedure] (conf? config)

Returns true iff x is a config object.

assoc-get

[procedure] (assoc-get alist key #!optional (equal equal?) default)

Utility analogous to conf-get on a pure alist. Returns the value of the cell in alist whose car is equal? to key, where the value is determined as the cadr if the cell is a proper list of two elements and the cdr otherwise. If no cell is found, returns default, or #f if unspecified.

assoc-get-list

[procedure] (assoc-get-list alist key #!optional (default (quote ())))

Equivalent to assoc-get but coerces its result to a list as described in the syntax section.

conf-head

[procedure] (conf-head config)

Returns just the base of config without any parent.

conf-load

[procedure] (conf-load file #!optional conf)

Loads the config file file, prepending to conf if provided.

conf-load-in-path

[procedure] (conf-load-in-path config-path file)

Search for and load any files named file in the config-path, which should be a list of strings.

conf-load-cascaded

[procedure] (conf-load-cascaded config-path file #!optional (include-keyword (quote include)) depth)

Similar to conf-load-in-path, but also recursively loads any "include" config files, indicated by a top-level include-keyword with either a string or symbol value. Includes are loaded relative to the current file, and cycles automatically ignored.

conf-get

[procedure] (conf-get config key #!optional default)

Basic config lookup - retrieves the value from config associated with key. If not present, return default. In conf-get and related accessors key can be either a symbol, or a list of symbols. In the latter case, each symbol is used as a key in turn, with the value taken as an alist to further lookup values in.

conf-get-list

[procedure] (conf-get-list config key #!optional (default (quote ())))

Equivalent to conf-get but coerces its result to a list as described in the syntax section.

conf-get-cdr

[procedure] (conf-get-cdr config key #!optional default)

Equivalent to conf-get but always returns the cdr as-is without possibly taking its car.

conf-get-multi

[procedure] (conf-get-multi config key)

Equivalent to conf-get-list but returns a list of all cascaded configs appended together.

conf-extend

[procedure] (conf-extend config alist #!optional source)

Extends the config with an additional alist.

conf-append

[procedure] (conf-append a b)

Joins two configs.

conf-unfold-key

[procedure] (conf-unfold-key key value)

Utility to create an alist cell representing the chained key key mapped to value.

conf-set

[procedure] (conf-set config key value)

Replace a new definition into the first config alist.

conf-specialize

[procedure] (conf-specialize config key name)

Lift specialized sections to the top-level of a config.

conf-verify

[procedure] (conf-verify spec config #!optional warn)

Verify that config conforms to spec. warn is the (optional) procedure used to report bad config entries.

Maintainer

Diego A. Mundo

Author

Alex Shinn

Version History

0.1.0

License

BSD

Copyright (c) 2009-2021 Alex Shinn 
All rights reserved. 
 
Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions 
are met: 
1. Redistributions of source code must retain the above copyright 
   notice, this list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright 
   notice, this list of conditions and the following disclaimer in the 
   documentation and/or other materials provided with the distribution. 
3. The name of the author may not be used to endorse or promote products 
   derived from this software without specific prior written permission. 
 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.