(terrible) MVC system added by arthurmaciel on Thu Feb 9 03:33:16 2012

;; PSEUDOCODE!
;; This should seem like a MVC system.

;; After writing it I realized that the only advantage would 
;; be 'encapsulation'. All this could be done with 'loose' procedures
;; without 'objects'. It does not need inheritance at all.

;; To me OO programming organizes the code and brings some 
;; security-from-the-programmer to the code. I don't know if it is a
;; Good(TM) feature.

;; But OO this way seems less verbose and 'loose' in other languages:
;;   model.delete_patient(first-param)
;;   ((model 'delete-patient) first-param)
;; After writing it and comparing, it is not 'loose', but a bit more 
;; verbose (4 chars more per line on Scheme), which does not matter much.

;; Scheme indeed looks like much more mathematical due to the 
;; parenthesis, and much more fluid, as now I understand the 
;; facilities of prefix notation.

;; I really have the impression that Scheme programmers are more secure
;; about their own coding/code and do not need any 
;; security-from-the-programmer feature.
;; And I realize I still have an imperative(-oriented) mind for 
;; programming.

;; Comments on the above would help me a lot.



;; ----------------------------------------------------------------------------
;; Structure of URLs:
;; prot://server.adress/controller/method/first-param/param2/.../paramN

;; Requested URLs that would serve the example
;; --->  http://server.com/patient/edit/10234
;; --->  http://server.com/patient/delete/10234


;; use DBMS eggs instead
(define (db-select table return-column where-column where-column-value)
  (db (++ "SELECT " (->string return-column) 
	  "FROM " (-> table)
	  "WHERE " (->string where-column) 
	  "=" (->string where-column-value))))

(define (db-delete table where-column where-column-value)
  (db (++ "DELETE "
	  "FROM " (-> table)
	  "WHERE " (->string where-column) 
	  "=" (->string where-column-value))))

(def-model patient-management
  (let ((table 'patients))
    (def-method (get-patient-name id)
      (db-select table 'name 'id id))
    (def-method (get-patient-ssn id)
      (db-select table 'ssn 'id id))
    (def-method (delete-patient id)
      (db-delete table id))
    ; ...
    ))

(def-view patient-data name
  (def-method (html)
    (<html> (<body> (<h1> name))))
  (def-method (xml)
    (<patient> (<name> name)))
  (def-method (plain-txt)
    (++ "Patient name: " name))
  (def-method (pdf)
    (invoke-model pdf)
    (print-pdf name))
  ; ...
  )
    
(def-controller patient
  (def-method (edit)
    (let* ((model (invoke-model patient-management))
	   (patient-name ((model 'get-patient-name) first-param))
	   (view ((invoke-view patient-data) patient-name)))
      ((view 'html)))) ; just change this line and you change the output
  (def-method (delete)
    (let ((model (invoke-model patient-management)))
      ((model 'delete-patient) first-param))))