stumpwm-devel
[Top][All Lists]
Advanced

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

Re: [STUMP] Explain definition please...


From: Tim Cross
Subject: Re: [STUMP] Explain definition please...
Date: Fri, 12 Jul 2019 15:03:18 +1000
User-agent: mu4e 1.3.1; emacs 26.2

Thanks Javier - those additional links are really appreciated. Your
explanation has prompted some long forgotten memories (I did do some CL
many many years ago i.e mid 90's, but pretty much have forgotten most of
the details. Your "in places' and gethash example were the key to
unlocking that forgotten snippet! "

This stumpwm thingy has re-awoken my enjoyment of CL, but I need to go
read and review to blow away the cobwebs. I wish my head had more RAM
and a larger cache!

Tim

Javier Olaechea <address@hidden> writes:

>> 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
>>


--
Tim Cross



reply via email to

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