untitled

Similar documents
Ruby演習テキスト1

Microsoft PowerPoint - ruby_instruction.ppt

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

「プログラミング言語」 SICP 第4章 ~超言語的抽象~ その6


¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

r1.dvi

10 (1) s 10.2 rails c Rails 7 > item = PlanItem.new => #<PlanItem id nil, name nil,...> > item.name = "" => "" > item.valid? => true valid? true false

Microsoft PowerPoint - 11RubyIntro-No02.ppt [互換モード]

RubyKaigi2009 COBOL




8 if switch for while do while 2

K227 Java 2

離散数理工学 第 2回 数え上げの基礎:漸化式の立て方

untitled

fp.gby

parser.y 3. node.rb 4. CD-ROM

15 Phoenix HTML 15.1 ModestGreeter RAVT web/router.ex web/router.ex : 12 scope "/", ModestGreeter do 13 pipe_through :browser get "/", TopCont

Ruby 50 Ruby UTF print, \n [Ruby-1] print("hello, Ruby.\n") [Ruby-2] Hello, Ruby. [Ruby-3] print("hello, \"Ruby\".\n") 2 [Ruby-4] seisuu = 10 pr

untitled

Java演習(4) -- 変数と型 --

haskell.gby

Kyosuke MOROHASHI

(Eclipse\202\305\212w\202\324Java2\215\374.pdf)

離散数理工学 第 2回 数え上げの基礎:漸化式の立て方

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

: : : TSTank 2

ohp07.dvi

226

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

自己紹介 前田修吾(Shugo Maeda) Schemeと同い年 家族 奥さん 娘 息子 NaCl勤務(1999 )

Ruby Ruby ruby Ruby G: Ruby>ruby Ks sample1.rb G: Ruby> irb (interactive Ruby) G: Ruby>irb -Ks irb(main):001:0> print( ) 44=>

Windows [ ] [ (R)..] cmd [OK] Z:\> mkdir progi [Enter] \ ) mkdir progi ) (command ) help [Enter] help ( help ) mkdir make directory Windows ) mkdir mk

.NETプログラマー早期育成ドリル ~VB編 付録 文法早見表~

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

