What little functions/macros do you use?
Posted: Tue Mar 23, 2010 3:20 pm
I had (and still have) a little file with little utilities in it, many of these aren't a big deal, but i could imagine them being an annoyance to others. So we should discuss them and try see if we can agree on using the same ones. Part of the objective of Alexandria is presumably this. PDF Draft documentation, autodocumentation. (Confused that it is named ".0.DEV" there..) Incase pdf misses anything. Of course Alexandria isn't the only library that could help standardize how we do stuff.
I personally changed some code to start using $#'if-let, $#'when-let, $#'curry, $#'rcurry of Alexandria instead of my own. (Actually i think i sometimes even found CL functions/macros to suit the utility i originally met with my own macro/function.
Some macros i still use have my own variant for:
setf- change a setf-able by a function; (defmacro setf- (change-function to-set &rest args) `(setf ,to-set (,change-function ,@args))), for instance (setf- max var ...) does the same as (alexandria:maxf var ...) (it is just more general) Of course i usually don't use setting anything, usually end up using it if i am writing a simulation.
with-mod-slots allows you do do two things 1) treat slots as interned into the current package, and 2) have the slots of two objects with same-named slots accessible directly without writing a $#'symbol-macrolet yourself. I also encounter this usually in simulations.You could do the same for $#'with-accessors i guess.
And, as i whined before, denest, but not very often at all. I use a more complicated version than the below.(too complicated infact, and i don't make use of it, but i can just cut it out)But i think that if you're using it, it is likely(but not certain) that you need to rethink how you're doing things.
More minorly, constant Just a function of the constant given with an ignored (&rest rest) argument, sqr, and i have some more in the file that i either end up not using much(case-let, mk for make-instance), or i should phase out using. Also got vector stuff i use. (Not this just use lisps vectors and pray that optimizes now.. (The suggested packages there seem to involved there, i just wanted basic vectors, and maybe matrices.)
So what little functions/macros do you use? And which libraries or do you keep them yourself? Have any libraries to suggest to others?
I personally changed some code to start using $#'if-let, $#'when-let, $#'curry, $#'rcurry of Alexandria instead of my own. (Actually i think i sometimes even found CL functions/macros to suit the utility i originally met with my own macro/function.
Some macros i still use have my own variant for:
setf- change a setf-able by a function; (defmacro setf- (change-function to-set &rest args) `(setf ,to-set (,change-function ,@args))), for instance (setf- max var ...) does the same as (alexandria:maxf var ...) (it is just more general) Of course i usually don't use setting anything, usually end up using it if i am writing a simulation.
with-mod-slots allows you do do two things 1) treat slots as interned into the current package, and 2) have the slots of two objects with same-named slots accessible directly without writing a $#'symbol-macrolet yourself. I also encounter this usually in simulations.
Code: Select all
(defmacro with-mod-slots (mod (&rest slots) object &body body)
(with-gensyms (obj)
`(let ((,obj ,object))
(symbol-macrolet
(,@(mapcar (lambda (slot)
`(,(intern (format nil "~D~D" mod slot))
(slot-value ,obj ',slot)))
slots))
,@body))))
And, as i whined before, denest, but not very often at all. I use a more complicated version than the below.(too complicated infact, and i don't make use of it, but i can just cut it out)
Code: Select all
(defmacro denest (&rest forms)
(if (null (cdr forms))
(car forms)
`(,@(car forms) (denest ,@(cdr forms)))))
More minorly, constant Just a function of the constant given with an ignored (&rest rest) argument, sqr, and i have some more in the file that i either end up not using much(case-let, mk for make-instance), or i should phase out using. Also got vector stuff i use. (Not this just use lisps vectors and pray that optimizes now.. (The suggested packages there seem to involved there, i just wanted basic vectors, and maybe matrices.)
So what little functions/macros do you use? And which libraries or do you keep them yourself? Have any libraries to suggest to others?