0 Members and 1 Guest are viewing this topic.
(setq a '((1 2 3)(4 5 6)(7 8 9)))(test1 a) =>> '((3 6 9) (12 15 18) (21 24 27))
'(((* 1 3) (* 2 3) (* 3 3)) ((* 4 3) (* 5 3) (* 6 3)) ((* 7 3) (* 8 3) (* 9 3)) )
(test1 '((1 2 3)(4 5 6)(7 8 9))) =>> '((3 6 9) (12 15 18) (21 24 27))(test1 '((1 2 3 4 5 6)(7 8 9)(10 5 0))) =>> '((3 6 9 12 15 18) (21 24 27) (30 15 0))(test1 '((1)(4 5)(10 5 0))) =>> '((3) (12 15) (30 15 0))
(setq a '((1 2 3) (4 5 6) (7 8 9)))(setq b '((11 12 13) (14 15 16) (17 18 19)))(test2 a b) =>> '((1 13 15) (4 19 21) (7 25 27))
'((1 (+ 2 11) (+ 3 12)) (4 (+ 5 14) (+ 6 15)) (7 (+ 8 17) (+ 9 18)) )
(test2 '((1 2 3) (4 5 6) (7 8 9)) '((11 12 13) (14 15 16) (17 18 19)));=>> '((1 13 15) (4 19 21) (7 25 27))(test2 '((1 2 3 4 5 6)(7 8 9)(10 5 0))'((11 12 13) (14 15 16) (17 18 19)));=>> '((1 13 15 17) (7 22 24) (10 22 18))(test2 '((1)(4 5)(6 7 8)) '((1)(4 5)(6 7 8)));=>> '((1) (4 9) (6 13 15))
(defun Fun1(arg) (mapcar (function (lambda(a) (if (vl-consp a) (fun1 a) (* 3 a) ) ) ) arg ) )
(defun Fun2 (arg1 arg2) (mapcar (function (lambda (a1 a2) (mapcar (function (lambda (i1 i2) (+ i1 i2) ) ) a1 (append '(0) a2) ) ) ) arg1 arg2 ))
(defun operation(type nombre lst) (mapcar '(lambda(x) (if (listp x) (operation type nombre x) ((eval type) nombre x) ) ) lst ))
(defun shift(type lst1 lst2) (mapcar '(lambda(x y) (if (listp x) (cons (car x) (shift type (cdr x) y)) ((eval type) x y) ) ) lst1 lst2 ))
(defun test1 (a) (mapcar '(lambda (a) (mapcar '* a '(3 3 3))) a))(defun test2 (a b) (mapcar '(lambda (a b) (cons (car a) (mapcar '+ (cdr a) b))) a b))
(defun MathList ( mathFunction listIn num ) (mapcar (function (lambda (x) (cond ((atom x) (mathFunction x num) ) ((listp x) (MathList mathFunction x num) ) ) ) ) listIn ))
(defun test2 ( listIn1 listIn2 ) (mapcar (function (lambda ( a b ) (cons (car a) (mapcar (function (lambda ( x y ) (+ x y) ) ) (cdr a) b ) ) ) ) listIn1 listIn2 ))
(defun multby3 (n) (* n 3))(mapcar '(lambda (sub) (mapcar 'multby3 sub)) lst)
(mapcar (function (lambda (sub) (mapcar (function (lambda (n) (* n 3))) sub))) lst)
a=1b=(1, 2, 3)c=((1, 2, 3), (4, 5, 6), (7, 8, 9))
def foo(lst, multiplier=1): if type(lst) in (list, tuple): return [foo(i, multiplier) for i in lst] else: return lst*multiplier
foo(a, 3) => 3foo(b, 3) => [3, 6, 9]foo(c, 3) => [[3, 6, 9], [12, 15, 18], [21, 24, 27]]
class Foo(): def __init__(self, multiplier=1): self.multiplier=multiplier def __call__(self, lst): if type(lst) in (list, tuple): return [self.__call__(i) for i in lst] else: return lst*self.multiplier
foo = Foo(3)foo(a) => 3foo(b) => [3, 6, 9]foo(c) => [[3, 6, 9], [12, 15, 18], [21, 24, 27]]
def make_foo(multiplier): def foo(lst): if type(lst) in (list, tuple): return [foo(i) for i in lst] else: return lst*multiplier return foo
foo = make_foo(3)foo(a) => 3foo(b) => [3, 6, 9]foo(c) => [[3, 6, 9], [12, 15, 18], [21, 24, 27]]
Python just for fun ...
##Extend the Array classclass Array def mult(arg) self.map{|x| x.map{|y| y*arg}} endenda =[[1,2,3,4],[4,5,6,7],[7,8,9,10]]d = a.mult(3)puts d.inspect
> let alist = [[1;2;3];[4;5;6];[7;8;9]]let times3 x = 3*x(List.map (fun x -> List.map times3 x) alist);;val it : int list list = [[3; 6; 9]; [12; 15; 18]; [21; 24; 27]]>
> (List.map (fun x -> List.map (fun x -> 3*x) x) alist);;val it : int list list = [[3; 6; 9]; [12; 15; 18]; [21; 24; 27]]>
(defun test1 (a) (mapcar '(lambda (a) (mapcar '+ a a a)) a))(defun test2 (a b) (mapcar '(lambda (a b) (mapcar '+ a (cons 0 b))) a b))
[[0..9];[10..19];[20..29]] |> List.map (List.map (fun n -> n*3));;
[[0; 3; 6; 9; 12; 15; 18; 21; 24; 27]; [30; 33; 36; 39; 42; 45; 48; 51; 54; 57]; [60; 63; 66; 69; 72; 75; 78; 81; 84; 87]]
let nestedMap f inputList = inputList |> List.map (List.map f)