Sha256: 9cf6aa72a826f20050d451149559ac7a18399b3ebc1636a6c8ed095c852f7957

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module PLang
  module VM
    module PFunctions
      def add_to_interpreter_string_functions
        
        def_object_message "{string: x}", :at do |object|
          plambda "{integer: y}" do |value|
            PObject.new(:char, [object.params[0][value[0].params[0]]])
          end
        end
        
        def_object_message "{string: x}", :concat do |object|
          plambda "{string: y}" do |value|
            PObject.new(:string, [object.params[0] + value[0].params[0]])
          end
        end
        
        def_object_message "x", :to_string do |object|
          plambda do |value|
            PObject.new(:string, [object.to_s])
          end
        end

        def_object_message "{string: x}", :to_integer do |object|
          plambda do |value|
            PObject.new(:integer, [object.params[0].to_i])
          end
        end

        def_object_message "{string: x}", :to_decimal do |object|
          plambda do |value|
            PObject.new(:decimal, [object.params[0].to_f])
          end
        end
        
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
p-lang-0.3.1 lib/vm/core/pstring.rb
p-lang-0.3.0 lib/vm/core/pstring.rb