stumpwm-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [STUMP] Explain definition please...


From: Javier Olaechea
Subject: Re: [STUMP] Explain definition please...
Date: Thu, 11 Jul 2019 21:40:30 -0500

> 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 <address@hidden> 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
address@hidden
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel


--
"I object to doing things that computers can do." — Olin Shivers

reply via email to

[Prev in Thread] Current Thread [Next in Thread]