Lisp two lists, get items from each list to be together -


i have 2 list follows

list 1 ((item 1 5 9) (item 2 50 15) (item 3 39 99) (item 4 16 79) (item 5 20 96))

list 2 ( (1 0 1 0 1) (1 1 1 1 1) (1 0 1 0 1))

i want

(item 1 5 9) (1) (item 2 50 15) (0) (item 3 39 99) (1) (item 4 16 79) (0) (item 4 16 79) (1)

and each chromosome. have following code far

(defun print-lists (list1 list2) (loop x in list1       y in list2       collect (print(list x y) )) ) 

i not grasp example, maybe help?

(loop x in '((1 1 1) (1 0 1))       append (mapcan (lambda (a b) (list (list b)))                      '((item 1 2 3) (item 4 5 6) (item 7 8 9))                      x)) 

which evaluates to:

((item 1 2 3) (1) (item 4 5 6) (1) (item 7 8 9) (1) (item 1 2 3) (1) (item 4 5 6) (0) (item 7 8 9) (1)) 

translated example like

(loop x in list2       append (mapcan (lambda (a b) (list (list b)))                      list1                      x)) 

(if rather have each iteration in seperate list, change append collect.)

you can print resulting list with

(format t "~{~a ~a~%~}" result-list) 

or similar.

keep in mind works if length of items in list2 matches length of list1.

for more information on mapcan can visit

http://www.lispworks.com/documentation/hyperspec/body/f_mapc_.htm

regards, k.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -