From 55b6a3f313670d2cb13847d1f1b04fe3e4b21d63 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 8 Apr 2010 20:09:16 +0000 Subject: Tuplr -> Resp (RESource Processing). git-svn-id: http://svn.drobilla.net/resp/resp@252 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- test/ack.resp | 7 +++ test/ack.tpr | 7 --- test/def.resp | 8 +++ test/def.tpr | 8 --- test/fac.resp | 7 +++ test/fac.tpr | 7 --- test/intro.resp | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/intro.tpr | 148 -------------------------------------------------------- test/nest.resp | 6 +++ test/nest.tpr | 6 --- test/poly.resp | 6 +++ test/poly.tpr | 6 --- test/tup.resp | 6 +++ test/tup.tpr | 6 --- 14 files changed, 188 insertions(+), 188 deletions(-) create mode 100644 test/ack.resp delete mode 100644 test/ack.tpr create mode 100644 test/def.resp delete mode 100644 test/def.tpr create mode 100644 test/fac.resp delete mode 100644 test/fac.tpr create mode 100644 test/intro.resp delete mode 100644 test/intro.tpr create mode 100644 test/nest.resp delete mode 100644 test/nest.tpr create mode 100644 test/poly.resp delete mode 100644 test/poly.tpr create mode 100644 test/tup.resp delete mode 100644 test/tup.tpr (limited to 'test') diff --git a/test/ack.resp b/test/ack.resp new file mode 100644 index 0000000..76fb397 --- /dev/null +++ b/test/ack.resp @@ -0,0 +1,7 @@ +(def (ack m n) + (if (= 0 m) (+ n 1) + (= 0 n) (ack (- m 1) 1) + (ack (- m 1) (ack m (- n 1))))) + +(ack 3 10) + diff --git a/test/ack.tpr b/test/ack.tpr deleted file mode 100644 index 76fb397..0000000 --- a/test/ack.tpr +++ /dev/null @@ -1,7 +0,0 @@ -(def (ack m n) - (if (= 0 m) (+ n 1) - (= 0 n) (ack (- m 1) 1) - (ack (- m 1) (ack m (- n 1))))) - -(ack 3 10) - diff --git a/test/def.resp b/test/def.resp new file mode 100644 index 0000000..dd9a0c8 --- /dev/null +++ b/test/def.resp @@ -0,0 +1,8 @@ +(def foo + (fn (x) + (def y 2) + (def z 3) + z)) + +(foo 3) + diff --git a/test/def.tpr b/test/def.tpr deleted file mode 100644 index dd9a0c8..0000000 --- a/test/def.tpr +++ /dev/null @@ -1,8 +0,0 @@ -(def foo - (fn (x) - (def y 2) - (def z 3) - z)) - -(foo 3) - diff --git a/test/fac.resp b/test/fac.resp new file mode 100644 index 0000000..0fb687c --- /dev/null +++ b/test/fac.resp @@ -0,0 +1,7 @@ +; Factorial +(def (fac n) + (if (= 0 n) 1 + (* n (fac (- n 1))))) + +(fac 6) + diff --git a/test/fac.tpr b/test/fac.tpr deleted file mode 100644 index 0fb687c..0000000 --- a/test/fac.tpr +++ /dev/null @@ -1,7 +0,0 @@ -; Factorial -(def (fac n) - (if (= 0 n) 1 - (* n (fac (- n 1))))) - -(fac 6) - diff --git a/test/intro.resp b/test/intro.resp new file mode 100644 index 0000000..bf8d8c8 --- /dev/null +++ b/test/intro.resp @@ -0,0 +1,148 @@ +;;; NOTE: This document is just a draft idea sketch pad + +;;; Data types + +; Resp uses algebraic datatypes which can also be used in an +; object based style with more flexibility than typical of +; languages with algebraic datatypes +; +; There is a single way of defining a type (the 'type' form) which +; encompasses unions, records, objects, etc. + +; A type is a discriminated union ("or") of types. +; Type names (including variables) always start with an uppercase letter. + +; There are many equivalent terms for kinds of types. We uniformly use: +; "Union" : "and", sum type +; "Record" : "or", product type, object, struct + +; Example: A Tree is a Node with a value and left/right children, or Nothing +; "Nothing" and "Node" are called constructors. In this case both are Records +(type (Tree T) + (Nothing) + (Node value :T + left :(Tree T) + right :(Tree T))) + +; Constructors have one of two forms: +; Union constructors have parameters enclosed in parenthesis, e.g. +; (Maybe (Nothing) (Just x)) +; Record constructors do not, e.g. +; (Point x y) +; +; Thus, types can be arbitrarily combined/nested, e.g +(type (Collection T) + (Tree + (Nothing) + (Node value :T + left :(Tree T) + right :(Tree T))) + (List + (Nothing) + (Node value :T + next :(List T)))) + +; Tree height (functional pattern matching style) +(def (height t) + (match t:Tree + (Empty) 0 + (Node v l r) (+ 1 (max (height l) (height r))))) + +; equivalently +(def (height t) + (match t + (Tree.Empty) 0 + (Tree.Node v l r) (+ 1 (max (height l) (height r))))) + +; GADTs +; The return type of a constructor can be specified explicitly +; e.g. a well-typed evaluator (this is not possible without GADTs): +; (http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html#gadt) +(type (Term T) + (Lit i :Int) :(Term Int) + (Succ t :Int) :(Term Int) + (IsZero t :Int) :(Term Bool) + (If c :Bool + t :(Term T) + e :(Term T)) :(Term T) + (Pair a :(Term T) + b :(Term T)) :(Term T)) + +; Objects +; A type with a single product constructor is simply that product type +; (i.e. sum types with a single element do not exist by definition) +; This can be used to create "record" or "object" types without any special +; language facilities: +(type (Person) + (Person + name :String + age :Number)) + +; The '.' ("dot") operator can be used to inspect product types + +(def dave (Person 'name "Dave" 'age 27)) + +(. dave name) ; => "Dave" +(. dave age) ; => 27 + + +;; Everything Is A ... + +; Everything in Resp is a closure. Records are simply closures with some +; internal definitions exposed (much like modules). + +; Objects can be created with their constructors: +(def steve (Person "Steve" 24)) + +; Equivalently (aside from type) with the generic Object constructor: +(def steve2 (Object 'name "Steve" 'age 24)) + +; Equivalently (aside from type) manually: +(def steve2 + (fn () + (def name "Steve") + (def age 24) + (export name age))) + +;; RDF style objects + +; A class is just an object (closure) with some required properties (ala OWL) +; All object fields have a URI. If a prefix is not explicitly given, the URI +; is the base URI of the document, followed by the Class, a dot, then the name. +; e.g. if the base URI of this document is "foo://bar/" the URI of "age" below is: +; foo://bar/Person.age + +(ns foaf "http://xmlns.com/foaf/0.1/") +(ns geom "http://www.charlestoncore.org/ontology/2005/08/geometry") + +(def (Point T) + (Point + geom.x :T + geom.y :T)) + +(type (Person) + foaf.name :String + age :Number) + +(type (Cat) + foaf.name :String + age :Number) + +; A 'constructor' (nothing special, just a function that returns a closure) +(def (newborn name) + (fn () + (def type Person) ; special, compiler will check required properties exist + (def foaf.name name) + (def age 1))) + +; Equivalently, +(def (newborn name) + (Person + foaf.name name + age 1)) + +(def stewie (newborn "Stewie")) +(def stewies-age (. stewie age)) + + + diff --git a/test/intro.tpr b/test/intro.tpr deleted file mode 100644 index 73a21bb..0000000 --- a/test/intro.tpr +++ /dev/null @@ -1,148 +0,0 @@ -;;; NOTE: This document is just a draft idea sketch pad - -;;; Data types - -; Tuplr uses algebraic datatypes which can also be used in an -; object based style with more flexibility than typical of -; languages with algebraic datatypes -; -; There is a single way of defining a type (the 'type' form) which -; encompasses unions, records, objects, etc. - -; A type is a discriminated union ("or") of types. -; Type names (including variables) always start with an uppercase letter. - -; There are many equivalent terms for kinds of types. We uniformly use: -; "Union" : "and", sum type -; "Record" : "or", product type, object, struct - -; Example: A Tree is a Node with a value and left/right children, or Nothing -; "Nothing" and "Node" are called constructors. In this case both are Records -(type (Tree T) - (Nothing) - (Node value :T - left :(Tree T) - right :(Tree T))) - -; Constructors have one of two forms: -; Union constructors have parameters enclosed in parenthesis, e.g. -; (Maybe (Nothing) (Just x)) -; Record constructors do not, e.g. -; (Point x y) -; -; Thus, types can be arbitrarily combined/nested, e.g -(type (Collection T) - (Tree - (Nothing) - (Node value :T - left :(Tree T) - right :(Tree T))) - (List - (Nothing) - (Node value :T - next :(List T)))) - -; Tree height (functional pattern matching style) -(def (height t) - (match t:Tree - (Empty) 0 - (Node v l r) (+ 1 (max (height l) (height r))))) - -; equivalently -(def (height t) - (match t - (Tree.Empty) 0 - (Tree.Node v l r) (+ 1 (max (height l) (height r))))) - -; GADTs -; The return type of a constructor can be specified explicitly -; e.g. a well-typed evaluator (this is not possible without GADTs): -; (http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html#gadt) -(type (Term T) - (Lit i :Int) :(Term Int) - (Succ t :Int) :(Term Int) - (IsZero t :Int) :(Term Bool) - (If c :Bool - t :(Term T) - e :(Term T)) :(Term T) - (Pair a :(Term T) - b :(Term T)) :(Term T)) - -; Objects -; A type with a single product constructor is simply that product type -; (i.e. sum types with a single element do not exist by definition) -; This can be used to create "record" or "object" types without any special -; language facilities: -(type (Person) - (Person - name :String - age :Number)) - -; The '.' ("dot") operator can be used to inspect product types - -(def dave (Person 'name "Dave" 'age 27)) - -(. dave name) ; => "Dave" -(. dave age) ; => 27 - - -;; Everything Is A ... - -; Everything in Tuplr is a closure. Records are simply closures with some -; internal definitions exposed (much like modules). - -; Objects can be created with their constructors: -(def steve (Person "Steve" 24)) - -; Equivalently (aside from type) with the generic Object constructor: -(def steve2 (Object 'name "Steve" 'age 24)) - -; Equivalently (aside from type) manually: -(def steve2 - (fn () - (def name "Steve") - (def age 24) - (export name age))) - -;; RDF style objects - -; A class is just an object (closure) with some required properties (ala OWL) -; All object fields have a URI. If a prefix is not explicitly given, the URI -; is the base URI of the document, followed by the Class, a dot, then the name. -; e.g. if the base URI of this document is "foo://bar/" the URI of "age" below is: -; foo://bar/Person.age - -(ns foaf "http://xmlns.com/foaf/0.1/") -(ns geom "http://www.charlestoncore.org/ontology/2005/08/geometry") - -(def (Point T) - (Point - geom.x :T - geom.y :T)) - -(type (Person) - foaf.name :String - age :Number) - -(type (Cat) - foaf.name :String - age :Number) - -; A 'constructor' (nothing special, just a function that returns a closure) -(def (newborn name) - (fn () - (def type Person) ; special, compiler will check required properties exist - (def foaf.name name) - (def age 1))) - -; Equivalently, -(def (newborn name) - (Person - foaf.name name - age 1)) - -(def stewie (newborn "Stewie")) -(def stewies-age (. stewie age)) - - - diff --git a/test/nest.resp b/test/nest.resp new file mode 100644 index 0000000..3085737 --- /dev/null +++ b/test/nest.resp @@ -0,0 +1,6 @@ +(def (f x) + (def (g y) + (* y 2)) + (g x)) + +(f 3) diff --git a/test/nest.tpr b/test/nest.tpr deleted file mode 100644 index 3085737..0000000 --- a/test/nest.tpr +++ /dev/null @@ -1,6 +0,0 @@ -(def (f x) - (def (g y) - (* y 2)) - (g x)) - -(f 3) diff --git a/test/poly.resp b/test/poly.resp new file mode 100644 index 0000000..33922e3 --- /dev/null +++ b/test/poly.resp @@ -0,0 +1,6 @@ +(def eq (fn (x y) (= x y))) + +(eq 1 2) +(eq 1 1) +(eq 10.0 20.0) +(eq 10.0 10.0) diff --git a/test/poly.tpr b/test/poly.tpr deleted file mode 100644 index 33922e3..0000000 --- a/test/poly.tpr +++ /dev/null @@ -1,6 +0,0 @@ -(def eq (fn (x y) (= x y))) - -(eq 1 2) -(eq 1 1) -(eq 10.0 20.0) -(eq 10.0 10.0) diff --git a/test/tup.resp b/test/tup.resp new file mode 100644 index 0000000..17d59cb --- /dev/null +++ b/test/tup.resp @@ -0,0 +1,6 @@ +(def t (cons 1 2 3 4 5)) +(. t 0) +(. t 1) +(. t 2) +(. t 3) +(. t 4) diff --git a/test/tup.tpr b/test/tup.tpr deleted file mode 100644 index 17d59cb..0000000 --- a/test/tup.tpr +++ /dev/null @@ -1,6 +0,0 @@ -(def t (cons 1 2 3 4 5)) -(. t 0) -(. t 1) -(. t 2) -(. t 3) -(. t 4) -- cgit v1.2.1