Re: [racket-users] Configuration Files

2015-11-18 Thread George Neuner

On 11/18/2015 5:19 PM, Christopher Walborn wrote:

I'm looking for a way to read configuration files. The configuration file 
format can be anything provided it's easily human readable/writable. I found 
the ApacheConf solution on RosettaCode and may use that, but am wondering if 
there is a conf format that's more commonly used for Racket projects.

There's no serious need for portability, longevity or anything else. I'm just 
using it to provide some settings and paths to local utilities in shell scripts 
which are little more than wrappers around other utilities.

Thanks,
Christopher


I second   Sam's suggestion to read/write files with Racket.

I personally don't like the require/dynamic-require approach that Neil 
suggested because the config file then is evaluated only at load time [I 
don't know a way to "unload" a module, though maybe it is possible with 
custodians], and it is hard to limit execution of arbitrary Racket code.


I work a lot on server applications where other people may have to edit 
the configuration file, and I often need ability to reload (parts of) 
the configuration while the process is running.



I use a simple dotted pair format:
( name1 . setting1 )
( name2 . setting2 )
:

and I read/eval it using something like:

(define (load-config config-path)
  (let [
(eval-ns  (make-base-namespace))
(params   (make-hash))
   ]

  (let [
(settings (file->list config-path))
   ]
(for [(name:value settings)]
  (let* [
 ; extract the 'name' symbol
 (n (car name:value))
 ; evaluate the 'value' expression
 (v (cdr name:value))
 (v (eval (quasiquote (,@v)) eval-ns))
]
(hash-set! params n v)
))
  )

params
))


My full version includes file error handling and ways to sanity check 
the settings, but this is the basic idea.   For more control, the 
namespace could be recreated (or copied) each time, or you can start 
with an empty namespace and add only those features you want to allow in 
the file.  Or use a sandbox with a custom language.   So far I have not 
found any of these to be necessary.


YMMV,
George

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Configuration Files

2015-11-18 Thread Neil Van Dyke
I generally second the idea of doing a configuration file format like 
"info.rkt" (but not using that particular filename, unless your program 
is tools for Racket development projects).


An advantage of this format is that you then have a few different 
options for how to use the file.  Specifically, if the file format looks 
like Racket code, you can use it via `read`/`read-syntax` (while setting 
parameters for safety), via `dynamic-require`, or via `require`.


And you can change your mind how to use the format later, without 
requiring end users to change the documented file format they use.


If you eventually go to `dynamic-require` or `require`, then you can add 
more Racket language features to the "configuration file", and then it's 
an extensibility language, or your program is a domain-specific 
framework.  This is also a good way to ease people into extension, and 
into using Racket.


Neil V.

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Configuration Files

2015-11-18 Thread WarGrey Gyoudmon Ju
info.rkt, that's its name, you can search it in docs for details.

On Thu, Nov 19, 2015 at 6:39 AM, Sam Tobin-Hochstadt 
wrote:

> I usually use a file that I `read` and `write` with racket data,
> probably a hash table.
>
> Sam
>
> On Wed, Nov 18, 2015 at 5:19 PM, Christopher Walborn 
> wrote:
> > I'm looking for a way to read configuration files. The configuration
> file format can be anything provided it's easily human readable/writable. I
> found the ApacheConf solution on RosettaCode and may use that, but am
> wondering if there is a conf format that's more commonly used for Racket
> projects.
> >
> > There's no serious need for portability, longevity or anything else. I'm
> just using it to provide some settings and paths to local utilities in
> shell scripts which are little more than wrappers around other utilities.
> >
> > Thanks,
> > Christopher
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Configuration Files

2015-11-18 Thread Sam Tobin-Hochstadt
I usually use a file that I `read` and `write` with racket data,
probably a hash table.

Sam

On Wed, Nov 18, 2015 at 5:19 PM, Christopher Walborn  wrote:
> I'm looking for a way to read configuration files. The configuration file 
> format can be anything provided it's easily human readable/writable. I found 
> the ApacheConf solution on RosettaCode and may use that, but am wondering if 
> there is a conf format that's more commonly used for Racket projects.
>
> There's no serious need for portability, longevity or anything else. I'm just 
> using it to provide some settings and paths to local utilities in shell 
> scripts which are little more than wrappers around other utilities.
>
> Thanks,
> Christopher
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Configuration Files

2015-11-18 Thread Christopher Walborn
I'm looking for a way to read configuration files. The configuration file 
format can be anything provided it's easily human readable/writable. I found 
the ApacheConf solution on RosettaCode and may use that, but am wondering if 
there is a conf format that's more commonly used for Racket projects.

There's no serious need for portability, longevity or anything else. I'm just 
using it to provide some settings and paths to local utilities in shell scripts 
which are little more than wrappers around other utilities.

Thanks,
Christopher

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.