Class: Lisp::Character

Inherits:
Atom show all
Defined in:
lib/rubylisp/character.rb

Constant Summary collapse

@@character_constants =
{}

Instance Attribute Summary

Attributes inherited from Atom

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Atom

#all?, #apply_to, #car, #cdr, #class?, #copy, #doc, #environment?, #eof_object?, #eq?, #equal?, #evaluate, #false?, #frame?, #function?, #length, #lisp_object?, #list?, #macro?, #negative?, #number?, #object?, #pair?, #port?, #positive?, #primitive?, #quoted, #set_location, #special?, #string?, #symbol?, #true?, #vector?, #zero?

Constructor Details

#initialize(n) ⇒ Character

Returns a new instance of Character.



6
7
8
# File 'lib/rubylisp/character.rb', line 6

def initialize(n)
  @value = n
end

Class Method Details

.character_constantsObject



100
101
102
# File 'lib/rubylisp/character.rb', line 100

def self.character_constants()
  @@character_constants
end

.with_value(n) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/rubylisp/character.rb', line 105

def self.with_value(n)
  if n.length == 1
    ch = Lisp::PrimCharacter.find_character_for_chr(n[0])
    return ch unless ch.nil?
    ch = self.new(n[0])
    @@character_constants[n] = ch
    ch
  elsif @@character_constants.has_key?(n)
    @@character_constants[n]
  elsif n[0..1] == "U+"
    Lisp::PrimCharacter.find_character_for_chr(n[2..-1].to_i(16).chr)
  else
    return Lisp::Debug.process_error("Invalid character name: #{n}", Lisp::EnvironmentFrame.global)
  end
end

Instance Method Details

#character?Boolean

Returns:



16
17
18
# File 'lib/rubylisp/character.rb', line 16

def character?
  true
end

#eqv?(other) ⇒ Boolean

Returns:



21
22
23
24
# File 'lib/rubylisp/character.rb', line 21

def eqv?(other)
  return false unless other.character?
  @value == other.value
end

#find_characternameObject



42
43
44
45
# File 'lib/rubylisp/character.rb', line 42

def find_charactername
  @@character_constants.each {|k, v| return k if v == self}
  "UNKNOWN"
end


48
49
50
# File 'lib/rubylisp/character.rb', line 48

def print_string
  return "#\\#{find_charactername}"
end

#set!(n) ⇒ Object



11
12
13
# File 'lib/rubylisp/character.rb', line 11

def set!(n)
  @value = n
end

#to_sObject



32
33
34
# File 'lib/rubylisp/character.rb', line 32

def to_s
  @value
end

#to_symObject



37
38
39
# File 'lib/rubylisp/character.rb', line 37

def to_sym
  @value.to_sym
end

#typeObject



27
28
29
# File 'lib/rubylisp/character.rb', line 27

def type
  :character
end