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

ActiveSupport、String#squish, String#squish!

まんま >> require "rubygems" => true >> require "active_support" => true >> s = " foo bar \n \t boo" => " foo bar \n \t boo" >> s.squish => "foo bar boo" >> s.squish! => "foo bar boo" >> s => "foo bar boo"

JDK5.0 新機能:EnumSet.range

「4.6. EnumSet」 import java.util.*; enum C2008083100_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008083100 { public static void main(String[] args) { EnumSet<C2008083100_Color> s; s = EnumSet.range(C2008083100_Color.RED, C2008083100_Color.WHITE</c2008083100_color>…

サブ規則の引数リスト 複数渡せる

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : rule['foo', 'bar', 'baz'] rule : 'a' { print "$arg[0] $arg[1] $arg[2]\n"; } }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defined $parse->inpu…

os.exit

元 exit ? #!/usr/bin/env lua os.exit(0) で、 $ ./2008083100.lua $ echo $? 0#!/usr/bin/env lua os.exit(1) で、 $ ./2008083101.lua $ echo $? 1

ActiveSupport、String#to_datetime

>> require "rubygems" => true >> require "active_support" => true >> "2008-01-01".to_datetime => Tue, 01 Jan 2008 00:00:00 +0000 >> "2008-01-01".to_datetime.class => DateTime

JDK5.0 新機能:EnumSet.of

「4.6. EnumSet」 import java.util.*; enum C2008083000_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008083000 { public static void main(String[] args) { EnumSet<C2008083000_Color> s = EnumSet.of(C2008083000_Color.RED); System.out.println(s); s = E</c2008083000_color>…

サブ規則の引数リスト

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : rule['foo'] rule : 'a' { print "$arg[0]\n"; } }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defined $parse->inputs($_) or print "Bad text!\n";…

os.date

元 date ? #!/usr/bin/env lua print(os.date("%%a %a %A")) print(os.date("%%b %b %B")) print(os.date("%%c %c")) print(os.date("%%d %d")) print(os.date("%%H %H")) print(os.date("%%I %I")) print(os.date("%%j %j")) print(os.date("%%m %m")) pri…

ActiveSupport、String#to_date

>> require "rubygems" => true >> require "active_support" => true >> "2008-01-01".to_date => Tue, 01 Jan 2008 >> "2008-01-01".to_date.class => Date

JDK5.0 新機能:EnumSet.complementOf

「4.6. EnumSet」 import java.util.*; enum C2008082900_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008082900 { public static void main(String[] args) { EnumSet<C2008082900_Color> s = EnumSet.complementOf(EnumSet.of(C2008082900_Color.RED)); System</c2008082900_color>…

ディレクティブ nocheck

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : rule rule : subrule(s) subrule }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defined $parse->inputs($_) or print "Bad text!\n"; } で、 Warning…

os.tmpname

元 tmpname ? #!/usr/bin/env lua print(os.tmpname()) で、 lua: ./2008082900.lua:3: `tmpname' not supportedあれ? io.tmpfile() を使えということなのか???

ActiveSupport、String#to_time

>> require "rubygems" => true >> require "active_support" => true >> "2008-01-01".to_time => Tue Jan 01 00:00:00 UTC 2008 >> "2008-01-01".to_time(:local) => Tue Jan 01 00:00:00 +0900 2008 >> "2008-01-01".to_time.class => Time

JDK5.0 新機能:EnumSet.copyOf

「4.6. EnumSet」 import java.util.*; enum C2008082800_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008082800 { public static void main(String[] args) { EnumSet<C2008082800_Color> s1 = EnumSet.allOf(C2008082800_Color.class); EnumSet<C2008082800_Color> s2 = EnumSet.c</c2008082800_color></c2008082800_color>…

ディレクティブ score、もう一つの例

まんま #!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : line line : seplist[sep=>','] <score: -@{$item[1]}> { print "*,*\n"; } | seplist[sep=>':'] <score: -@{$item[1]}> { print "*:*\n"; } | seplist[sep=>" "] <score: -@{$item[1]}> { print "* *\n"; } seplist: <skip:""> </skip:""></score:></score:></score:>

os.rename

元 rename ?まんま #!/usr/bin/env lua a, error = os.rename("foo", "bar") if not a then print("1: ", error) end a, error = os.rename("foo", "bar") if not a then print("2: ", error) end で、 2: foo: No such file or directory

ActiveSupport、String#ord

>> "a".ord NoMethodError: undefined method `ord' for "a":String from (irb):1 >> require "rubygems" => true >> require "active_support" => true >> "a".ord => 97 >> "abc".ord => 97

JDK5.0 新機能:EnumSet.allOf

「4.6. EnumSet」 import java.util.*; enum C2008082700_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008082700 { public static void main(String[] args) { EnumSet<C2008082700_Color> s = EnumSet.allOf(C2008082700_Color.class); System.out.println(s); </c2008082700_color>…

ディレクティブ autoscore

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : <autoscore: 1> | 'a' { print "*a1 $score $score_return*\n"; } | 'a' { print "*a2 $score $score_return*\n"; } | 'a' { print "*a3 $score $score_return*\n"; } }; my $parse = n</autoscore:>…

os.remove

元 remove ?まんま #!/usr/bin/env lua a, error = os.remove("foo") if not a then print("1: ", error) end a, error = os.remove("foo") if not a then print("2: ", error) end で、 2: foo: No such file or directory

ActiveSupport、String#last

まんま >> require "rubygems" => true >> require "active_support" => true >> "hello".last => "o" >> "hello".last(2) => "lo" >> "hello".last(10) => "hello"

JDK5.0 新機能:EnumSet.noneOf

「4.6. EnumSet」 import java.util.*; enum C2008082600_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008082600 { public static void main(String[] args) { EnumSet<C2008082600_Color> s = EnumSet.noneOf(C2008082600_Color.class); System.out.println(s);</c2008082600_color>…

ディレクティブ score、変数 $score, $score_return

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : 'a' { print "*a1 $score $score_return*\n"; } <score: 1> | 'a' { print "*a2 $score $score_return*\n"; } <score: 2> | 'a' { print "*a3 $score $score_return*\n"; } <score: 3> }; my $parse = n</score:></score:></score:>…

io.write

元 write ? #!/usr/bin/env lua io.write("foo") io.write("bar") io.write(1, "\n") --io.write(nil) --print(nil) で、 foobar1

ActiveSupport、String#first

まんま >> require "rubygems" => true >> require "active_support" => true >> "hello".first => "h" >> "hello".first(2) => "he" >> "hello".first(10) => "hello" Array に合せて?

JDK5.0 新機能:EnumMap

「4.5. EnumMap」まんま import java.util.*; enum C2008082500_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008082500 { public static void main(String[] args) { EnumMap<C2008082500_Color, String> map = new EnumMap<C2008082500_Color, String>(C2008082500_Color.class); map.put(C20080825</c2008082500_color,></c2008082500_color,>…

ディレクティブ score

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : 'a' { print "*a1*\n"; } | 'a' { print "*a2*\n"; } | 'a' { print "*a3*\n"; } }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defined $parse->inpu…

io.read

元 read ? #!/usr/bin/env lua print(io.read("*n")) print(io.read("*l")) print(io.read("*a")) で、以下を入力 123 foo aaabbbcccで、 123 foo aaabbbccc #!/usr/bin/env lua print(io.read("*n")) で、以下を入力 fooで、 nil

ActiveSupport、String#to

まんま >> require "rubygems" => true >> require "active_support" => true >> "hello".to(0) => "h" >> "hello".to(2) => "hel" >> "hello".to(10) => "hello"

JDK5.0 新機能:enum の switch 文での利用

「4.4. switch - case 文での利用」 enum C2008082400_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008082400 { public static void main(String[] args) { C2008082400_Color color = C2008082400_Color.valueOf("WHITE"); switch (color) {…