hosneyalaa Posted June 25, 2020 Share Posted June 25, 2020 Sorry English is not good Hello all If possible, help If he has the following list (setq lst-pt '((2.91097 7.9291) (15.2064 6.99916) (12.7764 1.72037) (0.268183 0.311625))) Depending on the location of the item (reverseLITP lst-pt 2) ((2.91097 7.9291) (15.2064 6.99916) (0.268183 0.311625) (12.7764 1.72037)) OR (reverseLITP lst-pt 1) ((2.91097 7.9291) (0.268183 0.311625) (12.7764 1.72037) (15.2064 6.99916)) Thanks, thanks ALL Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 25, 2020 Share Posted June 25, 2020 Here is one way. (defun reverse:list (lst pos / lft run new lft out) (and (< pos (length lst)) (setq lft lst run -1 ) (repeat pos (setq new (cons (nth (setq run (1+ run)) lst) new) lft (cdr lft) ) ) (setq out (append (reverse new) (reverse lft))) ) out ) 1 Quote Link to comment Share on other sites More sharing options...
dlanorh Posted June 25, 2020 Share Posted June 25, 2020 45 minutes ago, hosneyalaa said: Sorry English is not good Hello all If possible, help If he has the following list (setq lst-pt '((2.91097 7.9291) (15.2064 6.99916) (12.7764 1.72037) (0.268183 0.311625))) Depending on the location of the item (reverseLITP lst-pt 2) ((2.91097 7.9291) (15.2064 6.99916) (0.268183 0.311625) (12.7764 1.72037)) OR (reverseLITP lst-pt 1) ((2.91097 7.9291) (0.268183 0.311625) (12.7764 1.72037) (15.2064 6.99916)) Thanks, thanks ALL Try this (defun revlstp (lst p / nlst) (repeat p (setq nlst (cons (car lst) nlst) lst (cdr lst))) (reverse (append lst nlst)) ) 1 Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 25, 2020 Share Posted June 25, 2020 (edited) Nice Tharwat & dlnorh (defun foo (i l / n k) (setq n (length l)) (cond ((not i)(reverse l)) ((< i n) (repeat (1+ i) (setq k (cons (car l) k) l (cdr l) ) ) (apply 'append (mapcar 'reverse (list k l))) ) (t nil) ) ) this reverse (1+ nth) (setq lst '(1 2 3 4 5 6 7)) (foo nil lst) ;(7 6 5 4 3 2 1) (foo 0 lst) ;(1 7 6 5 4 3 2) (foo 3 lst) ;(1 2 3 4 7 6 5) (foo 6 lst) ;(1 2 3 4 5 6 7) (foo 7 lst) ; nil (defun revnth (n lst) ;hp 25.06.2020 ((lambda (f n l) (reverse (append (f (- (length lst) n) (reverse lst)) (f n lst)))) (list '(n l) '(if (> n 0) (cons (nth (1- n) l) (f (1- n) l)))) n l ) ) reverse at nth (setq lst '( 1 2 3 4 5 6 7 8 9 10 ) ) (revnth 0 lst) ; (10 9 8 7 6 5 4 3 2 1 0 ) (revnth 2 lst) ; (0 1 10 9 8 7 6 5 4 3 2 ) Edited June 25, 2020 by hanhphuc add revnth 1 Quote Link to comment Share on other sites More sharing options...
hosneyalaa Posted June 25, 2020 Author Share Posted June 25, 2020 Thanks @Tharwat and @dlanorh and @ hanhphuc Sorry for my late reply The lisps were shown working great and I think beautiful thanks ALL 1 2 Quote Link to comment Share on other sites More sharing options...
pBe Posted June 25, 2020 Share Posted June 25, 2020 Another (defun _relist (lst n) ((lambda (i / l m) (while (and (< i n) (setq v (Car lst))) (setq l (cons v l) i (1+ i) lst (cdr lst)) ) (append (reverse l) (reverse lst)) ) 0 ) ) @ hanhphuc You just have to go the other way than the rest of us don't you.. < n before l st > (defun revnth (n lst)... (defun foo (i l / n k)... 1 Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 26, 2020 Share Posted June 26, 2020 4 hours ago, pBe said: @ hanhphuc You just have to go the other way than the rest of us don't you.. < n before l st > i didn't notice it, it's a habit putting list after n perhaps subconsciousness like cons apply mapcar vl-remove etc.. 1 Quote Link to comment Share on other sites More sharing options...
hosneyalaa Posted June 27, 2020 Author Share Posted June 27, 2020 On 6/25/2020 at 11:18 PM, pBe said: Another (defun _relist (lst n) ((lambda (i / l m) (while (and (< i n) (setq v (Car lst))) (setq l (cons v l) i (1+ i) lst (cdr lst)) ) (append (reverse l) (reverse lst)) ) 0 ) ) @ hanhphuc You just have to go the other way than the rest of us don't you.. < n before l st > (defun revnth (n lst)... (defun foo (i l / n k)... Thanks @pBe 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.
Note: Your post will require moderator approval before it will be visible.