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

まんま module Main where import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec.Expr expr :: Parser Integer expr = buildExpressionParser table factor "expression" table = [[op "*" (*) AssocLeft, op "/" div AssocLeft] ,[…

関数呼び出し、引数の数が異なる場合

#!/usr/bin/env lua function f(a, b) end function g(a, b, c) end f(1,2,3) g(1,2) で、エラー出ない。こんなので良いの?

ActiveSupport、Array#to_xml

>> require "rubygems" => true >> require "active_support" => true >> [].to_xml => "\n<nil-classes type=\"array\"/>\n" >> [].to_xml(:skip_types => true) => "\n<nil-classes/>\n" >> [{:foo => 1, :bar => 2}, {:baz => 3}]…</nil-classes/></nil-classes>

JDK5.0 新機能:スレッドの状態の取得

「10.4. スレッドの状態の取得」 public class C2008092200 implements Runnable { public void run() { } public static void main(String[] args) { System.out.println(Thread.State.NEW); System.out.println(Thread.State.RUNNABLE); System.out.printl…

エラーメッセージ

まんま module Main where --import Parsec import Text.ParserCombinators.Parsec word :: Parser String word = many1 letter "word" sentence :: Parser [String] sentence = do{ words <- sepBy1 word separator ; oneOf ".?!" ; return words } separa…

関数定義いろいろ

#!/usr/bin/env lua t = {} function t.f() print("f") end t.f() で、 f#!/usr/bin/env lua local function f() print("f") end f() で、 f

ActiveSupport、Array#to_formatted_s

>> require "rubygems" => true >> require "active_support" => true >> [1, 2, 3].to_formatted_s => "123" >> ["foo", "bar", "baz"].to_formatted_s => "foobarbaz" >> [1, 2, 3].to_formatted_s(":") => "123" >> [1, 2, 3].to_formatted_s(:db) /usr/l…

JDK5.0 新機能:UncaughtExceptionHandler

「10.3. キャッチされない例外の取得」まんま import java.lang.Thread.UncaughtExceptionHandler; class C2008092100_MyUncaughtExceptionHandler implements UncaughtExceptionHandler { public void uncaughtException(Thread thread, Throwable throwabl…

連接と分離記号

まんま module Main where --import Parsec import Text.ParserCombinators.Parsec word :: Parser String word = do{ c <- letter ; do{ cs <- word ; return (c:cs) } <|> return [c] } sentence :: Parser [String] sentence = do{ words <- sepBy1 word …

無名関数みたいな?

#!/usr/bin/env lua f = function() print("f") end f() で、 f

ActiveSupport、Array#to_query

>> require "rubygems" => true >> require "active_support" => true >> [1, 2, 3].to_query("foo") => "foo%5B%5D=1&foo%5B%5D=2&foo%5B%5D=3"

JDK5.0 新機能:キャッチされない例外の取得

「10.3. キャッチされない例外の取得」まんま public class C2008092000 implements Runnable { public void run() { throw new RuntimeException(); } public static void main(String[] args) { Thread thread = new Thread(new C2008092000()); thread.st…

追加される意味

まんま module Main where --import Parsec import Text.ParserCombinators.Parsec nesting :: Parser Int nesting = do{ char '(' ; n <- nesting ; char ')' ; m <- nesting ; return (max (n+1) m) } <|> return 0 run :: Show a => Parser a -> String -…

関数呼び出しの括弧の前で改行はできない

まあ、妥当だろうな #!/usr/bin/env lua function f() print("f") end f() f( ) --f --() で、 f f

ActiveSupport、Array#to_param

>> require "rubygems" => true >> require "active_support" => true >> [1, 2, 3].to_param => "1/2/3" >> ["foo", "bar", "baz"].to_param => "foo/bar/baz"

JDK5.0 新機能:スタックトレースの取得

「10.2. スタックトレースの取得」まんま public class C2008091900 implements Runnable { public void run() { } public static void main(String[] args) { StackTraceElement[] elements = Thread.currentThread().getStackTrace(); for(StackTraceEleme…

予測的なパーサ

まんま module Main where --import Parsec import Text.ParserCombinators.Parsec testOr = string "(a)" <|> string "(b)" testOr1 = do{ char '(' ; char 'a' <|> char 'b' ; char ')' } testOr2 = try (string "(a)") <|> string "(b)" testOr3 = do{ tr…

関数戻り値と括弧

#!/usr/bin/env lua function f() return 1, 2, 3, 4 end a,b,c = 10, f() print(a,b,c) a,b,c = 10, (f()) print(a,b,c) で、 10 1 2 10 1 nilえっー

ActiveSupport、Array#to_sentence

>> require "rubygems" => true >> require "active_support" => true >> [1].to_sentence => "1" >> [1, 2].to_sentence => "1 and 2" >> [1, 2, 3].to_sentence => "1, 2, and 3" >> [1, 2, 3].to_sentence(:connector => "foo") => "1, 2, foo 3" >> ["fo…

JDK5.0 新機能:Retention アノテーション

「9.3. 標準メタアノテーション型」 public class C2008091800 { public static void main(String[] args) { System.out.println(java.lang.annotation.RetentionPolicy.SOURCE); System.out.println(java.lang.annotation.RetentionPolicy.CLASS); System.o…

連接と選択

まんま module Main where --import Parsec import Text.ParserCombinators.Parsec openClose :: Parser Char openClose = do{ char '(' ; char ')' } parens :: Parser () parens = do{ char '(' ; parens ; char ')' ; parens } <|> return () run :: Show…

関数戻り値とテーブル

#!/usr/bin/env lua function f() return 1, 2, 3, 4 end a = {f()} for x in a do print(x) end print("***") a = {f(), nil} for x in a do print(x) end で、 1 2 3 4 *** 1

ActiveSupport、Array#from, Array#to

まんま >> require "rubygems" => true >> require "active_support" => true >> %w( a b c d ).from(0) => ["a", "b", "c", "d"] >> %w( a b c d ).from(2) => ["c", "d"] >> %w( a b c d ).from(10) => nil >> %w( a b c d ).to(0) => ["a"] >> %w( a b c …

JDK5.0 新機能:Target アノテーション

「9.3. 標準メタアノテーション型」 public class C2008091700 { public static void main(String[] args) { System.out.println(java.lang.annotation.ElementType.TYPE); System.out.println(java.lang.annotation.ElementType.FIELD); System.out.println…

一番簡単なパーサ

http://www.lab2.kuis.kyoto-u.ac.jp/~hanatani/tmp/Parsec.html を読んで試すまんま module Main where --import Parsec import Text.ParserCombinators.Parsec simple :: Parser Char simple = letter run :: Show a => Parser a -> String -> IO () run p…

関数戻り値と多重代入

#!/usr/bin/env lua function f() return 1, 2, 3, 4 end a,b,c = f(), 10 print(a,b,c) a,b,c = 10, f() print(a,b,c) a,b,c = f() print(a,b,c) で、 1 10 nil 10 1 2 1 2 3

ActiveSupport、String#to_xs

>> require "rubygems" => true >> require "active_support" => true >> "foo".to_xs => "foo" 何?(マニュアルにはないかも)

JDK5.0 新機能:複数のアノテーションの定義

「9.2. アノテーションの定義」 public @interface C2008091600 { String[] b(); int c(); } と public class C2008091601 { @C2008091600( b={"foo","bar"}, c=10 ) static void a() { System.out.println("a"); } public static void main(String[] args) …

行ごとの処理

良く分からなくなってきた〜(アクションのつけかたに問題???) #!/usr/bin/env perl use strict; use Parse::RecDescent; #$Parse::RecDescent::skip = '[ \t]+'; my $grammar = q{ inputs : line line : /\w+/ "\n" { print "*$item[1]*\n"; } }; my $par…

関数戻り値と引数

#!/usr/bin/env lua function f(x, y, z) print(x, y, z) end function g() return 1, 2 end f(10, g()) f(g(), 3) で、 10 1 2 1 3 nil