Module: Kl::Primitives::Streams

Included in:
Environment
Defined in:
lib/kl/primitives/streams.rb

Instance Method Summary collapse

Instance Method Details

#close(stream) ⇒ Object



32
33
34
35
# File 'lib/kl/primitives/streams.rb', line 32

def close(stream)
  stream.close
  :NIL
end

#open(stream_type, name, direction) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/kl/primitives/streams.rb', line 24

def open(stream_type, name, direction)
  unless stream_type == :file
    raise Kl::Error, "unsupported stream type: #{stream_type}"
  end
  File.open(File.expand_path(name, value(:'*home-directory*')),
            direction == :out ? 'w' : 'r')
end

#pr(s, stream) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/kl/primitives/streams.rb', line 4

def pr(s, stream)
  if stream == STDIN
    # shen-prbytes in toplevel.kl calls pr on *stinput* rather than
    # *stoutput*. As a temporary solution, use the same approach
    # that Bruno Deferrari uses in his Scheme port. See
    # https://groups.google.com/d/topic/qilang/2ixosqX4Too/discussion
    stream = STDOUT if stream == STDIN
  end
  stream.write(s)
  s
end