2008-06-01から1ヶ月間の記事一覧

PDF::Writer:Color::CMYK#to_rgb

require 'color' black = Color::CMYK.new(0, 0, 0, 100) p black.to_rgb p Color::CMYK.new(0, 1, 1, 0).to_rgb p Color::CMYK.new(0, 100, 100, 0).to_rgb p Color::CMYK.new(0, 100, 100, 0).to_rgb(true) で、 #<Color::RGB:0x40228b44 @b=0.0, @g=0.0, @r=0.0> #<Color::RGB:0x40228824 @b=0.99, @g=0.99, @r=1.0> #</color::rgb:0x40228824></color::rgb:0x40228b44>

Java FAQ:Cloneable インターフェース

Java FAQ:S027 Q-03確かに clone() の実装されている java.util.LinkedList とかでは Cloneable を使っているようだ //class C2008063001 implements Cloneable { class C2008063001 { public C2008063001 dup() { try { return (C2008063001)this.clone();…

$return

何もしなかった場合、「$item[$#item]」となるのが仕様だったらしい #!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : ab { print "$item[1]\n"; } ab : 'a' 'b' }; my $parse = new Parse::RecDescent ($grammar); while…

PDF::Writer:Color::CMYK#html

require 'color' black = Color::CMYK.new(0, 0, 0, 100) p black.html で、 "#000000"

Java FAQ:オブジェクトのコピー

Java FAQ:S027 Q-02 さらっと「Object#clone() メソッドを使用します」と書いてあったが、Ruby の感覚では使えなかった… java.util.* あたりのコレクションクラスだと単純に呼び出せそうな感じ public class C2008062900 { public static void main(String[…

%item

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : 'a' 'b' { print Data::Dumper::Dumper(%item); } }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defined $parse->inputs($_) or p…

PDF::Writer:Color::CMYK#pdf_fill, #pdf_stroke

require 'color' black = Color::CMYK.new(0, 0, 0, 100) p black.pdf_fill p black.pdf_stroke で、 "0.000 0.000 0.000 1.000 k" "0.000 0.000 0.000 1.000 K"version 2.0 でなくなるらしい

Java FAQ:java.lang.Thread.currentThread()

Java FAQ:S022 Q-04 public class C2008062800 { public static void main(String[] args) { System.out.println(java.lang.Thread.currentThread()); } } で、 Thread[main,5,main]

