AM Posted October 12, 2016 Share Posted October 12, 2016 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. Quote Link to comment Share on other sites More sharing options...
opmo Posted October 12, 2016 Share Posted October 12, 2016 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. Quote Link to comment Share on other sites More sharing options...
AM Posted October 12, 2016 Author Share Posted October 12, 2016 okay, i see... i will modify it for myself thanx! Quote Link to comment Share on other sites More sharing options...
AM Posted October 12, 2016 Author Share Posted October 12, 2016 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)) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.