chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] INI files in Scheme? (or something similar)


From: Shawn Rutledge
Subject: Re: [Chicken-users] INI files in Scheme? (or something similar)
Date: Mon, 3 Mar 2008 18:56:05 -0700

On Mon, Mar 3, 2008 at 6:22 PM, Hans Nowak <address@hidden> wrote:
>  Is there a "standard" way to do INI files (or similar kinds of initialization
>  files, ala .bashrc etc) in Scheme?  For example, something like this:

My first idea would be put an alist in the conf file:

((developer . dev_id)
 (application . app_id) ... )

then to get the values, write a function like this:

(define conf-or-default #f)
(let ([alist #f])
  (set! conf-or-default (lambda (key default)
    (unless alist (... read the file into alist ...))
    (let ([ret (assq alist key)])
       (if (pair? ret) (cdr ret) default))))

It can read the whole file the first time it is needed, in one swoop,
and expect that it has only one s-expression in it.  (Sorry if there
are any mistakes, I didn't test it)

>  I understand that this could easily be done in Scheme itself, e.g.
>
>  (define developer INSERT_DEV_ID)
>  (define url "api.sandbox.foobar.com")

It depends whether you can think of any use cases for the user to
write some code in this file as well as just defining values.  That
can be quite useful: e.g. the user could write callbacks for some
events that your app exposes, just like JavaScript allows the web page
author to do this; and also dangerous: the user can use set! to
redefine variables that your app depends on, and create arbitrary
bugs.  But you can mitigate that by loading the config file inside a
restricted environment, so that some things can be redefined and some
not.  You are comparing to .bashrc, which can do both (set environment
variables and also execute arbitrary code).

Either way, it's possible to avoid parsing the conf file line-by-line, at least.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]