Sha256: c0316be6da12b2730cde52248587a7bd378a22cce62b59d58e7c242962e556eb

Contents?: true

Size: 982 Bytes

Versions: 7

Compression:

Stored size: 982 Bytes

Contents

module Kl
  module Primitives
    module Vectors
      def absvector(n)
        raise Kl::Error, "#{n} is not a number" unless n.kind_of? Fixnum
        raise Kl::Error, "#{n} must be >= 0" unless n >= 0
        Kl::Absvector.new(n)
      end

      define_method 'address->' do |v, n, value|
        raise Kl::Error, "#{v} is not a vector" unless v.kind_of? Kl::Absvector
        raise Kl::Error, "#{n} is not a number" unless n.kind_of? Fixnum
        if n < 0 || n >= v.upper_limit
          raise Kl::Error, "out of bounds"
        end

        v[n] = value
        v
      end

      define_method '<-address' do |v, n|
        raise Kl::Error, "#{v} is not a vector" unless v.kind_of? Kl::Absvector
        raise Kl::Error, "#{n} is not a number" unless n.kind_of? Fixnum
        if n < 0 || n >= v.upper_limit
          raise Kl::Error, "out of bounds"
        end

        v[n]
      end

      def absvector?(v)
        v.kind_of? Kl::Absvector
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shen-ruby-0.10.0 lib/kl/primitives/vectors.rb
shen-ruby-0.9.0 lib/kl/primitives/vectors.rb
shen-ruby-0.8.1 lib/kl/primitives/vectors.rb
shen-ruby-0.8.0 lib/kl/primitives/vectors.rb
shen-ruby-0.7.0 lib/kl/primitives/vectors.rb
shen-ruby-0.6.0 lib/kl/primitives/vectors.rb
shen-ruby-0.5.0 lib/kl/primitives/vectors.rb