First time posting here. Some background info: Been interested in common lisp a while, had a course with SICP as course book then after university i read OnLisp once, found it fascinating.
Now i am trying to make a DSL language which will read and then modify C# code and print the modified code out, but i got stuck.
I have managed to parse a C# func but then i have it as a lisp list in my program, which creates problems for my output macro.
I think it is easier if i show you, i will first show the working output macro then my macro (which doesn't work) which calls it with a list.
Calling expression:
Code: Select all
(fn-def-pattern ("public" "void" "setName") ("string" "newName") (list (list "int" "id")(list "bool" "employee")) (list "var _a = 2;" (fn-body-add-setter-fn fn-new-para-name)))
Code: Select all
(defmacro fn-def-pattern ((c-visibility c-ret-type c-name) (fn-new-para-type fn-new-para-name) fnParams &body body)
`(let ((c-name ,c-name)
(fn-new-para-name ,fn-new-para-name))
(format nil "~a ( ~a ~a ){ ~% ~{~a~&~} ~& } "
(format nil "~a ~a ~a " ,c-visibility ,c-ret-type ,c-name )
(format nil "~{~{~a ~a~}~^, ~}" ,fnParams ) ;; '((int id)(string name))
(format nil ",~a ~a" ,fn-new-para-type ,fn-new-para-name)
;; ,(cadar body);;,@body;;,(cadar body)
;; (list ,@body)
,@body
)))
(defun fn-body-add-setter-fn ( var-name )
(format nil "var _~a = ~a;" var-name var-name) )
Code: Select all
(LET ((C-NAME "setName") (FN-NEW-PARA-NAME "newName"))
(FORMAT NIL
"~a ( ~a ~a ){ ~% ~{~a~&~} ~& } "
(FORMAT NIL "~a ~a ~a " "public" "void" "setName")
(FORMAT NIL
"~{~{~a ~a~}~^, ~}"
(LIST (LIST "int" "id") (LIST "bool" "employee")))
(FORMAT NIL ",~a ~a" "string" "newName")
(LIST "var _a = 2;" (FN-BODY-ADD-SETTER-FN FN-NEW-PARA-NAME)))
Code: Select all
"public void setName ( int id, bool employee ,string newName ){
var _a = 2;
var _newName = newName;
} "
Code: Select all
(let ((fn-list (list (list "public" "void" "setName") (list "string" "newName") (list (list "int" "id")(list "bool" "employee")) '"var _a = 2;" '(fn-body-add-setter-fn fn-new-para-name)))) (fn-def-pattern-list fn-list))
Code: Select all
(defmacro fn-def-pattern-list (fn-list)
`(fn-def-pattern ((nth 0 (car ,fn-list)) (nth 1 (car ,fn-list)) (nth 2 (car ,fn-list)))
((nth 0 (cadr ,fn-list)) (nth 1 (cadr ,fn-list)))
(nth 2 ,fn-list);;(("int" "id")("bool" "employee"))
(nthcdr 3 ,fn-list)));;`( ,(nth 3 fn-list))))));;(nth 3 ,fn-list)));;(list "var _a = 2;" (fn-body-add-setter-fn fn-new-para-name)))))
Code: Select all
(LET ((FN-LIST
(LIST (LIST "public" "void" "setName")
(LIST "string" "newName")
(LIST (LIST "int" "id") (LIST "bool" "employee"))
'"var _a = 2;"
'(FN-BODY-ADD-SETTER-FN FN-NEW-PARA-NAME))))
(LET ((C-NAME (NTH 2 (CAR FN-LIST)))
(FN-NEW-PARA-NAME (NTH 1 (CADR FN-LIST))))
(FORMAT NIL
"~a ( ~a ~a ){ ~% ~{~a~&~} ~& } "
(FORMAT NIL
"~a ~a ~a "
(NTH 0 (CAR FN-LIST))
(NTH 1 (CAR FN-LIST))
(NTH 2 (CAR FN-LIST)))
(FORMAT NIL "~{~{~a ~a~}~^, ~}" (NTH 2 FN-LIST))
(FORMAT NIL ",~a ~a" (NTH 0 (CADR FN-LIST)) (NTH 1 (CADR FN-LIST)))
(NTHCDR 3 FN-LIST))))
Code: Select all
"public void setName ( int id, bool employee ,string newName ){
var _a = 2;
(FN-BODY-ADD-SETTER-FN FN-NEW-PARA-NAME)
} "
But i haven't managed to find a working solution and at this stage i am prepeared to accept anything that can give me correct end result.
I am happy for any help and suggestions! Thanks!