Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
[[toc:]] == 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: <table> <tr><th>name</th><th>pros</th><th>cons</th></tr> <tr><td>environment variables</td><td>implicit - no need to retype; can share between applications</td><td>unclear when set; unexpected differences between users; limited size</td></tr> <tr><td>command-line options</td><td>explicit - visible each tie a command is run</td><td>verbose; limited size</td></tr> <tr><td>config files</td><td>implicit; preserved - can be shared and version controlled</td><td>requires a parser</td></tr> </table> 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: <table> <tr><th>Cell</th><th>{{conf-get}} result</th><th>{{conf-get-list}} result</th></tr> <tr><td>{{key}}</td><td>{{()}}</td><td>{{()}}</td></tr> <tr><td>{{(key . non-list-value)}}</td><td>{{non-list-value}}</td><td>{{(non-list-value)}}</td></tr> <tr><td>{{(key non-list-value)}}</td><td>{{non-list-value}}</td><td>{{(non-list-value)}}</td></tr> <tr><td>{{key (value1 value2 ...)}}</td><td>{{(value1 value2 ...)}}</td><td>{{(value1 value2 ...)}}</td></tr> <tr><td>{{key value1 value2 ...}}</td><td>{{(value1 value2 ...)}}</td><td>{{(value1 value2 ...)}}</td></tr> </table> 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)</procedure> Returns true iff {{x}} is a config object. ==== {{assoc-get}} <procedure>(assoc-get alist key #!optional (equal equal?) default)</procedure> 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 ())))</procedure> Equivalent to {{assoc-get}} but coerces its result to a list as described in the syntax section. ==== {{conf-head}} <procedure>(conf-head config)</procedure> Returns just the base of {{config}} without any parent. ==== {{conf-load}} <procedure>(conf-load file #!optional conf)</procedure> Loads the config file {{file}}, prepending to {{conf}} if provided. ==== {{conf-load-in-path}} <procedure>(conf-load-in-path config-path file)</procedure> 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)</procedure> 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)</procedure> 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 ())))</procedure> 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)</procedure> 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)</procedure> Equivalent to {{conf-get-list}} but returns a list of all cascaded configs appended together. ==== {{conf-extend}} <procedure>(conf-extend config alist #!optional source)</procedure> Extends the config with an additional alist. ==== {{conf-append}} <procedure>(conf-append a b)</procedure> Joins two configs. ==== {{conf-unfold-key}} <procedure>(conf-unfold-key key value)</procedure> Utility to create an alist cell representing the chained key {{key}} mapped to {{value}}. ==== {{conf-set}} <procedure>(conf-set config key value)</procedure> Replace a new definition into the first config alist. ==== {{conf-specialize}} <procedure>(conf-specialize config key name)</procedure> Lift specialized sections to the top-level of a config. ==== {{conf-verify}} <procedure>(conf-verify spec config #!optional warn)</procedure> 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.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you add 21 to 1?