Jump to content

Recommended Posts

Posted

hii !!

my programme suppose to loop in 2 list (ptinslist and li )to applicate the translate function.. the first loop worked but the k one doesn't work

 

plzz help

 

(setq k 0)

(setq j 0)

 

(while (

(while (

 

(setq tran (translate (nth k ptinslist)(nth j li)))

 

(setq nvlist (append nvlist (list tran)))

(setq j (+ j 1))

 

)

 

(setq all (append all (list nvlist)))

 

 

(setq k (+ k 1))

)

  • Replies 36
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    15

  • SOliver

    8

  • yajis_narif

    8

  • BlackBox

    3

Popular Days

Top Posters In This Topic

Posted Images

Posted

I have changed the title of your thread to something more descriptive, please use more descriptive titles in the futre, it helps.

Posted

Your snippet is rather confusing, but I think you can accomplish what you are after with mapcar+lambda.

 

eg.

(mapcar '(lambda (a b) (translate a b))
       ptinlist
       li
)

 

BTW, translate is not a native function, so I'm assuming it's one you wrote. If it's trans you are trying for, then you'll need three arguments, not two.

Posted

ok tiger i will thanks

 

alanjit yes translate is a function :

 

(defun translate (pt1 pt2 /)

(mapcar' + pt1 pt2)

 

but i need to loop in the two list (the length of the two list is 4 )

Posted
(mapcar '(lambda (a b) (apply 'mapcar (cons '+ (list a b))))
       ptinlist
       li
)

Posted

If you're intending on goin' with your original code I'd suggest it was written similar to below - for neatnes etc.

(setq k -1)
(while (< (setq k(1+ k)) Lins)
 (setq j -1)
 (while ( < (setq j(1+ j)) Lcord)  
    (setq tran (translate (nth k ptinslist)(nth j li)))    
    (setq nvlist (append nvlist (list tran)))
  )
  (setq all (append all (list nvlist)))
)                         

I'm with alanjt on this one since you're iterating through lists although I think it would need to be

(mapcar '(lambda(x)
 (mapcar '(lambda(y)
   (translate x y))
   Lcoord))
 Lins)

It depends on what you're trying to achieve: if you're trying to translate every point in Lcoord against every point in Lins then the above mapcar cluster is probably what you're looking for. If you're trying to run translate against each lists' respective coordinate e.g

(setq lins (list 0 10 20))
(setq lCoord (list 5 60 80))
;Example point
(translate (nth 0 lins)(nth 0 lCoord))
(translate (nth 1 lins)(nth 1 lCoord))
(translate (nth 2 lins)(nth 2 lCoord))

then you want to go with alanjt's suggestion - which I believe is what you're looking for however; you're posted code is trying to do the solution I've provided.

 

Hope that helps

 

EDIT: Before someone shoots my foot off; all code was written in the respond to thread area and therefore hasn't been tested. Other than the possiblity of an extra right paren or syntax error the principle is sound. :)

Posted

If using the subroutine, I think it should look like this:

 

(mapcar '(lambda (a b) (translate a b)) ptinlist li)

Posted

thanks every one i will try this and reply

for the code i'm trying to do this :

 

(setq lins (list 0 10 20))

(setq lCoord (list 5 60 80))

;Example point

(translate (nth 0 lins)(nth 0 lCoord))

(translate (nth 0 lins)(nth 1 lCoord))

(translate (nth 0 lins)(nth 2 lCoord))

 

(translate (nth 1 lins)(nth 0 lCoord))

(translate (nth 1 lins)(nth 1 lCoord))

(translate (nth 1 lins)(nth 2 lCoord))

 

(translate (nth 2 lins)(nth 0 lCoord))

(translate (nth 2 lins)(nth 1 lCoord))

(translate (nth 2 lins)(nth 2 lCoord))

Posted

I'm confused, is it a list of points or a list of integers?

 

points: '( (0. 0. 0.) (0. 1. 1.) (1. 1. 1.))

integers: '(0 1 2 3 4 5 6)

Posted

no i'ts a list of points actually they are coordinate

Posted
thanks every one i will try this and reply

for the code i'm trying to do this

 

................................

 

In that case use the above (and now below)

(mapcar '(lambda(x)
  (mapcar '(lambda(y)
    (translate x y))
    Lcoord))
  Lins)

Posted

yajis_narif,

 

Please place your codes between code tags. (Just hit the # symbol near the smilies).

 

Thank you.

Posted
In that case use the above (and now below)
(mapcar '(lambda(x)
  (mapcar '(lambda(y)
    (translate x y))
    Lcoord))
  Lins)

 

i'm not that good with the lambda function but doeas this loop into the list actually this code worked

(while (

(setq j -1)

(while (

 

(setq tran (translate (nth k ptinslist)(nth j li)))

 

(setq nvlist (append nvlist (list tran)))

 

)

 

(setq all (append all (list nvlist)))

 

 

 

)

but it return one list of all coordinates actually the first list is a list of four coordinate and the second list is a list of four points too

 

i want to add the first four coordinate to eatch points of the secons list and return a list of 4 list in it

 

i'm sorry i'm not that good in english ^^

Posted
yajis_narif,

 

Please place your codes between code tags. (Just hit the # symbol near the smilies).

 

Thank you.

Better do what he says; you won't like him when he's angry.

Posted
Better do what he says; you won't like him when he's angry.

ok i'm sorry i'm new here so... i will do what he says :)

thanks

Posted
ok i'm sorry i'm new here so... i will do what he says :)

thanks

Sorry, it's a reference to his avatar. I was joking. kickMe.gif
Posted
Better do what he says; you won't like him when he's angry.

 

I see what you did there...... :lol:

Posted

yes yes i know ... he is already angry i guess :sweat:

Posted
Sorry, it's a reference to his avatar. I was joking. kickMe.gif

 

You big bully! Do your little girls know you're such a meany to new kids!? :lol: LoL

 

Edit - (^^ I too am only joking with a friend ^^)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...