Jul. 12th, 2013

juan_gandhi: (VP)
Народ время от времени впадает в панику, что чужие ходят через нейбохуд; вчера опять кто-то прошел. Некоторое время назад я написал такую троллическую хрень:

"I got a vague feeling we all the good people have to arm ourselves and start patrolling our neighborhood so all the bad people get scared and run away screaming. Since in the daytime most of the males are busy working, it's up to moms and unemployed people to do it in the daylight. When we are back from work, we can do the night shifts."

(upd: перевод. "У меня есть смутное ощущение, что все хорошие люди должны вооружиться и начать патрулировать местность, чтобы все плохие люди испугались и с воплями убежали. Так как днём большинство лиц мужского пола заняты работой, то матери и безработные должны заниматься этим в светлое время суток. А когда мы вернёмся с работы, мы можем пойти патрулировать в ночную смену.")

Такое ощущение, что восприняли всерьёз; трепещите теперь, Трейвоны!

nice scala

Jul. 12th, 2013 06:34 pm
juan_gandhi: (VP)
deep copy done easily
object Example {
  trait Nested[A] { def dup: A => A }
  object Nested {
    implicit def nestedAnything[A] = new Nested[A] { def dup = identity }
    implicit def nestedArray[A](implicit ev: Nested[A], mf: Manifest[A]) = 
      new Nested[Array[A]] { def dup = _ map ev.dup }
  }
  def deepDup[A](aa: Array[A])(implicit ev: Nested[Array[A]]) = ev dup aa
}

scala> val a = Array(Array(1,2,3), Array(4,5,6), Array(7,8))
a: Array[Array[Int]] = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8))
scala> val c = deepDup(a)
c: Array[Array[Int]] = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8))
scala> a(0)(0)=9; c // it's a copy, not a reference
res0: Array[Array[Int]] = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8))



questions? improvements?

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 17th, 2025 05:15 pm
Powered by Dreamwidth Studios