Re: Using Settings
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 02/03/2014 12:37 AM, Anne Ogborn wrote: > I never seem to get this right > > What's the idiomatic way to use settings? > > For example, I'm just starting a new project (called 'crane'). Like usual, I have a debug.pl that > starts the system up in debug mode. > > :- module(debug, []). > > I then define a setting > > :- setting(crane_debug_port, positive_integer, 14000, 'Port to run the Crane Game on in debug mode.'). From the remainder of the story, I think this is defined in the module 'crane', no? > In debug mode I want pldoc available, so I let the doc server be the server. > > :- setting(crane_debug_port, Port), doc_server(Port). And this appears in `debug'? > Oops - > >> ERROR: c:/docs/jondorbolo/quickygame/crane/crane/prolog/debug.pl:62: > setting `debug:crane_debug_port' does not exist > Warning: c:/docs/jondorbolo/quickygame/crane/crane/prolog/debug.pl:62: > Goal (directive) failed: debug: (setting(crane_debug_port,_G130),doc_server(_G130)) > > changing all occurrences of crane_debug_port to crane:crane_debug_port fixes it. Both declaring and using settings is module aware. You, can use Module:Name both to declare and access a setting in another module. Typically though, declaration and usage should be at the same place, so it all nicely sticks together. > OK, but I'm still not clear what the canonical way to do this is. > > First, if I was using, rather than writing, this code, and wanted debug to run on 16000, > instead of 14000, I'd add a setting to program files\swipl\customize\pl.ini ? Typically, your application calls load_settings/1 at startup to load the settings from a file and act on it. You'll see that in our beloved Prolog website code (loading plweb.conf). To change a setting, there should be some form of UI. But, if there is no UI, you can still do this from the toplevel: ?- set_setting(crane:crane_debug_port, 1600). ?- save_settings. An example of a UI can be found in ClioPatria. That cannot be provided by the library because the application may have a web ui, classical graphical UI, be embedded, etc. > But no, apparently it's to > > > > Installation: > > Unix/MacOS:~/.plrc > Windows:<appdata>/pl.ini (see win_folder(appdata, AppData)) > > > > which would be set_setting? I wouldn't use ~/.plrc or pl.ini for that. It is an application specific thing. The personal setup file is for things you typically like to have around for any project during debugging. The skeleton file gives some typical things you might like there. Examples are command line history, colors, small debugging helpers, editor preferences, etc.