taruss
9/28/2015 5:43:00 PM
On Monday, September 28, 2015 at 8:37:07 AM UTC-7, CAI GENGYANG wrote:
> CL-USER 1 > (defun qualify (expr)
> (nconc (copy-list expr) (list 'maybe)))
Simpler: (append expr (list 'maybe))
If you are going to make a copy of the first argument anyway, there is no
reason to use NCONC instead of APPEND, since APPEND will also make the copy.
> CL-USER 2 > (let ((x 0)) (defun total (y)
> (incf x y)))
You realize that you have no way to find out the value of X independently.
Although I suppose you could always call (TOTAL 0) to find out the current value of X.
What do you want this TOTAL function to accomplish?
> CL-USER 3 >
> (defun ok (x)
> (nconc (list 'a x) (list 'c)))
Simpler: (list 'a x 'c)
> CL-USER 4 > (defun not-ok (x)
> (nconc (list 'a) x (list 'c)))
You realize that this will destructively modify X, which must be a list.
> CL-USER 5 > (defun anything (x) (+ x *anything*))
> ANYTHING
You need to also define *ANYTHING*, presumably with DEFVAR or DEFPARAMETER.
>
> CL-USER 6 > (defun f (x)
> (let ((val (g x)))
> ; safe to modify val here? ))
Depends on what you mean by modify and safe.
Using SETQ or SETF on VAL will always be safe, since it just changes the local
variable binding.
If you destructively modify the object that is bound to VAL then that may or
may not be safe, but that depends on what invariants your program wants to have
and what could be considered safe.