@item

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : 'a' 'b' { print "* ", Data::Dumper::Dumper(@item); print "* ", Data::Dumper::Dumper($item[0]); print "* ", Data::Dumper::Dumper($item[1]); p…

PDF::Writer:Color::CMYK.from_fraction

require 'color' black = Color::CMYK.from_fraction(0, 0, 0, 1) p black p (black == Color::RGB::Black) で、 #<Color::CMYK:0x4022aad4 @y=0, @m=0, @c=0, @k=1> trueマニュアルでは「black = Color::CMYK.new(0, 0, 0, 1)」と直し忘れているようだ</color::cmyk:0x4022aad4>

Java FAQ:スレッドを sleep

Java FAQ:S022 Q-01 public class C2008062700 { public static void main(String[] args) { System.out.println("*"); try { java.lang.Thread.sleep(1000); } catch(java.lang.InterruptedException e) { } System.out.println("*"); } } で、 * *

空のアクション

undef が返り、失敗するらしい #!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : 'a' { } }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defined $parse->inputs($_) or print "Bad text!\n"; } で、 a…

PDF::Writer:Color::CMYK.new

require 'color' black = Color::CMYK.new(0, 0, 0, 100) p black p (black == Color::RGB::Black) で、 #<Color::CMYK:0x401cba70 @y=0.0, @m=0.0, @c=0.0, @k=1.0> true</color::cmyk:0x401cba70>

Java FAQ:コンストラクタ内の synchronized

Java FAQ:S021 Q-11 public class C2008062600 { C2008062600() { synchronized (this) { } } public static void main(String[] args) { new C2008062600(); } } 書けることは書けるらしい

$Parse::RecDescent::skip

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; $Parse::RecDescent::skip = ''; my $grammar = q{ inputs : /[a-z ]/ { print Data::Dumper::Dumper($item[1]); } }; my $parse = new Parse::RecDescent ($grammar); while (<>…

PDF::Writer:Color::RGB#r=, #g=, #b=

require 'color' c = Color::RGB::Red.dup p c c.r = 0 c.b = 1 p c p (c == Color::RGB::Blue) で、 #<Color::RGB:0x401cb944 @g=0.0, @r=1.0, @b=0.0> #<Color::RGB:0x401cb944 @g=0.0, @r=0, @b=1> true</color::rgb:0x401cb944></color::rgb:0x401cb944>

Java FAQ:コンストラクタに synchronized の指定はダメ

Java FAQ:S021 Q-10 public class C2008062500 { synchronized C2008062500() { } public static void main(String[] args) { new C2008062500(); } } で、 C2008062500.java:8: 修飾子 synchronized をここで使うことはできません。 synchronized C2008062…

トークンの正規表現にはパラメータも可

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : /[a-z]/i { print Data::Dumper::Dumper($item[1]); } }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defined $parse->inputs($_) …

PDF::Writer:Color::RGB#r, #g, #b

require 'color' p [Color::RGB::Red.r, Color::RGB::Red.g, Color::RGB::Red.b] p [Color::RGB::Blue.r, Color::RGB::Blue.g, Color::RGB::Blue.b] で、 [1.0, 0.0, 0.0] [0.0, 0.0, 1.0]

Java FAQ:wait と notify で待ち合わせ

Java FAQ:S021 Q-09全コードが書いてないので、良く分からない…

ルールに変数

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : "$::x" { print Data::Dumper::Dumper($item[1]); } }; my $parse = new Parse::RecDescent ($grammar); my $x = "foo"; while (<>) { defined $parse…

PDF::Writer:Color::RGB#adjust_hue

require 'color' p Color::RGB::Red.adjust_hue(10) p Color::RGB::Green.adjust_hue(10) p Color::RGB::Blue.adjust_hue(10) p Color::RGB::Red.adjust_hue(-10) p Color::RGB::Green.adjust_hue(-10) p Color::RGB::Blue.adjust_hue(-10) で、 #<Color::RGB:0x40228aa4 @r=1.0, @b=0.0, @g=0.0> #</color::rgb:0x40228aa4>

Java FAQ:wait, notify で IllegalMonitorStateException

Java FAQ:S021 Q-06 public class C2008062300 { C2008062300() { try { wait(); } catch (InterruptedException e) { System.out.println(e); } } public static void main(String[] args) { new C2008062300(); } } で、 Exception in thread "main" java…

反復指定子の第二引数

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : input(s /;/) { print Data::Dumper::Dumper($item[1]); } input : 'a' 'b' { [@item[1,2]]; } }; my $parse = new Parse::RecDescent ($grammar); wh…

PDF::Writer:Color::RGB#adjust_saturation

require 'color' p Color::RGB::Red.adjust_saturation(10) p Color::RGB::Green.adjust_saturation(10) p Color::RGB::Blue.adjust_saturation(10) p Color::RGB::Red.adjust_saturation(-10) p Color::RGB::Green.adjust_saturation(-10) p Color::RGB::Bl…

Java FAQ:wait(), notify()

Java FAQ:S019 Q-20http://www.nextindex.net/java/thread/waitnotify2.html を動作させてみた Consumer: 0 Producer: 0 Consumer: 1 Producer: 1 Consumer: 2 Producer: 2 Consumer: 3 Producer: 3 Consumer: 4 Producer: 4

リテラルにも反復指定子

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : ('a')(s) { print Data::Dumper::Dumper($item[1]); } }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defined $parse->inputs($_) …

PDF::Writer:Color::RGB#adjust_brightness

require 'color' p Color::RGB::Red.adjust_brightness(10) p Color::RGB::Green.adjust_brightness(10) p Color::RGB::Blue.adjust_brightness(10) p Color::RGB::Red.adjust_brightness(-10) p Color::RGB::Green.adjust_brightness(-10) p Color::RGB::Bl…

Java FAQ:IllegalThreadStateException

Java FAQ:S019 Q-19 import java.lang.Thread; public class C2008062100 { public static void main(String[] args) { ThreadGroup g = new ThreadGroup("foo"); g.destroy(); Thread t = new Thread(g, "bar"); t.start(); } } で、 Exception in thread …

サブ規則の反復指定子

7種類 #!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : input(?) { print Data::Dumper::Dumper($item[1]); } input : 'a' 'b' { [@item[1,2]]; } }; my $parse = new Parse::RecDescent ($grammar); …