[#5219] ruby for perl users — Noritsugu Nakamura <nnakamur@...>

35 messages 1997/11/09
[#5220] Re: ruby for perl users — tateishi@... (Tateishi Takaaki) 1997/11/09

立石です。

[#5224] Re: ruby for perl users — shugo@... (Shugo Maeda) 1997/11/09

前田です。

[#5243] read from subprocess — Kikutani Makoto <kikutani@...>

きくたにです。

17 messages 1997/11/10
[#5250] Re: read from subprocess — matz@... (Yukihiro Matsumoto) 1997/11/11

まつもと ゆきひろです

[#5300] Win32用の Rubyでの tkの使用 — Tomoaki Takebayashi <tota@...>

はじめまして、竹林といいます。

14 messages 1997/11/15
[#5302] Re: Win32用の Rubyでの tkの使用 — WATANABE Hirofumi <eban@...> 1997/11/15

わたなべです.

[#5303] Re: Win32 用の Rubyでの tkの使用 — Tomoaki Takebayashi <tota@...> 1997/11/15

[#5305] Re: Win32 用の Ruby での tk の使用 — aito@...5sun.yz.yamagata-u.ac.jp 1997/11/17

あ伊藤です.

[#5320] ruby 1.0-971118 released — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

20 messages 1997/11/18
[#5337] Re: ruby 1.0-971118 released — WATANABE Hirofumi <watanabe@...> 1997/11/19

わたなべです.

[#5340] Re: ruby 1.0-971118 released — matz@... (Yukihiro Matsumoto) 1997/11/19

まつもと ゆきひろです

[#5398] 配列への追加について — a-nisida@... (西田明良)

はじめまして、西田@初心者 と申します。m(..)m

16 messages 1997/11/22

[ruby-list:5322] Questions on specs and threads

From: Kazuhisa Yanagawa <katze@...>
Date: 1997-11-18 06:45:18 UTC
List: ruby-list #5322
  はじめまして. 読んでただけで今まで書いたことが無かったものです.

  最近になって細かなスクリプトや, あそびで lisp interpreter を書いてみ
  たりしはじめました. で, 「少しは還元しようか」ということで印象や疑問
  を書いてみようと思います....

  1) case 文について

     case 文で when 節に配列を書くとマッチしません.

       case 1
         when [1, 2, 3]
           print 1
       end
       ==> nil

     ここで

       a = [1, 2, 3]
       def a.===(o)
         self.include? o
       end

     とすると

       case 1
         when a
           1
       end
       ==> 1

     となります. こっちのほうが嬉しくはないでしょうか?

  2) typecase

     typecase のようなものはいりませんでしょうか? if-elsif-else-end で
     十分という意見は確かにあるのですが.

       typecase foo
         when Nil                  if foo.is_a? nil      
           ...            <==>       ...                 
         when String               elsif foo.is_a? String
           ...                       ...                 
       end                         end                   

     t = foo.type; case t ... end でもいいかと思ったけどこれだとサブク
     ラスがマッチしませんし.

  3) 記号的な記法

     これは単なる私の趣味ですが, 単項インクリメントとかがたまに欲しく
     なります. i += 1 でいいわけですが. i++ と書いて怒られる (^^;

     SR 風な(CSP 風な?)

       if condition1
         ...
       [] condition2
         ...
       [] else
         ...
       end

     なんてのも好きかもしれない.

  4) thread についての疑問

     これは今までのとは何の関係もありませんが....最後に付けたようなス
     クリプトがデッドロックします. 結局は Queue#push に変な引数を与え
     るのが悪いのですが, なんで Wrong # of arguments(3 for 1) とかにな
     らないのかが理解できません.

     # 仕様? 1.0-971021 まではずっとこう. ちなみに sparc-solaris2.4.

  5) どこかに exception の一覧があったりしないでしょうか. TypeError と 
     RuntimeError ぐらいしか把握できなかったりするんですが.

     # lisp を書いてて raise するときそれぐらいしか使えなかった. もっ
     # ともあんまり真面目に書いてないんで, 例外を起こすことのほうがま
     # れではありますが (^^;

始めて書くにしては要求ばかりな上に長いのね....
===========================================================================
  柳川 @ 情報システム学研究科 . 電気通信大学
  katze@yuba.is.uec.ac.jp                            November 18th, 1997.  
# 明日は明日の桶屋が儲かる


===========================================================================
# 大雑把に言って, active object の手抜きな実装....のプロトタイプ.
# Actor は send で送られて来たメッセージを disp でディスパッチしたい.

require "thread"

class Actor
  def initialize
    print "Actor started.\n"
    @q = Queue.new
    Thread.start {disp}
    print "end init\n"
  end
  
  def disp
    print "disp started.\n"
    while TRUE
      print "    gets message from queue.\n"
      m = @q.pop
      print "    shows message.\n"
      meth m
    end
  end
  
  def meth(m)
    print "    ", m, "\n"
  end
  
  def send(m)
    print "    recieved ", m, "\n"
    @q.push m
  end
end

def proc(p, n)
  print "proc ", n, " started.\n"
  while TRUE
    sleep rand 5
    print "proc ", n, " sends.\n"
    # p.send の引数を [] で括ると意図した通りに動く. 以下のままだと 
    # 引っかかってしまうようだ(error にもならない).
    p.send "proc ", n, " living.\n"
    print "proc ", n, " ends send.\n"
  end
end

p = Actor.new

for i in 0..9
  Thread.start {proc(p, i)}
end
sleep

In This Thread

Prev Next