you can obtain the "AND" result by iterating over the two lists at the same time with foreach, and then if you want to filter away the nil results you can do that using "setof". Here's an example:
foreach(mapcar (a b) bslist1 bslist2 a&&b)
=> (nil nil nil nil nil
(111.135 67.755) (114.9 67.755) (114.9 66.35) (113.045 66.35)
setof(item foreach(mapcar (a b) bslist1 bslist2 a&&b) item)
=> ((111.135 67.755)
By the way, I inserted a single quote ' before the open parentheses from your example of defining bslist1 and bslist2. The 'mapcar' allows us to return the result rather than the (first) original list. With the foreach function you can iterate two variables over two lists, three variables over three lists and so on; the number of iterations is determined by the first list, so if the lists are not equal in length the first list should be the shortest or an error will ensue.
Hopefully this answers your question?
In reply to Andrew Beckett:
Sorry, deliberate mistake (ok, typo from typing on a smart phone). Should have been:
Andrew, Lawrence, thanks for your help, works a charm.
In reply to blankman:
Andrew & Lawrence,
I have 2 lists below, essentially lists within a list. How would I go
about comparing and extracting the corresponding points to true values
in this case?
bspartselobjvalidlist = ((nil nil nil nil nil nil t nil) (nil t nil nil))
bspartselobjpointlist = (((-3.685 7.465) (-4.45 7.465) (-4.45 8.0)
(-5.39 8.0) (-5.39 7.24) (-4.675 7.24) (-4.675 6.335) (-3.685 6.335))
((-5.39 3.555) (-5.39 4.74) (-4.01 4.74) (-4.01 3.555)))
I'm not sure how you want to store your results, but here is one way to do it:
procedure(myListAnd(list1 list2) let((pointList) foreach((subList1 subList2) list1 list2 foreach((flag point) subList1 subList2 when(flag println(point) pointList = cons(point pointList) ) ) ) pointList ) ;let) ;proc
Or you can wrap Andrew's example as a function and call it using the same foreach-mapcan structure:
procedure(CCFandLists(blist1 blist2 "ll")
foreach(mapcan (a b) blist1 blist2 a&&list(b))
foreach(mapcan (a b) bspartselobjvalidlist bspartselobjpointlist
=> ((-4.675 6.335)
So you can then either call the CCFandLists function directly similar to Andrew's earlier post (e.g. CCFandLists(bslist1 bslist2) ) when the lists are in that format, or you can call the function as in the above example when the lists are list-of-lists. This way you are re-using the function...
In reply to skillUser:
Lawrence Derek thanks, I made an attempt at it since I posted and
came up with the below. Working fine.
Its insightful to see
foreach(elementb bspartselobjvalidlist elementc=car(bspartselobjpointlist) bspartselobjpointlist=cdr(bspartselobjpointlist) result=foreach(mapcan (a b) elementb elementc a&&list(b)) bspartselobjvalidpointlist = cons( result bspartselobjvalidpointlist))
Here's how I'd have done it - with a recursive function. This will then cope with any nested structure of lists:
procedure(CCFandNestedLists(blist1 blist2) if(listp(car(blist1)) && car(blist1) foreach(mapcar (a b) blist1 blist2 CCFandNestedLists(a b)) foreach(mapcan (a b) blist1 blist2 a && list(b)) ))
The lists will be returned in the same order; Brian's solution reverses them (which may not matter to you).