[ Skill ] map mapc mapcan mapcar mapcon maplist mapinto

https://www.cnblogs.com/yeungchie/

map

map(
  lambda(( a b )
    println( list( a b ))
  )
  list( 1 2 3 )
  list( 4 5 6 )
)
; ((1 2 3) (4 5 6))
; ((2 3) (5 6))
; ((3) (6))
; => (1 2 3)

mapc

mapc(
  lambda(( a b )
    println( list( a b ))
  )
  list( 1 2 3 )
  list( 4 5 6 )
)
; (1 4)
; (2 5)
; (3 6)
; => (1 2 3)

mapcan

mapcan(
  lambda(( a b )
    println( list( a b ))
    list( a + b )
  )
  list( 1 2 3 )
  list( 4 5 6 )
)
; (1 4)
; (2 5)
; (3 6)
; => (5 7 9)

mapcar

mapcan(
  lambda(( a b )
    println( list( a b ))
    a + b
  )
  list( 1 2 3 )
  list( 4 5 6 )
)
; (1 4)
; (2 5)
; (3 6)
; => (5 7 9)

mapcon

mapcon(
  lambda(( a b )
    println( list( a b ))
    list(a b)
  )
  list( 1 2 3 )
  list( 4 5 6 )
)
; ((1 2 3) (4 5 6))
; ((2 3) (5 6))
; ((3) (6))
; => ((1 2 3) (4 5 6) (2 3) (5 6) (3) (6))

maplist

maplist(
  lambda(( a b )
    println( list( a b ))
    list(a b)
  )
  list( 1 2 3 )
  list( 4 5 6 )
)
; ((1 2 3) (4 5 6))
; ((2 3) (5 6))
; ((3) (6))
; => (((1 2 3) (4 5 6)) ((2 3) (5 6)) ((3) (6)))

mapinto

mapinto(
  list( 0 0 0 0 0 )
  lambda(( a b )
    println( list( a b ))
    a + b
  )
  list( 1 2 3 )
  list( 4 5 6 )
)
; (1 4)
; (2 5)
; (3 6)
; => (5 7 9 0 0)
上一篇:个人对lambda表达式的理解


下一篇:【机器学习】非凸转成凸、约束转无约-运筹学和支持向量机中的拉格朗日松弛法