| |
comp.lang.lisp |
I'm struggling with my sense of beauty here, having difficulties to I'm working with graphs (the mathematical structures) and wrote a couple Therefore instead of (progn now I can do (with-graph (some-graph) This comes in very handy when I have to do multiple operations on the Thanks (defgeneric graph-add-vertex (graph ...) ...) (defparameter *graph-functions* (defun graph-flet-curry (graph function new-function) ;; function `remove-symbol-prefix' alters a symbol by removing a prefix (defmacro with-graph ((graph) &body body)
decide if the following is a good or bad idea. A few comments about the
following code with respect to good lisp style would be highly
appreciated.
of functions which all take a graph as it's first argument. To safe
myself some keystrokes, I wrote a macro which takes a graph as argument,
and provides curried functions of the graph-functions, also changing
the name to avoid confusion (and to safe a few more keystrokes).
(graph-add-vertex some-graph 4)
(graph-delete-vertex some-graph 5))
(add-vertex 4)
(delete-vertex 5)
same object. However, it feels strange to generate new symbols, so I
wonder if there is a better way doing this kind of thing. Global
variables would work, but that would break my attempt of doing things in
a functional manner.
A
'(graph-add-vertex graph-delete-vertex graph-vertex-outdegree))
`(,new-function (&rest args)
(apply #',function ,graph args)))
;; (function definition not included for shortness)
(flet ((graph-flet-curry (graph function new-function)
`(,new-function (&rest args)
(apply #',function ,graph args))))
`(flet ,(loop for function in *graph-functions*
collect (graph-flet-curry graph
function
(remove-symbol-prefix function
'graph)))
,@body)))