replace slice of list to a element

Started by ssqq, June 11, 2014, 07:33:25 AM

Previous topic - Next topic

ssqq

As manual said:
QuoteSlices or rest parts of lists or arrays as used in implicit resting or slicing cannot be substituted at once using setf, but would have to be substituted element by element.
.



If I want replace a piece of list to a element:


(set 'lst '(a b c d e f)
(replace-slice (slice lst 2 3) 'g)
lst --> '(a b g f)


I use:
(append (nth '(0 1) lst) 'g (nth 5 lst))

If have any other simple way to get result?

rickyboy

#1
Quote from: "ssqq"I use:
(append (nth '(0 1) lst) 'g (nth 5 lst))
If have any other simple way to get result?

That append expression won't even work.


> (append (nth '(0 1) lst) 'g (nth 5 lst))

ERR: array, list or string expected : a

However, the following will work.


> (append (slice lst 0 2) (list 'g) (slice lst 5))
(a b g f)
> ;; or, with implicits:
> (append (0 2 lst) (list 'g) (5 lst))
(a b g f)
(λx. x x) (λx. x x)

ssqq

#2
Sorry, I have test my code.



Thanks a lots.