3 Powered by mod_perl, Apache & MySQL use Item; my $item = Item->new( id => 1, name => ' ', price => 1200,

明解Java入門編

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");



Windows Cygwin Mac *1 Emacs Ruby ( ) 1 Cygwin Bash Cygwin Windows Cygwin Cygwin Mac 1 Mac 1.2 *2 ls *3 *1 OS Linux *2 *3 Enter ( ) 2

P03.ppt

23回会社説明会資料(HP用)

listings-ext

明解Javaによるアルゴリズムとデータ構造

Sinatra と MongoDB 今回は Sinatra で MongoDB の操作を体験してみます 進捗に合わせて ドライバから Ruby で使える便利な ORM の紹介をします

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1

(CC Attribution) Lisp 2.1 (Gauche )

今日からはじめるプロアクティブ

サイボウズ ガルーン 3 管理者マニュアル

H1_H4_ ai

P indd


85

1


1 2 STEP 1 STEP 2 STEP 3

1


untitled

制御盤BASIC Vol.3

altus_storage_guide

橡matufw

untitled

O


財団法人母子健康協会第三十回シンポジウム

NewBead_no17_4c_pdf.indd

PowerPoint Presentation


8 4 end 5 6 private def message 7 'Hello' 8 end 9 end g = Greeting.new 12 g.hello $ ruby lib/lessons/greeting.rb Hello Ruby public method protec

6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent thread, 1 GUI 6.0.2, mutlithread C

新・明解Javaで学ぶアルゴリズムとデータ構造

新・明解Java入門

JEB Plugin 開発チュートリアル 第4回

1_cover

r9.dvi

Microsoft PowerPoint - Ruby n

Java updated

コンピュータ概論

Appendix A BASIC BASIC Beginner s All-purpose Symbolic Instruction Code FORTRAN COBOL C JAVA PASCAL (NEC N88-BASIC Windows BASIC (1) (2) ( ) BASIC BAS

Java学習教材

コーディング基準.PDF

1 Ex Ex. 2 2

r02.dvi

明解Javaによるアルゴリズムとデータ構造

ruby novice ruby novice ruby novice.

An introduction and future of Ruby coverage library

Rubyのしくみ:Ruby Under a Microscope

ohp02.dvi

untitled

Microsoft PowerPoint - 13Kadai.pptx

数理.indd

PowerPoint Presentation

I 1 1 ( *) ( *) ex1-1.rb ) 2 CGI


ALG2012-A.ppt

Transcription:

30 callcc yhara ( ( )

(1) callcc (2) callcc (3) callcc

callcc Continuation callcc

(1) (2) (3)

(1) (2) (3) (4)

class Foo def f p 1 callcc{ cc return cc} p 2 class Bar def initialize @cc = Foo.new.f def g p 3 @cc.call p 4 Bar.new.g

Matz?

class Matumoto 89

callcc callcc cc.call $cc = nil def hoge print 1 callcc{ cc $cc = cc} print 3 hoge $cc.call cc.call callcc (cc ) cc Continuation

callcc callcc cc.call $cc = nil def hoge print 1 callcc{ cc $cc = cc} print 2 hoge $cc.call cc.call callcc (cc ) cc Continuation

callcc callcc{} cc.call(arg) arg ( ) $cc = nil def hoge print 1 print callcc{ cc $cc = cc; 2} print 3 hoge $cc.call(4) # 1 2 3 4 3 4 3 4

callcc{ cc } # cc cc.call callcc

callcc

(1) 3 for i in (0..10) for j in (0..10) for k in (0..10) if i==j && j==k #

(1) 3 callcc{ cc for i in (0..10) for j in (0..10) for k in (0..10) if i==j && j==k cc.call } (callcc )

catch catch catch/throw catch(:escape){ for i in (0..10) for j in (0..10) for k in (0..10) if i==j && j==k throw :escape }

(2) def event king.say( #{@name} ) wait_ok king.say( ) wait_ok king.say( #{@name} ) wait_ok until input[ ok ] # sleep 1 #

( ) def event(input) case @step when 0 king.say #{@name} @step += 1 when 1 @step += 1 if input[ ok ] when 2 king.say @step += 1 when 3 @step += 1 if input[ ok ] when 4 king.say #{@name}

callcc wait_ok return def event king.say( #{@name} ) wait_ok king.say( ) wait_ok king.say( #{@name} )

(3) baker 5F cooper 1F miller cooper smith fletcher 1

for baker in 1, 2, 3, 4, 5 for cooper in 1, 2, 3, 4, 5 for fletcher in 1, 2, 3, 4, 5 for miller in 1, 2, 3, 4, 5 for smith in 1, 2, 3, 4, 5 if baker!= 5 && cooper!= 1 && fletcher!= 1 && fletcher!= 5 && miller > cooper return [baker,cooper,fletcher,miller,smith]

callcc require "amb A = Amb.new baker = A.choose(1, 2, 3, 4, 5) # 1 5 cooper = A.choose(1, 2, 3, 4, 5) fletcher= A.choose(1, 2, 3, 4, 5) miller = A.choose(1, 2, 3, 4, 5) smith = A.choose(1, 2, 3, 4, 5) A.assert([baker, cooper, fletcher, miller, smith].uniq.length == 5) A.assert(baker!= 5) A.assert(cooper!= 1) A.assert(fletcher!= 1 && fletcher!= 5) A.assert(miller > cooper) A.assert((smith - fletcher).abs!= 1) A.assert((fletcher - cooper).abs!= 1) p [baker, cooper, fletcher, miller, smith]

(4) each C++ requrie generator ( ) g = Generator.new([1,2,3]) while g.next? p g.next

(5) ppp p irb> p x 3 irb> p x=#{x} x=3 binding irb> ppp :x x=3

binding binding def ppp(symbol) set_trace_func{ *args.. cc.call(eval( binding )} b = callcc{ cc..} if state == :prepare return else puts #{symbol} = #{eval(symbol, b)} a = 1 ppp :a Ruby 3 eval (eval, *_eval) (*_missing, set_trace_func) callcc

binding binding def ppp(symbol) set_trace_func{ *args.. cc.call(eval( binding )} b = callcc{ cc..} if state == :prepare return else puts #{symbol} = #{eval(symbol, b)} a = 1 ppp :a

Binding.of_caller Rails (ActiveSupport) 1.8.5 ppp http://www.rubyist.net/~rubikitch/computer/ppp/

callcc

(Ruby ) Ruby [BUG] Segmentation fault: core Rubyist Magazine Ruby (akr) http://jp.rubyist.net/magazine/?0002-rubycore

foo do puts hello puts world

static VALUE rb_foo(value ary1) { } int *p = malloc(...); rb_yield(); free(*p); foo do puts hello puts world

static VALUE rb_foo(value ary1) { } int *p = malloc(...); rb_yield(); free(*p); foo do callcc{ $cc } puts hello puts world $cc.call

static VALUE rb_foo(value ary1) { } int *p = malloc(...); rb_yield(); free(*p); 2 free foo do callcc{ $cc } puts hello puts world $cc.call

callcc

callcc

callcc callcc Ruby

Fiber

callcc Fiber callcc (A) / (generator, wait_ok) (B) (amb, ppp) callcc (B) (A) 1.9 Fiber

Fiber Fiber( ) Thread( ) Thread new Fiber#yield Fiber Fiber (Fiber.prev) foo = Fiber.new{ p 2 Fiber.prev.yield } bar = Fiber.new{ p 1 foo.yield p 3 } bar.yield #1 2 3

1.9 Ruby1.9 Fiber -@IT ( ) callcc Fiber Fiber callcc callcc Fiber 1.9.x