Sha256: ea8f9eb38f66c284ff90b567f4c2563e2d8058798e8de182889aaa01747241df

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require "shuwar/stdlib"

module Shuwar::Stdlib
  module Base
    VALUES = {
        load: lambda do |lib|
          load_lib lib
        end,

        begin: lambda do |*vals|
          vals[-1]
        end,

        print: lambda do |*vals|
          vals.each {|a| p a}
        end,

        puts: lambda do |*vals|
          puts *vals
        end
    }

    MARCOS = {
        quote: lambda do |val|
          val
        end,

        set: lambda do |key, val|
          set_value key, evaluate(val)
        end,

        lambda: lambda do |args, *body|
          if body.one?
            env = self # Avoiding self trouble
            lambda do |*as|
              raise "Expecting #{args.size} args, got #{as.size}" unless as.size == args.size
              e = env.dup
              (0...as.size).each do |i|
                env.set_value args[i], as[i]
              end

              e.evaluate body[0]
            end
          else
            evaluate [:lambda, args, [:begin, *body]]
          end
        end
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shuwar-1.2.0 lib/shuwar/stdlib/base.rb