> 2. How do you call/use such a function? (setf (getenv "VAR") "VALUE")
> 1. Why define it like this instead of just doing something like (defun setenv (val var) ...)? Because that wouldn't follow the conventions for assignment in lisp. The way you set values (in places) is with setf. ej. (setf (gethash k ht) v). But as you point out there APIs that use setenv. uiop is another example, that prefers to use setf, (setf (uiop:getenv ...) ...). In CL a function name is defined as "A symbol or a list (setf symbol)"[0]. (defun (setf ..) is one of the simpler ways to define a setf expander, there are others like defsetf. I'll leave some links below if you want to know more about them, You can read more about it in - Function Call Forms as Places http://www.lispworks.com/documentation/lw50/CLHS/Body/05_abb.htm - The less-familiar parts of Lisp for beginners — define-setf-expander https://blog.cneufeld.ca/2014/01/the-less-familiar-parts-of-lisp-for-beginners-define-setf-expander/ - Generalized reference http://www.lispworks.com/documentation/lw50/CLHS/Body/05_a.htm [0]: http://www.lispworks.com/documentation/lw50/CLHS/Body/26_glo_f.htm#function_name On Thu, Jul 11, 2019 at 8:04 PM Tim Cross <theophil...@gmail.com> wrote: > Hi, > > while my stumpwm migration is going really well and I'm really enjoying > this WM, I have come across something which I simply don't understand > which is beyond my meagre CL skills. Would appreciate it if someone can > explain it. > > In the wrappers.lisp, we have the following two function definitions > > (defun getenv (var) > "Return the value of the environment variable." > (sb-posix:getenv (string var))) > > (defun (setf getenv) (val var) > "Set the value of the environment variable, @var{var} to @var{val}." > (sb-posix:putenv (format nil "~A=~A" (string var) (string val)))) > > The second one has me quite baffled. Two main questions: > > 1. Why define it like this instead of just doing something like (defun > setenv (val var) ...)? > > 2. How do you call/use such a function? > > thanks, > > Tim > > -- > Tim Cross > > _______________________________________________ > Stumpwm-devel mailing list > Stumpwm-devel@nongnu.org > https://lists.nongnu.org/mailman/listinfo/stumpwm-devel > -- "I object to doing things that computers can do." — Olin Shivers
_______________________________________________ Stumpwm-devel mailing list Stumpwm-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/stumpwm-devel