Cuneiform Ruby
July 3, 2009
I’m guessing that you don’t have a cuneiform font installed. Install one now.
Cuneiform characters were officially assigned Unicode points in 2006. None of these points are in the Basic Multilingual Plane. A lot of software which claims to handle Unicode cannot handle points outside of the BMP. For example, before version 1.5 java assumed all characters could fit into 16 bits. So cuneiform is a good test of the system.
Ruby 1.9 extends the \u notation for entering Unicode points in strings:
bash$ irb
irb(main):001:0> puts "\u{1204C}"
𒁌
Better yet, use cuneiform as a variable
bash$ cat cuneiform.rb # encoding: utf-8 𒀻 = 13 puts 𒀻 bash$ ruby cuneiform.rb 13
I had better luck with vi than emacs editing the file. There were display issues. Beacuse 𒀻 is quite wide for a single character and Terminal is fixed width, the cuneiform character was overlapping the characters that follow it.
bash$ cat cuneiform.rb
# encoding: utf-8
class 𒀽
def puts
puts "I am cuneiform: \u{1203D}"
end
end
c = 𒀽.new
c.puts
bash$ ruby cuneiform.rb
cuneiform.rb:3: class/module name must be CONSTANT
So this tells us that Ruby considers the character to be lower case. Ruby doesn’t appear to recognize any non-ASCII capital letters in source code:
bash$ cat greek.rb
#encoding: utf-8
class Λ
def initialize(λ)
@λ = λ
end
def apply(*a)
@λ.call(*a)
end
end
λ = Λ.new(lambda { |x,y| x+y })
puts λ.apply(3,7)
bash$ ruby greek.rb
greek.rb:2: class/module name must be CONSTANT
Ruby is aware of capitals in strings:
irb(main):010:0> s = "\u039B"; puts s; /\p{Upper}/.match(s)
Λ
=> #<MatchData "Λ">
irb(main):011:0> s = "\u03BB"; puts s; /\p{Upper}/.match(s)
λ
=> nil
irb(main):012:0> s = "\u{12040}"; puts s; /\p{Upper}/.match(s)
𒁀
=> nil
We can use Unicode in symbols:
# encoding: utf-8
alias :λ :lambda
add = λ { |x,y| x + y }
puts add.call(3,11)