[svn] r6216: nemerle/trunk: lib/narray.n lib/nstring.n
ncc/testsuite/positive/extension-methods-lib.n ncc/...
malekith
svnadmin at nemerle.org
Wed May 3 13:09:51 CEST 2006
Log:
Make methods from NString and NArray extension methods. Add NArray.ToList.
Author: malekith
Date: Wed May 3 13:09:50 2006
New Revision: 6216
Modified:
nemerle/trunk/lib/narray.n
nemerle/trunk/lib/nstring.n
nemerle/trunk/ncc/testsuite/positive/extension-methods-lib.n
nemerle/trunk/ncc/testsuite/positive/extension-methods.n
Modified: nemerle/trunk/lib/narray.n
==============================================================================
--- nemerle/trunk/lib/narray.n (original)
+++ nemerle/trunk/lib/narray.n Wed May 3 13:09:50 2006
@@ -26,6 +26,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+using Nemerle.Collections;
+
namespace Nemerle.Utility
{
/**
@@ -36,7 +38,7 @@
/**
* Iterates a function over an array.
*/
- public Iter ['a] (arr : array ['a], f : 'a -> void) : void
+ public Iter ['a] (this arr : array ['a], f : 'a -> void) : void
{
def loop (i)
{
@@ -54,7 +56,7 @@
* Iterates a function over an array, passing both the array index
* and value as the iterated function parameters.
*/
- public IterI ['a] (arr : array ['a], f : int * 'a -> void) : void
+ public IterI ['a] (this arr : array ['a], f : int * 'a -> void) : void
{
def loop (i)
{
@@ -67,7 +69,7 @@
loop (0)
}
- public Map ['a, 'b] (ar : array ['a], f : 'a -> 'b) : array ['b]
+ public Map ['a, 'b] (this ar : array ['a], f : 'a -> 'b) : array ['b]
{
def result = array (ar.Length);
@@ -87,7 +89,7 @@
/**
* Folds a function over an array.
*/
- public Fold ['a, 'b] (arr : array ['b], ini : 'a, f : 'b * 'a -> 'a) : 'a
+ public Fold ['b, 'a] (this arr : array ['b], ini : 'a, f : 'b * 'a -> 'a) : 'a
{
def loop (acc, i)
{
@@ -103,7 +105,7 @@
* Folds a function over an array, passing the array index
* as an additional parameter to the folded function parameters.
*/
- public FoldI ['a, 'b] (arr : array ['b], ini : 'a, f : int * 'b * 'a -> 'a) : 'a
+ public FoldI ['b, 'a] (this arr : array ['b], ini : 'a, f : int * 'b * 'a -> 'a) : 'a
{
def loop (acc, i)
{
@@ -125,7 +127,7 @@
*
* evaluates to 'true' as there is one string of length 3 on the list.
*/
- public Exists ['a] (a : array ['a], f : 'a -> bool) : bool
+ public Exists ['a] (this a : array ['a], f : 'a -> bool) : bool
{
def walk_array (i : int) : bool
{
@@ -146,7 +148,7 @@
*
* evaluates to 'true' as all the array's elements are even integers.
*/
- public ForAll ['a] (a : array ['a], f : 'a -> bool) : bool
+ public ForAll ['a] (this a : array ['a], f : 'a -> bool) : bool
{
def walk_array (i : int) : bool
{
@@ -162,6 +164,11 @@
x.ToArray ()
}
+ public ToList ['a] (this arr : array ['a]) : list ['a]
+ {
+ List.FromArray (arr)
+ }
+
public Iter2['a, 'b] (a : list ['a], b : array ['b], f : 'a * 'b -> void) : void {
def loop (l, acc) : void {
match (l) {
Modified: nemerle/trunk/lib/nstring.n
==============================================================================
--- nemerle/trunk/lib/nstring.n (original)
+++ nemerle/trunk/lib/nstring.n Wed May 3 13:09:50 2006
@@ -143,7 +143,7 @@
/** Same as [Implode (List.Map (Explode (s), f))] but a lot faster. */
- public Map (s : string, f : char -> char) : string
+ public Map (this s : string, f : char -> char) : string
{
def res = StringBuilder (s.Length);
for (mutable i = 0; i < s.Length; ++i)
@@ -153,7 +153,7 @@
/** Same as [Concat ("", List.Map (Explode (s), f))] but a lot faster. */
- public MapCS (s : string, f : char -> string) : string
+ public MapCS (this s : string, f : char -> string) : string
{
def res = StringBuilder (s.Length);
for (mutable i = 0; i < s.Length; ++i)
@@ -163,7 +163,7 @@
/** Call [f] for all characters in [s] in turn. */
- public Iter (s : string, f : char -> void) : void
+ public Iter (this s : string, f : char -> void) : void
{
for (mutable i = 0; i < s.Length; ++i)
f (s [i]);
@@ -172,14 +172,14 @@
/** Call [f] for all characters in [s] in turn, passing the current
index as the additional paramter. */
- public IterI (s : string, f : char * int -> void) : void
+ public IterI (this s : string, f : char * int -> void) : void
{
for (mutable i = 0; i < s.Length; ++i)
f (s [i], i);
}
- public Fold['a] (s : string, ini : 'a, f : char * 'a -> 'a) : 'a
+ public Fold['a] (this s : string, ini : 'a, f : char * 'a -> 'a) : 'a
{
def loop (acc, i) {
if (i >= s.Length) acc
@@ -204,7 +204,7 @@
/** Return [true] if [f] is returns [true] for all of the characters
in the string [s]. */
- public ForAll (s : string, f : char -> bool) : bool
+ public ForAll (this s : string, f : char -> bool) : bool
{
def loop (i) {
if (i >= s.Length) true
@@ -217,7 +217,7 @@
/** Return [true] if [f] is returns [true] for any of the characters
in the string [s]. */
- public Exists (s : string, f : char -> bool) : bool
+ public Exists (this s : string, f : char -> bool) : bool
{
def loop (i) {
if (i >= s.Length) false
@@ -232,7 +232,7 @@
Warning: this should not be used in performance critical parts of
the program, because of list's memory overheads. */
- public Explode (s : string) : list [char]
+ public Explode (this s : string) : list [char]
{
def loop (i, acc) {
if (i < 0) acc
Modified: nemerle/trunk/ncc/testsuite/positive/extension-methods-lib.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/extension-methods-lib.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/extension-methods-lib.n Wed May 3 13:09:50 2006
@@ -16,7 +16,7 @@
namespace SomeDeepNamespace
public class OtherwiseUnusedClass
- public static ToList[T] (this a : array [T]) : list [T]
+ public static ToList2[T] (this a : array [T]) : list [T]
List.FromArray (a)
public class B
Modified: nemerle/trunk/ncc/testsuite/positive/extension-methods.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/extension-methods.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/extension-methods.n Wed May 3 13:09:50 2006
@@ -18,7 +18,11 @@
a.Rev ()
System.Console.WriteLine (List.FromArray (a))
B.Rev (a)
+System.Console.WriteLine (a.ToList2 ())
System.Console.WriteLine (a.ToList ())
+a.Iter (fun (x) { WriteLine (x) })
+WriteLine ("gppcbs".Map (fun (c:char) { ((c :> int) - 1) :> char }))
+
/*
BEGIN-OUTPUT
@@ -42,5 +46,10 @@
System.Double
[15, 14, 3]
[3, 14, 15]
+[3, 14, 15]
+3
+14
+15
+foobar
END-OUTPUT
*/
More information about the svn
mailing list