Jump to content

Recommended Posts

works fine:

(rnd-replace '(123) '(1 2 3 4))

=> (1 2 3 123)

 

don't work ... why?

(rnd-replace '(123) '(1 2 3 4) :exclude '(2 3))

=> 

> Error: The value 1 is not of the expected type list.
> While executing: pos-rep, in process Listener-1(6).
> Type cmd-. to abort, cmd-\ for a list of available restarts.
> Type :? for other options.

Link to comment
Share on other sites

section and exclude works with lists not on a list.

 

Arguments and Values:

 

section            an integer or a list of integers. Selected list or lists to process. The default is NIL.

exclude            an integer or a list of integers. Excluded list or lists from process. The default is NIL.

Link to comment
Share on other sites

i needed something like that..

regards

andré

(defun rnd-replace/user (item sequence &key (exclude 'nil))
    (loop for i in sequence
      with val
      with pos = (position (car (loop 
                                  do (setf val (nth (random (length sequence)) sequence))
                                  when (null (member val exclude))
                                  collect val into bag
                                  when (= (length bag) 1)
                                  do (return bag))) 
                           sequence)
      for cnt = 0 then (incf cnt)
      when (= cnt pos)
      collect (rnd-pick item)
      else collect i))

(rnd-replace/user '(123 987) '(1 2 3 4 5) :exclude '(1 5))

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy