From: Sean O'Dell Date: 2003-11-21T06:16:19+09:00 Subject: Re: Partial Euphoric Type Checking On Thursday 20 November 2003 12:52 pm, T. Onoma wrote: > Greetings all Type Checkers! > > I have implemented a version of euphoria's type system in Ruby. > > # the good stuff > > module Kernel > def typechecking(x=nil) > return $_tc if x == nil > $_tc = x ? true : false > end > end > > class Module > def type(tname, &check) > define_method(tname) do |*v| > if $_tc > unless v.all? { |y| check.call(y) } > raise TypeError > end > end > return *v > end > end > end > > # demonstrate how it feels > > class TypeTest > type :big4 do |x| > x > 4 > end > def ameth(x) > # -- type checking -- > big4 x > # -- rest of code -- > puts x > end > end > > typechecking true # turn type checking on > t = TypeTest.new > t.ameth(5) # => 5 > t.ameth(2) # => TypeError > > Now if you can just get matz to add a little sytax sugar for type and > inline parameter methods: > > class TypeTest > type big4(x) > x > 4 > end > def ameth(big4 x) > puts x > end > end > > would that quell the need? In some ways, but it's written in Ruby, and it doesn't look like it can check available object methods without slipping in Ruby code to do so. It falls under the category of "third-party kludge" because it's doing a job that most people assume the language implementation itself would provide. I can't imagine this would be terribly efficient, either. Sean O'Dell