October 12, 20169 yr 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.
October 12, 20169 yr 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.
October 12, 20169 yr Author 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))
Create an account or sign in to comment