[Chicken-users] idiomatic/usual way of file-based configuration in Scheme
Hi folks, I was wondering if there was something like Java's properties files that is commonly used in Scheme. (The reference to Java is because I learned it, not because I like it :) It would just amount to read a list of key/value pairs in Scheme syntax. Or maybe a triple if the type is given. What do you use ? Thanks, thu ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] idiomatic/usual way of file-based configuration in Scheme
Hello Thu, On Tue, 6 Feb 2007 10:52:36 +0100 minh thu [EMAIL PROTECTED] wrote: I was wondering if there was something like Java's properties files that is commonly used in Scheme. (The reference to Java is because I learned it, not because I like it :) It would just amount to read a list of key/value pairs in Scheme syntax. Or maybe a triple if the type is given. What do you use ? A simple approach would be dumping the representation of scheme objects (e.g., lists) to a file: csi (define my-list '((1 2 3) (4 5 6) (a b c))) csi (with-output-to-file my-file (lambda () (pp my-list))) csi (with-input-from-file my-file read) ((1 2 3) (4 5 6) (a b c)) There is also the s11n egg: http://www.call-with-current-continuation.org/eggs/s11n.html PS: I don't know what Java's properties files are, I considered the second paragraph from your message. Best wishes, Mario ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] idiomatic/usual way of file-based configuration in Scheme
On Feb 6, 2007, at 2:49 AM, Mario Domenech Goulart wrote: Hello Thu, On Tue, 6 Feb 2007 10:52:36 +0100 minh thu [EMAIL PROTECTED] wrote: I was wondering if there was something like Java's properties files that is commonly used in Scheme. (The reference to Java is because I learned it, not because I like it :) It would just amount to read a list of key/value pairs in Scheme syntax. Or maybe a triple if the type is given. What do you use ? A simple approach would be dumping the representation of scheme objects (e.g., lists) to a file: csi (define my-list '((1 2 3) (4 5 6) (a b c))) csi (with-output-to-file my-file (lambda () (pp my-list))) csi (with-input-from-file my-file read) ((1 2 3) (4 5 6) (a b c)) There is also the s11n egg: http://www.call-with-current-continuation.org/eggs/s11n.html PS: I don't know what Java's properties files are, I considered the second paragraph from your message. Best wishes, Mario Take a look at the SRFI-29 egg. ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re : [Chicken-users] idiomatic/usual way of file-based configuration in Scheme
2007/2/6, Kon Lovett [EMAIL PROTECTED]: On Feb 6, 2007, at 2:49 AM, Mario Domenech Goulart wrote: Hello Thu, On Tue, 6 Feb 2007 10:52:36 +0100 minh thu [EMAIL PROTECTED] wrote: I was wondering if there was something like Java's properties files that is commonly used in Scheme. (The reference to Java is because I learned it, not because I like it :) It would just amount to read a list of key/value pairs in Scheme syntax. Or maybe a triple if the type is given. What do you use ? A simple approach would be dumping the representation of scheme objects (e.g., lists) to a file: csi (define my-list '((1 2 3) (4 5 6) (a b c))) csi (with-output-to-file my-file (lambda () (pp my-list))) csi (with-input-from-file my-file read) ((1 2 3) (4 5 6) (a b c)) There is also the s11n egg: http://www.call-with-current-continuation.org/eggs/s11n.html PS: I don't know what Java's properties files are, I considered the second paragraph from your message. Best wishes, Mario Take a look at the SRFI-29 egg. Although I was not asking about for l10n issue, it might become handy. Thanks, thu ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] idiomatic/usual way of file-based configuration in Scheme
On 2/6/07, minh thu [EMAIL PROTECTED] wrote: It would just amount to read a list of key/value pairs in Scheme syntax. Or maybe a triple if the type is given. What do you use ? As I think you realise, this is a capability that is as old as Lisp itself. A property list is just a specialized form of s-expression. I'm not aware of any formal standards for this, but it's pretty much a matter of basic Scheme. Key-value tuples as given by other respondents ((locale ca)(lang fr)(user-data paul users)), use read to read the list of key-value pairs, (with-output-to-file properties write to write it. (define property-list (with-input-from-file properties read)) ... (with-output-to-file properties (write property-list)) And to perform lookup, (let ((value-list (assq 'locale property-list))) ...) Your first value would be (cadr value-list), the third (caddr value-list) and so on. (car value-list) holds the matching lookup key. An alternative would be to use lists of pairs ((locale . en)(lang . fr)). The only difference is that you use cdr to address the value, not car. Remember that '(a b c) is exactly the same as '(a . (b c)), so you can mix both notations in the same list as long as your software (and anyone who edits the list by hand) knows which form to use for a given property. To update, use something like this: (define my-age 64) ... (let ((value-list (assq 'age property-list))) (set-cdr! value-list (list my-age))) To delete an entry, use SRFI-1 delete or delete! (normally you'd use eq? as a comparison operator for this, to compare by keyword). (delete! 'lang property-list (lambda (key value-list) (eq? key (car value-list If your keys can't be represented as symbols, surround them in string quotes and use assoc rather than assq. An association list can contain any serializable Scheme data, including other association lists. For very large collections of keyed data that you will need to lookup frequently, consider using SRFI-69 hash tables for the internal representation. Procedures alist-hash-table and hash-table-alist are provided for this purpose. This kind of heavy duty tool shouldn't be needed for normal property lookups, however. ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users