From: ptkwt@... (Phil Tomson) Date: 2003-11-21T06:52:16+09:00 Subject: Re: Partial Euphoric Type Checking In article , 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: Why does Matz need to add any sugar? You show how it can be done above. Sure, it would make what you're trying to do look a little nicer, but why don't you just release your code above as a module on the RAA and document it nicely and then people can use it if they wish (and not use it if they wish). > > class TypeTest > type big4(x) > x > 4 > end > def ameth(big4 x) > puts x > end > end > >would that quell the need? It's got it's uses but I wouldn't hold my breath for any sugar ;-) Phil