summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
Diffstat (limited to 'sample')
-rw-r--r--sample/caller.rb15
-rw-r--r--sample/dbm.rb2
-rw-r--r--sample/export.rb13
-rw-r--r--sample/fib.rb2
-rw-r--r--sample/fib.scm6
-rw-r--r--sample/list3.rb20
-rw-r--r--sample/ruby-mode.el5
-rwxr-xr-xsample/time.rb8
-rwxr-xr-xsample/uumerge.rb27
9 files changed, 80 insertions, 18 deletions
diff --git a/sample/caller.rb b/sample/caller.rb
deleted file mode 100644
index 8988733377..0000000000
--- a/sample/caller.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-def test
- for i in 1..2
- for j in 1..5
- print(j, ": ", caller(j).join(':'), "\n")
- end
- end
-end
-
-def test2
- print(1, ": ", caller(1).join(':'), "\n")
- test()
-end
-
-test2()
-caller()
diff --git a/sample/dbm.rb b/sample/dbm.rb
index 1f2886e026..128391faec 100644
--- a/sample/dbm.rb
+++ b/sample/dbm.rb
@@ -1,6 +1,6 @@
# ruby
#
-d = Dbm.open("test")
+d = DBM.open("test")
for k in d.keys; print(k, "\n"); end
for v in d.values; print(v, "\n"); end
diff --git a/sample/export.rb b/sample/export.rb
new file mode 100644
index 0000000000..3a6a8198df
--- /dev/null
+++ b/sample/export.rb
@@ -0,0 +1,13 @@
+class foo
+ export(\printf)
+end
+
+def foobar
+ print "foobar\n"
+end
+
+f = foo.new
+#foo.unexport(\printf)
+foo.export(\foobar)
+f.foobar
+f.printf "%s\n", foo
diff --git a/sample/fib.rb b/sample/fib.rb
index c72f91f2f2..9fb8b24697 100644
--- a/sample/fib.rb
+++ b/sample/fib.rb
@@ -1,4 +1,4 @@
-def fib (n)
+def fib(n)
if n<2
n
else
diff --git a/sample/fib.scm b/sample/fib.scm
new file mode 100644
index 0000000000..8eba75bb9e
--- /dev/null
+++ b/sample/fib.scm
@@ -0,0 +1,6 @@
+(define (fib n)
+ (if (< n 2)
+ n
+ (+ (fib (- n 2)) (fib (- n 1)))))
+
+(fib 20)
diff --git a/sample/list3.rb b/sample/list3.rb
new file mode 100644
index 0000000000..c38e5bfb43
--- /dev/null
+++ b/sample/list3.rb
@@ -0,0 +1,20 @@
+# Linked list program -- short version
+class Point
+ def Point.new(x, y)
+ super.init(x, y)
+ end
+
+ def init(x, y)
+ @x = x; @y = y
+ self
+ end
+
+ def to_s
+ sprintf("%d@%d", @x, @y)
+ end
+end
+
+list1 = [10, 20, Point.new(2, 3), Point.new(4, 5)]
+list2 = [20, Point.new(4, 5), list1]
+print("list1: ", list1._inspect, "\n")
+print("list2: ", list2._inspect, "\n")
diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el
index 8f864d3846..7f97e71c54 100644
--- a/sample/ruby-mode.el
+++ b/sample/ruby-mode.el
@@ -18,7 +18,7 @@
(defconst ruby-block-end-re "end")
(defconst ruby-delimiter
- (concat "[/<(){}#\"'`]\\|\\[\\|\\]\\|\\b\\("
+ (concat "[$/<(){}#\"'`]\\|\\[\\|\\]\\|\\b\\("
ruby-block-beg-re "\\|" ruby-block-end-re "\\)\\b")
)
@@ -55,6 +55,7 @@
;;(modify-syntax-entry ?\n ">" ruby-mode-syntax-table)
;;(modify-syntax-entry ?\f ">" ruby-mode-syntax-table)
(modify-syntax-entry ?# "<" ruby-mode-syntax-table)
+ (modify-syntax-entry ?$ "/" ruby-mode-syntax-table)
(modify-syntax-entry ?\\ "'" ruby-mode-syntax-table)
(modify-syntax-entry ?_ "w" ruby-mode-syntax-table)
(modify-syntax-entry ?< "." ruby-mode-syntax-table)
@@ -193,6 +194,8 @@ The variable ruby-indent-level controls the amount of indentation.
nil
(goto-char indent-point)
(setq in-string t))))))
+ ((string= "$" w) ;skip $char
+ (forward-char 1))
((string= "#" w) ;skip comment
(forward-line 1))
((string= "(" w) ;skip to matching paren
diff --git a/sample/time.rb b/sample/time.rb
new file mode 100755
index 0000000000..b0ef065ce3
--- /dev/null
+++ b/sample/time.rb
@@ -0,0 +1,8 @@
+#! /usr/local/bin/ruby
+cmd = $ARGV.join(" ")
+b = Time.now
+system(cmd)
+e = Time.now
+ut, st, cut, cst = Time.times
+total = (e - b).to_f
+printf $stderr, "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst
diff --git a/sample/uumerge.rb b/sample/uumerge.rb
new file mode 100755
index 0000000000..420a3924b6
--- /dev/null
+++ b/sample/uumerge.rb
@@ -0,0 +1,27 @@
+#!/usr/local/bin/ruby
+
+while gets()
+ if /^begin\s*(\d*)\s*(\S*)/
+ $mode, $file = $1, $2
+ $sawbegin+=1
+ break
+ end
+end
+
+fail "missing begin" unless $sawbegin;
+OUT = open($file, "w") if $file != "";
+
+while gets()
+ if /^end/
+ $sawend+=1
+ break
+ end
+ sub(/[a-z]+$/, ""); # handle stupid trailing lowercase letters
+ continue if /[a-z]/
+ continue unless ((($_[0] - 32) & 077) + 2) / 3 == $_.length / 4
+ OUT << $_.unpack("u");
+end
+
+fail "missing end" unless $sawend;
+File.chmod $mode.oct, $file;
+exit 0;