PatrickMimran Posted May 14, 2017 Share Posted May 14, 2017 (trans '((1 2 3) (a b c) (4 5 6)) => ((1 a 4) (2 b 5) (3 c 6)) is it somewhere in Opusmodus ? Any idea how to make it ? Thanks Patrick Quote Link to comment Share on other sites More sharing options...
o_e Posted May 14, 2017 Share Posted May 14, 2017 46 minutes ago, rndrnd said: (trans '((1 2 3) (a b c) (4 5 6)) => ((1 a 4) (2 b 5) (3 c 6)) is it somewhere in Opusmodus ? Any idea how to make it ? Thanks Patrick (loop for x in '(1 2 3) for y in '(a b c) for z in '(4 5 6) collect (list x y z)) hth ole loopyc 1 Quote Link to comment Share on other sites More sharing options...
opmo Posted May 14, 2017 Share Posted May 14, 2017 (matrix-transpose '((1 2 3) (a b c) (4 5 6))) loopyc 1 Quote Link to comment Share on other sites More sharing options...
PatrickMimran Posted May 14, 2017 Author Share Posted May 14, 2017 Thank you Patrick Quote Link to comment Share on other sites More sharing options...
AM Posted May 14, 2017 Share Posted May 14, 2017 ;;; in "pure lisp" with NIL when lists have not the same length (defun trans* (lists) (loop repeat (car (last (sort-asc (mapcar 'length lists)))) for cnt = 0 then (incf cnt) collect (loop for i in lists collect (nth cnt i)))) (trans* '((1 2 3 4) (a b c d) (11 12 13 14) (k l m n))) (trans* '((1 2 3 4) (a b c d e) (11 12 13 14 14 16) (k l m n o p q r s t))) (trans* '((1 2 3 4) (a b c d e) (11 12 13 14) (k l m n r s t))) loopyc 1 Quote Link to comment Share on other sites More sharing options...
torstenanders Posted May 14, 2017 Share Posted May 14, 2017 Here is another approach to implement the same thing, but a but more concisely in just one line (most of the code below is the documentation :) (defun mat-trans (lists) "Matrix transformation. (mat-trans '((a1 a2 a3) (b1 b2 b3) (c1 c2 c3) ...)) => ((a1 b1 c1 ...) (a2 b2 c2 ...) (a3 b3 c3 ...))" (apply #'mapcar #'(lambda (&rest all) all) lists)) loopyc and AM 2 Quote Link to comment Share on other sites More sharing options...
AM Posted May 14, 2017 Share Posted May 14, 2017 (apply #'mapcar #'(lambda (&rest all) all) lists)) this is really cool! :-) Quote Link to comment Share on other sites More sharing options...
opmo Posted May 14, 2017 Share Posted May 14, 2017 (apply #'mapcar #'list '((1 3 5) (2 4 6))) AM, loopyc, torstenanders and 1 other 4 Quote Link to comment Share on other sites More sharing options...
AM Posted May 14, 2017 Share Posted May 14, 2017 i have to learn more about lisp :-) Quote Link to comment Share on other sites More sharing options...
PatrickMimran Posted May 14, 2017 Author Share Posted May 14, 2017 Thank you to all of you for your time and your help Patrick 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.