unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Data Dictionary and Configuration Files with Guile Scheme
@ 2010-08-05 17:15 Romel Sandoval
  2010-08-05 21:04 ` No Itisnt
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Romel Sandoval @ 2010-08-05 17:15 UTC (permalink / raw)
  To: guile-user

Hi,

I'm trying to create a data dictionary [1] to generate code from it. But
since I'm a scheme newbie I was wondering if this is the best method:

{{{
(define-syntax table
  (syntax-rules ()
    ((table name ...)
     (list 'table name ...))))

(define-syntax column
  (syntax-rules ()
	((column name ...)
	 (list 'column name ...))))

(define-syntax type
  (syntax-rules ()
	((type symbol)
	 (cons 'type symbol))))

(define-syntax constraint
  (syntax-rules ()
	((constraint symbol)
	 (cons 'constraint symbol))))

(define-syntax length
  (syntax-rules ()
	((length value)
	 (cons 'length value))))

(define *projects-table*
  (table "projects"
	(column "id" 
		(type 'integer) (constraint 'primary-key))
	(column "title" 
		(type 'string) (length 32) (constraint 'not-null))))
}}}

This way I can write s-exp as in the example *projects-table* an after a
load I will have the data structure ready to work with it.

{{{
scheme@(guile-user)> (load "dd.scm")
scheme@(guile-user)> *projects-table*
(table "projects" (column "id" (type . integer) (constraint .
primary-key)) (column "title" (type . string) (length . 32)
(constraint . not-null)))
}}}

I think this could be a good way to define configuration files too.

What do you think?
Exists better alternatives with Guile?
This mail should go to another list? :-)

Regards,

-- 
Romel R. Sandoval-Palomo

[1]http://database-programmer.blogspot.com/2008/06/using-data-dictionary.html






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Data Dictionary and Configuration Files with Guile Scheme
  2010-08-05 17:15 Data Dictionary and Configuration Files with Guile Scheme Romel Sandoval
@ 2010-08-05 21:04 ` No Itisnt
  2010-08-18 16:05 ` Andy Wingo
  2010-08-18 18:20 ` Thien-Thi Nguyen
  2 siblings, 0 replies; 7+ messages in thread
From: No Itisnt @ 2010-08-05 21:04 UTC (permalink / raw)
  To: Romel Sandoval; +Cc: guile-user

I would use records instead of lists. I think you can also make the
input much simpler, for instance it might look like this:

