| hi, i just started learning lisp.. and experimenting it whether i can make use for my daily job. I wrote some code to generate sql statement, to use with c#, but it seems to be very harder than writing in c#. It also doesnt look neat. I want to know how you people would make this code look cool and short. ;;; table metadata
(= tbl
'(Study ; table name
(StudyId int pk studyseq)
(StudyCode string 25)
(StartDate datetime 8)
(Description string 25)))
;; this code generates the insert statement
;; for the above table
(do
(pr "insert into " (car tbl) " ( ")
(with (l1 "" l2 "" pk nil)
(each field (cdr tbl)
(if (find 'pk field)
(= pk field)
(do
(+= l1 (string (car field)) ", ")
(+= l2 ":" (string (car field)) ", "))))
(sref l1 #\Space (- (len l1) 2))
(sref l2 #\Space (- (len l2) 2))
(pr l1)
(unless (is pk nil)
(pr ", " (string (car pk))))
(pr " ) values ( " l2)
(unless (is pk nil)
(pr ", " (string (last pk) ".nextval")))
(pr ")")
(unless (is pk nil)
(pr " returning " (string (car pk)) " into :"
(string (car pk)))))
nil)
output is :
insert into Study ( StudyCode, StartDate, Description , StudyId ) values ( :StudyCode, :StartDate, :Description , studyseq.nextval) returning StudyId into :StudyId |