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

leftop を使わない方法?

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : list { print Data::Dumper::Dumper($item[1]); } list : '(' list_item(s /,/) ')' { $return = $item[2] } list_item : /\w/ }; my $parse = new Pa…

io.output

元 writeto ? #!/usr/bin/env lua if io.output() then --print("foo") io.write("foo") end #!/usr/bin/env lua if io.output("2008082401.txt") then -- print("foo") io.write("foo") end print を使うと、ファイルに書き込まれない

ActiveSupport、String#from

まんま >> require "rubygems" => true >> require "active_support" => true >> "hello".from(0) => "hello" >> "hello".from(2) => "llo" >> "hello".from(10) => "" 確かにこれに相当する簡潔な記述はなかったかも。python ならあるけど

JDK5.0 新機能:java.lang.Enum クラスの getDeclaringClass() というメソッド

「4.3. 定数ごとに異なる振る舞いを持った enum」基本的に、まんま enum C2008082300_Color { RED, BLUE, YELLOW, BLACK, WHITE } enum C2008082300_Style { BOLD() { public String apply(String s) { return "<b>" + s + "</b>"; }}, ITALIC() { public String ap…

ディレクティブ leftop のリスト表現で空リストを扱う

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : list { print Data::Dumper::Dumper($item[1]); } list : '(' <leftop: list_item /(,|=>)/ list_item>(?) ')' { $return = $item[2] } list_item : /\w/ }; my $parse = new Pa</leftop:>…

io.input

元 readfrom ? #!/usr/bin/env lua for line in io.input():lines() do print(line) end ファイル名の指定 #!/usr/bin/env lua for line in io.input("2008082301.lua"):lines() do print(line) end

ActiveSupport、String#at

まんま >> require "rubygems" => true >> require "active_support" => true >> "hello".at(0) => "h" >> "hello".at(4) => "o" >> "hello".at(10) => "" 何が嬉しいんだっけ?

JDK5.0 新機能:定数ごとに異なる振る舞いを持った enum

「4.3. 定数ごとに異なる振る舞いを持った enum」まんま enum C2008082200_Style { BOLD() { public String apply(String s) { return "<b>" + s + "</b>"; }}, ITALIC() { public String apply(String s) { return "<i>" + s + "</i>"; }}, RED() { public String apply(S…

ディレクティブ leftop, rightop で演算子も返したい

サブ規則か正規表現の括弧を使用まんま #!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : list { print Data::Dumper::Dumper($item[1]); } list : '(' <leftop: list_item separator list_item> ')' { $return = $item[2] } list_item : /\w/ </leftop:>…

定義済みファイルディスクリプタ

#!/usr/bin/env lua print(io.stdin) print(io.stdout) print(io.stderr) print(io.input) print(io.input()) print(io.output) print(io.output()) で、 file (0x804ed18) file (0x804f080) file (0x804f0d8) function: 0x804ea70 file (0x804ed18) functio…

ActiveSupport、Float#round_with_precision

>> require "rubygems" => true >> require "active_support" => true >> x = 1.337 => 1.337 >> x.round => 1 >> x.round(1) => 1.3 >> x.round(2) => 1.34 >> x.round(3) => 1.337 >> x.round_without_precision => 1 printf 使うのと何が違うんだ?と思っ…

JDK5.0 新機能:enum、カスタムのメソッドの実装

「4.2. カスタムのメソッドの実装」ほぼ、まんま enum C2008082100_Color { RED("赤"), BLUE("青"), YELLOW("黄"), BLACK("黒"), WHITE("白"); private String name; private C2008082100_Color(String name) { this.name = name; } public String toString(…

ディレクティブ leftop, rightop は演算子に関わるオペランドのリストを返す

まんま #!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : list { print Data::Dumper::Dumper($item[1]); } list : '(' <leftop: list_item ',' list_item> ')' { $return = $item[2] } list_item : /\w/ }; my $parse = new Parse::RecD</leftop:>…

その他の math 関数

#!/usr/bin/env lua print(math.log(1)) print(math.log10(10)) print(math.cos(0)) print(math.sin(math.pi/2)) print(math.tan(math.pi/4)) print(math.acos(1)) print(math.asin(1)) print(math.atan(1)) --print(math.tan2(1, 0)) print(math.deg(math.p…

ActiveSupport、Numeric::Time

>> require "rubygems" => true >> require "active_support" => true >> Time.local(2008) => Tue Jan 01 00:00:00 +0900 2008 >> 1.seconds.since(Time.local(2008)) => Tue Jan 01 00:00:01 +0900 2008 >> 1.second.since(Time.local(2008)) => Tue Jan 0…

JDK5.0 新機能:enum のメソッド

「4.1. 簡単な enum」 enum C2008082000_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008082000 { public static void main(String[] args) { C2008082000_Color white = C2008082000_Color.valueOf("WHITE"); System.out.println(white); Sy…

ディレクティブ leftop, rightop

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : assign { print Data::Dumper::Dumper($item[1]); } assign :

math.min, math.max

まんま #!/usr/bin/env lua print(math.min(23, 5, 123, 3)) print(math.max(23, 5, 123, 3)) で、 3 123

ActiveSupport、Numeric#to_utc_offset_s

ほぼ、まんま >> require "rubygems" => true >> require "active_support" => true >> -21_600.to_utc_offset_s => "-06:00" >> -21_600.to_utc_offset_s(false) => "-0600" >> 60*60*9 => 32400 >> -32_400.to_utc_offset_s => "-09:00"

JDK5.0 新機能:enum

「4.1. 簡単な enum」ほぼ、まんま enum C2008081900_Color { RED, BLUE, YELLOW, BLACK, WHITE } public class C2008081900 { public static void main(String[] args) { C2008081900_Color white = C2008081900_Color.valueOf("WHITE"); System.out.printl…

ディレクティブ leftop, rightop

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

string.gsub

まんま #!/usr/bin/env lua print(string.gsub("Linguagem Lua 3.0", " ", "+")) texto = " Linguagem Lua 3.0 " print(string.gsub(texto, " *", " ")) lista = [[ arq.txt texto.txt r.txt ]] print(string.gsub(lista, "(.*)%.txt\n", "move %1.txt %1.ba…

ActiveSupport、Numeric::Bytes 残り

>> require "rubygems" => true >> require "active_support" => true >> 1.kilobytes => 1024 >> 1.kilobyte => 1024 >> 1.2.kilobytes => 1228.8 >> 1.megabytes => 1048576 >> 1.megabyte => 1048576 >> 1.2.megabytes => 1258291.2 >> 1.gigabytes => 10…

JDK5.0 新機能:オートボクシング、実習課題

import java.util.*; public class C2008081800 { public static void main(String[] args) { ArrayList<Double> a = new ArrayList<Double>(); double sum = 0; int num = 1000; for (int i = 0; i < num; i++) { a.add(Math.random()); } for (Double d : a) { sum += d; }</double></double>…

ディレクティブ leftop, rightop の一歩前

#!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ inputs : disjunction { print Data::Dumper::Dumper($item[1]); } disjunction : /\w/ ('or' /\w/)(s?) { $return = [ $item[1], @{$item[2]} ] } }; my $pars…

string.format

まんま #!/usr/bin/env lua name = "Car" id = 123 cmd = string.format("insert into table (name, id) values (%s , %d)" , name, id) print(cmd) print(string.format("%c", 65)) a = 123.456 print(string.format("%+010.2f", a)) で、 insert into tabl…

ActiveSupport、Numeric#byte, Numeric#bytes

>> require "rubygems" => true >> require "active_support" => true >> 1.byte => 1 >> 1.bytes => 1 >> 1.2.bytes => 1.2 alias されているのは、単数の場合には、byte を使って、複数の場合には、bytes を使うため?

JDK5.0 新機能:オートボクシング、インスタンスの共用

「3.4. インスタンスの共用」ほぼ、まんま public class C2008081700 { public static void main(String[] args) { Integer a = 100; Integer b = 100; System.out.println(a == b); Integer c = 10000; Integer d = 10000; System.out.println(c == d); Int…

ディレクティブ token

まんま #!/usr/bin/env perl use strict; use Parse::RecDescent; use Data::Dumper; my $grammar = q{ lex : token(s) { print Data::Dumper::Dumper($item[1]); } token : /a\b/ <token:INDEF> | /the\b/ <token:DEF> | /fly\b/ <token:NOUN,VERB> | /[a-z]+/i { lc $item[1] } <token:ALPHA> | <error: Unknown token> }; m…</error:></token:alpha></token:noun,verb></token:def></token:indef>

string.byte

元 ascii ?まんま #!/usr/bin/env lua print(string.byte("abc", 2)) で、 98マニュアルの「(結果)42.」は全然違うような?「42」は「B」のASCIIコードの16進表現のような?