(define-table projects
  (integer id primary-key)
  (string name non-null #:length 32))


On Thu, Aug 5, 2010 at 12:15 PM, Romel Sandoval <romel@lavabit.com> wrote:
> Hi,
>
> I'm trying to create a data dictionary [1] to generate code from it. But
> since I'm a scheme newbie I was wondering if this is the best method:
>
> {{{
> (define-syntax table
>  (syntax-rules ()
>    ((table name ...)
>     (list 'table name ...))))
>
> (define-syntax column
>  (syntax-rules ()
>        ((column name ...)
>         (list 'column name ...))))
>
> (define-syntax type
>  (syntax-rules ()
>        ((type symbol)
>         (cons 'type symbol))))
>
> (define-syntax constraint
>  (syntax-rules ()
>        ((constraint symbol)
>         (cons 'constraint symbol))))
>
> (define-syntax length
>  (syntax-rules ()
>        ((length value)
>         (cons 'length value))))
>
> (define *projects-table*
>  (table "projects"
>        (column "id"
>                (type 'integer) (constraint 'primary-key))
>        (column "title"
>                (type 'string) (length 32) (constraint 'not-null))))
> }}}
>
> This way I can write s-exp as in the example *projects-table* an after a
> load I will have the data structure ready to work with it.
>
> {{{
> scheme@(guile-user)> (load "dd.scm")
> scheme@(guile-user)> *projects-table*
> (table "projects" (column "id" (type . integer) (constraint .
> primary-key)) (column "title" (type . string) (length . 32)
> (constraint . not-null)))
> }}}
>
> I think this could be a good way to define configuration files too.
>
> What do you think?
> Exists better alternatives with Guile?
> This mail should go to another list? :-)
>
> Regards,
>
> --
> Romel R. Sandoval-Palomo
>
> [1]http://database-programmer.blogspot.com/2008/06/using-data-dictionary.html
>
>
>
>
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Data Dictionary and Configuration Files with Guile Scheme
  2010-08-05 17:15 Data Dictionary and Configuration Files with Guile Scheme Romel Sandoval
  2010-08-05 21:04 ` No Itisnt
@ 2010-08-18 16:05 ` Andy Wingo
  2010-08-18 17:38   ` Romel Sandoval
  2010-08-18 18:20 ` Thien-Thi Nguyen
  2 siblings, 1 reply; 7+ messages in thread
From: Andy Wingo @ 2010-08-18 16:05 UTC (permalink / raw)
  To: Romel Sandoval; +Cc: guile-user

On Thu 05 Aug 2010 10:15, Romel Sandoval <romel@lavabit.com> writes:

> I'm trying to create a data dictionary [1] to generate code from it.
[...]
> This way I can write s-exp as in the example *projects-table* an after a
> load I will have the data structure ready to work with it.

I think you are quite confused :) Use procedures, not macros. If you
really want to use s-expressions, use alists and define accessor
procedures, and be sure not to mutate literal values. You could use hash
tables and records also. Or myriad other data structures. Read
http://mitpress.mit.edu/sicp/, especially the chapters on data
abstraction and state.

But above all, don't take your data structure advice from anyone who
mentions SQL :)

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Data Dictionary and Configuration Files with Guile Scheme
  2010-08-18 16:05 ` Andy Wingo
@ 2010-08-18 17:38   ` Romel Sandoval
  0 siblings, 0 replies; 7+ messages in thread
From: Romel Sandoval @ 2010-08-18 17:38 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-user

El mié, 18-08-2010 a las 09:05 -0700, Andy Wingo escribió:
> On Thu 05 Aug 2010 10:15, Romel Sandoval <romel@lavabit.com> writes:
> 
> > I'm trying to create a data dictionary [1] to generate code from it.
> [...]
> > This way I can write s-exp as in the example *projects-table* an after a
> > load I will have the data structure ready to work with it.
> 
> I think you are quite confused :) Use procedures, not macros. If you
> really want to use s-expressions, use alists and define accessor
> procedures, and be sure not to mutate literal values. You could use hash
> tables and records also. Or myriad other data structures. Read
> http://mitpress.mit.edu/sicp/, especially the chapters on data
> abstraction and state.

Now I see. Thanks.

> 
> But above all, don't take your data structure advice from anyone who
> mentions SQL :)

The problem it's that I haven't found any alternative to SQL :-( So I'm
trying to manage the problem.

SQL alternative?... Anyone?

Romel






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Data Dictionary and Configuration Files with Guile Scheme
  2010-08-05 17:15 Data Dictionary and Configuration Files with Guile Scheme Romel Sandoval
  2010-08-05 21:04 ` No Itisnt
  2010-08-18 16:05 ` Andy Wingo
@ 2010-08-18 18:20 ` Thien-Thi Nguyen
  2010-08-20 14:10   ` Romel Sandoval
  2 siblings, 1 reply; 7+ messages in thread
From: Thien-Thi Nguyen @ 2010-08-18 18:20 UTC (permalink / raw)
  To: Romel Sandoval; +Cc: guile-user

() Romel Sandoval <romel@lavabit.com>
() Thu, 05 Aug 2010 12:15:44 -0500

   What do you think?

I use Guile-PG (several modules) and a homegrown metainfo table
accessible via ‘(ttn-do zzz various-db) personal-pgtable-defs’ et al:
http://www.gnuvola.org/software/ttn-do/ttn-do.html.gz#zzz-various_002ddb

Here is ~/.pgtable-defs, omitting some parts:

  ;;; ~/.pgtable-defs --- database descriptions -*- scheme -*-
  
  ;; Keyword Expansions
  ;; ------------------
  
  ((#:pk "PRIMARY KEY")
   (#:u  "UNIQUE")
   (#:nn "NOT NULL")
   (#:mf "MATCH FULL")
   (#:dc "ON DELETE CASCADE")
   (#:uc "ON UPDATE CASCADE")
   (#:r  "REFERENCES")
   (#:tz "WITH TIME ZONE"))
  
  ;; Database Table Definitions
  ;; --------------------------
  ;;
  ;; ((DB-1 (TABLE DEF ...) (TABLE DEF ...) ...)
  ;;  (DB-2 (TABLE DEF ...) (TABLE DEF ...) ...) ...)
  ;;
  ;; Some day `infer-defs' will be able to round-trip these...
  
  (("ttn"
  
    ("sw_maint"
     (v    bool #:nn)
     (url  text #:nn)
     (mon  text #:nn)
     (name text #:pk)
     (orig text)
     (mtim timestamp[])))                 ; 0: mon
  
   ("gnuvola"
  
    ("updbad"
     (time     timestamp #:pk)
     (cause    text)
     (errmsg   text))
  
    ("updok"
     (time     timestamp #:pk)
     (wrote    int4)
     (read     int4)
     (rate     float4)
     (total    int4)
     (speedup  float4))
  
    ("updfiles"
     (file     text)
     (move     char)
     (time     timestamp #:r "updok" #:dc #:uc))))
  
  ;;; ~/.pgtable-defs ends here

This file consists of two forms.  The first is (hopefully)
self-explanatory.  The second describes two databases:

  db       tables
  -------  -----------------------
  ttn      sw_maint
  gnuvola  updbad, updok, updfiles

Each table's columns are further described in a way that really ought to
be queryable from the backend, so that is a Code Enhancement Opportunity
for the Guile-PG reflection module alluded to by the "Some day" comment.

Although i think SQL is ugly (and thus concur in jest, i believe,
with Andy Wingo's admonition :-), Guile-PG makes it livable.  E.g.:
http://www.gnuvola.org/software/guile-pg/qcons-notes.txt

So, to answer your question: yes, sexps work fine as a Data Dictionary.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Data Dictionary and Configuration Files with Guile Scheme
  2010-08-18 18:20 ` Thien-Thi Nguyen
@ 2010-08-20 14:10   ` Romel Sandoval
  2010-08-20 14:39     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 7+ messages in thread
From: Romel Sandoval @ 2010-08-20 14:10 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: guile-user

Thanks Thien-Thi that's exactly what I was trying to achieve.

El mié, 18-08-2010 a las 20:20 +0200, Thien-Thi Nguyen escribió:
> () Romel Sandoval <romel@lavabit.com>
> () Thu, 05 Aug 2010 12:15:44 -0500
> 
>    What do you think?
> 
> I use Guile-PG (several modules) and a homegrown metainfo table
> accessible via ‘(ttn-do zzz various-db) personal-pgtable-defs’ et al:
> http://www.gnuvola.org/software/ttn-do/ttn-do.html.gz#zzz-various_002ddb
> 
> Here is ~/.pgtable-defs, omitting some parts:
> 
>   ;;; ~/.pgtable-defs --- database descriptions -*- scheme -*-
>   
>   ;; Keyword Expansions
>   ;; ------------------
>   
>   ((#:pk "PRIMARY KEY")
>    (#:u  "UNIQUE")
>    (#:nn "NOT NULL")
>    (#:mf "MATCH FULL")
>    (#:dc "ON DELETE CASCADE")
>    (#:uc "ON UPDATE CASCADE")
>    (#:r  "REFERENCES")
>    (#:tz "WITH TIME ZONE"))
>   
>   ;; Database Table Definitions
>   ;; --------------------------
>   ;;
>   ;; ((DB-1 (TABLE DEF ...) (TABLE DEF ...) ...)
>   ;;  (DB-2 (TABLE DEF ...) (TABLE DEF ...) ...) ...)
>   ;;
>   ;; Some day `infer-defs' will be able to round-trip these...
>   
>   (("ttn"
>   
>     ("sw_maint"
>      (v    bool #:nn)
>      (url  text #:nn)
>      (mon  text #:nn)
>      (name text #:pk)
>      (orig text)
>      (mtim timestamp[])))                 ; 0: mon
>   
>    ("gnuvola"
>   
>     ("updbad"
>      (time     timestamp #:pk)
>      (cause    text)
>      (errmsg   text))
>   
>     ("updok"
>      (time     timestamp #:pk)
>      (wrote    int4)
>      (read     int4)
>      (rate     float4)
>      (total    int4)
>      (speedup  float4))
>   
>     ("updfiles"
>      (file     text)
>      (move     char)
>      (time     timestamp #:r "updok" #:dc #:uc))))
>   
>   ;;; ~/.pgtable-defs ends here
> 
> This file consists of two forms.  The first is (hopefully)
> self-explanatory.  The second describes two databases:
> 
>   db       tables
>   -------  -----------------------
>   ttn      sw_maint
>   gnuvola  updbad, updok, updfiles
> 
> Each table's columns are further described in a way that really ought to
> be queryable from the backend, so that is a Code Enhancement Opportunity
> for the Guile-PG reflection module alluded to by the "Some day" comment.
> 
> Although i think SQL is ugly (and thus concur in jest, i believe,
> with Andy Wingo's admonition :-), Guile-PG makes it livable.  E.g.:
> http://www.gnuvola.org/software/guile-pg/qcons-notes.txt
> 
> So, to answer your question: yes, sexps work fine as a Data Dictionary.






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Data Dictionary and Configuration Files with Guile Scheme
  2010-08-20 14:10   ` Romel Sandoval
@ 2010-08-20 14:39     ` Thien-Thi Nguyen
  0 siblings, 0 replies; 7+ messages in thread
From: Thien-Thi Nguyen @ 2010-08-20 14:39 UTC (permalink / raw)
  To: Romel Sandoval; +Cc: guile-user

() Romel Sandoval <romel@lavabit.com>
() Fri, 20 Aug 2010 09:10:14 -0500

   Thanks Thien-Thi that's exactly what I was trying to achieve.

Cool, we can "relate". :-D



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-08-20 14:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-05 17:15 Data Dictionary and Configuration Files with Guile Scheme Romel Sandoval
2010-08-05 21:04 ` No Itisnt
2010-08-18 16:05 ` Andy Wingo
2010-08-18 17:38   ` Romel Sandoval
2010-08-18 18:20 ` Thien-Thi Nguyen
2010-08-20 14:10   ` Romel Sandoval
2010-08-20 14:39     ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).