Lisp HUG Maillist Archive

shrink vector and setf expansion

Hello Lispers,

1) I want to shrink a vector (string). Looking at the source code of
puri.lisp from franz inc, I found that for Lispwork they used this
undocumented function:

system::shrink-vector$vector

Is it a legitimate use? Or is it better to use subseq to get a shorter
string from the original? Any other options to shrink a vector
(adjust-array, for example)?


2) I have these simple lines:

(defparameter a 0)
(setf a 1)

In some sources it is said that for such a case the macroexapnd of
setf should be simple (setq a 1), but Lispworks does something like
this:

(LET* ((#:G684 1)) (SETQ A #:G684))

What is the rationale behind this (let form)? Just curious. :)


Best,
 Art


Re: shrink vector and setf expansion

arthymc@mail.ru wrote on Fri, 8 Jan 2010 02:09:40 +0300 02:09:

| 1) I want to shrink a vector (string). Looking at the source code of
| puri.lisp from franz inc, I found that for Lispwork they used this
| undocumented function:
|
| system::shrink-vector$vector
|
| Is it a legitimate use? Or is it better to use subseq to get a shorter
| string from the original? Any other options to shrink a vector
| (adjust-array, for example)?

It is not recommended to use the symbols that are not exported and not
documented. Though they works anyhow :-). OTOH, adjust-array is only
applicable to adjustable vectors, which are treated slower than simple
vectors.

If you are in doubt, you can take a look at another portable URI
implementation (not using system::shrink-vector$vector) at http://lisp.ystok.ru/projects.html#yuri

| 2) I have these simple lines:
|
| (defparameter a 0)
| (setf a 1)
|
| In some sources it is said that for such a case the macroexapnd of
| setf should be simple (setq a 1), but Lispworks does something like
| this:
|
| (LET* ((#:G684 1)) (SETQ A #:G684))

Do not worry, I believe the compiler should optimize and strips away this
"let" afterwards.
--
Sincerely,
Dmitriy Ivanov
lisp.ystok.ru


Re: shrink vector and setf expansion

On 7 Jan 2010, at 23:09, arthymc@mail.ru wrote:

> In some sources it is said that for such a case the macroexapnd of
> setf should be simple (setq a 1), but Lispworks does something like
> this:
>
> (LET* ((#:G684 1)) (SETQ A #:G684))
>
> What is the rationale behind this (let form)? Just curious. :)

My guess is that this is some residual artifact of the SETF expansion  
avoiding multiple evaluation.  In any case it will almost certainly be  
optimized away. I don't think you have any guarantee of what the  
expansion of SETF will be (unless it's one you've defined): rather you  
know that it will have certain properties (evaluating things only  
once, returning the new value, probably some others), which this  
clearly does.

--tim


Updated at: 2020-12-10 08:40 UTC