I'm starting to look Rather More Seriously at understanding the transaction 
engine.

This is encouraging me to establish sets of data structures on the Guile side 
of the world to represent data in the two quite distinct forms:
a) QIF's "bunch of transactions that get attached to an account, sometimes 
with a split," and

b) The GnuCash Engine "Bunch of accounts that have transactions attached to 
them that have a bunch of splits attached to them."

Those are quite different structures, and I didn't fully grasp what was going 
on until Friday night.

What struck me Friday morning was that I really should be marshalling data 
into somewhat more organized "structures" rather than just building assoc 
lists.  I also finally grokked define-struct, and maybe am looking at is as a 
"hammer," and am looking for "nails" to hit with it.

What I'd like to do is collect the data all together via

(define-struct qif-txn-structure '(memo date id payee addresslist amount status
                          category splitlist)))

and then go off and do (define thistxn (make-qif-txn-structure)) every time I 
want to create a new transaction.

Seems sensible to have the names all together in one spot, much as 
gnucash/src/engine/TransactionP.h and the other *P.h files collect such data 
together into C structures.

Unfortunately, Guile evidently hides (define-struct) and I've not gotten it to 
compile or otherwise work.

Hence, note the attached, that does largely the same thing.

I would be more than pleased to eliminate it in favor of a more "native" 
facility, if the "true" define-struct may be made to work.

[This is one of the annoyances of Scheme as compared to Common Lisp; there are 
many commonly desirable functions/macros that CL has standardized but that 
different Schemes handle differently.]

Note to those that didn't know; the below essentially represents a message 
dispatch system; Object Oriented Programming recreated in 43 lines of code.

Paul Graham's book, "Common Lisp," does a presentation of an 8 line OO system 
that does everything but multiple inheritance...
--
"It's a pretty rare beginner who isn't clueless.  If beginners weren't
clueless, the infamous Unix learning cliff wouldn't be a problem." 
-- david parsons
[EMAIL PROTECTED] <http://www.hex.net/~cbbrowne/langlisp.html>

;;; Some functions to help build structures

;;; define-mystruct is used to build an association list that defines
;;; the layout of a structure...
(define (define-mystruct lst)
  (define alist '())  ;; Association list
  (define count 0)    ;; Number of entries
  (define (add-item item)
    (set! alist (cons (cons item count) alist))
    (set! count (+ 1 count)))
  (for-each add-item lst)
  alist)
;;; Use as follows:
;;; (define qif-split-structure  (define-mystruct '(category memo
;;; amount percent)))  
;;;

(define (build-mystruct-instance structinfo)
  ;;;  struct-instance is the vector for the data...
  (define struct-instance (make-vector (length structinfo) #f))
  (define (get-item field-id)   ;;; Look up entry based on ID
    (let ((assocv (assoc field-id structinfo)))
      (if assocv
          (vector-ref struct-instance (cdr assocv))
          #f)))

  (define (set-item! field-id value)   ;;; Plunk in new value
    (let ((assocv (assoc field-id structinfo)))
      (if assocv
          (vector-set! struct-instance (cdr assocv) value)
          #f)))

  (define (actions action field . value) ;;; now, methods to be applied
    (cond
     ((eq? action 'get) 
      (car (get-item field)))
     ((eq? action 'put) 
      (set-item! field (car value)))
     (else
      (list structinfo struct-instance))))
  actions)

Reply via email to