summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-02-17 14:08:43 +0000
committerpaltherr <paltherr@epfl.ch>2003-02-17 14:08:43 +0000
commite0b8cd4966d3453cf2e1817e18a85c314723a17a (patch)
tree81677ab0b28a28fdaa867fc3df41f61ee9de4515
parentae4ce8d3c477e4cc2ad08a731a964bd0b6e40afc (diff)
downloadscala-e0b8cd4966d3453cf2e1817e18a85c314723a17a.tar.gz
scala-e0b8cd4966d3453cf2e1817e18a85c314723a17a.tar.bz2
scala-e0b8cd4966d3453cf2e1817e18a85c314723a17a.zip
- Added Tuple.scm and Tuple.tmpl
-rw-r--r--sources/scala/Tuple.scm49
-rw-r--r--sources/scala/Tuple.tmpl24
2 files changed, 73 insertions, 0 deletions
diff --git a/sources/scala/Tuple.scm b/sources/scala/Tuple.scm
new file mode 100644
index 0000000000..081690b08b
--- /dev/null
+++ b/sources/scala/Tuple.scm
@@ -0,0 +1,49 @@
+;; This rule file defines the environment for the expansion of
+;; Tuple.tmpl template.
+;;
+;; It defines the following variables:
+;;
+;; Name Meaning Value for Tuple2
+;; -----------------------------------------------------
+;; n Arity of the tuple 2
+;; type-params Type parameters [T1, T2]
+;; value-params Value parameters _1: T1, _2: T2
+;; equal Equality test (_1 == that._1) && (_2 == that._2)
+;; hash-code Body of hashCode() _1.hashCode() ^ _2.hashCode()
+;; to-string Body of toString() "(" + _1 + "," + _2 + ")"
+
+(define (repeated-string f n sep)
+ (string-join (map f (list-tabulate n (lambda (x) (+ x 1)))) sep))
+
+(define (make-type-params n)
+ (string-append "[" (repeated-string (lambda (i) (format #f "T~a" i)) n ", ") "]"))
+
+(define (make-value-params n)
+ (repeated-string (lambda (i) (format #f "_~a: T~a" i i)) n ", "))
+
+(define (make-equal n)
+ (repeated-string (lambda (i) (format #f "(_~a == that._~a)" i i)) n " && "))
+
+(define (make-hash-code n)
+ (repeated-string (lambda (i) (format #f "_~a.hashCode()" i)) n " ^ "))
+
+(define (make-to-string n)
+ (string-append
+ "\"(\" + "
+ (repeated-string (lambda (i) (format #f "_~a" i)) n " + \",\" + ")
+ " + \")\""))
+
+(define file-name-rx (rx "Tuple" (submatch (+ digit)) ".scala"))
+
+(define (make-env target-file)
+ (let ((match (regexp-search file-name-rx target-file)))
+ (if match
+ (let ((n (string->number (match:substring match 1))))
+ (list (cons 'n (number->string n))
+ (cons 'type-params (make-type-params n))
+ (cons 'value-params (make-value-params n))
+ (cons 'equal (make-equal n))
+ (cons 'hash-code (make-hash-code n))
+ (cons 'to-string (make-to-string n))))
+ (error "invalid file name" target-file))))
+
diff --git a/sources/scala/Tuple.tmpl b/sources/scala/Tuple.tmpl
new file mode 100644
index 0000000000..a04d34c613
--- /dev/null
+++ b/sources/scala/Tuple.tmpl
@@ -0,0 +1,24 @@
+// [#do-not-edit#]
+
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala with {
+ case class Tuple[#n#][#type-params#]([#value-params#]) extends scala.Object with {
+
+ override def hashCode() = [#hash-code#];
+
+ override def == (other: Any) =
+ if (other.is[Tuple[#n#][#type-params#]]) {
+ val that = other.as[Tuple[#n#][#type-params#]];
+ [#equal#]
+ } else Boolean.False;
+
+ override def toString() = [#to-string#];
+ }
+}