[pypy-svn] r65560 - pypy/branch/io-lang/pypy/lang/io/io

david at codespeak.net david at codespeak.net
Wed Jun 3 20:24:02 CEST 2009


Author: david
Date: Wed Jun  3 20:24:01 2009
New Revision: 65560

Added:
   pypy/branch/io-lang/pypy/lang/io/io/bsd_license.txt
Modified:
   pypy/branch/io-lang/pypy/lang/io/io/Map.io
Log:
Add bsd license from io sources and the full Map.io file also from the io repository

Modified: pypy/branch/io-lang/pypy/lang/io/io/Map.io
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/io/Map.io	(original)
+++ pypy/branch/io-lang/pypy/lang/io/io/Map.io	Wed Jun  3 20:24:01 2009
@@ -1,27 +1,98 @@
 Map do(
-    //doc Map with(key1, value1, key2, value2, ...) Returns a new map containing the given keys and values
-    with := method(
-    	m := Map clone
-    	args := call message arguments 
-    	for(i, 0, args size - 1, 2,
-    		m atPut(call evalArgAt(i), call evalArgAt(i+1))
-    	)
-    	m
-    )
+	//doc Map with(key1, value1, key2, value2, ...) Returns a new map containing the given keys and values
+	with := method(
+		m := Map clone
+		args := call message arguments 
+		for(i, 0, args size - 1, 2,
+			m atPut(call evalArgAt(i), call evalArgAt(i+1))
+		)
+		m
+	)
+	
+	asJson := method(
+		"{" .. self keys map(k, k asJson .. ":" .. self at(k) asJson) join(",") .. "}"
+	)
+	
+	//doc Map asList Converts a Map to a list of lists. Each element in the returned list will be a list of two elements: the key, and the value.
+	asList := method(
+		self keys map(k, list(k, self at(k)))
+	)
 
-    asJson := method(
-    	"{" .. self keys map(k, k asJson .. ":" .. self at(k) asJson) join(",") .. "}"
-    )
+	/*doc Map map(key, value, message)
+		Create a List of results of message applied to self's items in a random
+		order.
+	*/
+	map := method(
+		result := List clone
+		key := call argAt(0)
+		value := call argAt(1)
+		body := call argAt(2)
+		self foreach(k, v,
+			call sender setSlot(key name, k)
+			call sender setSlot(value name, v)
+			ss := stopStatus(r := call sender doMessage(body))
+			if(ss isReturn, call setStopStatus(ss); return getSlot("v"))
+			if(ss isBreak, break)
+			if(ss isContinue, continue)
+			result append(getSlot("r"))
+		)
+		result
+	)
 
-    //doc Map asList Converts a Map to a list of lists. Each element in the returned list will be a list of two elements: the key, and the value.
-    asList := method(
-    	self keys map(k, list(k, self at(k)))
-    )
- 
-        //doc Map asObject Create a new Object whose slotDescriptionMap will be equal to self
-    	asObject := method(
-    		o := Object clone
-    		self foreach(k, v, o setSlot(k, getSlot("v")))
-            o
-    	)
+	/*doc Map select(optionalIndex, optionalValue, message)
+		Create a new Map with keys,values of self for which message evaluated
+		to non-nil.
+	*/
+	select := method(
+		result := Map clone
+		self keys foreach(key,
+			if(call argCount > 1,
+				call sender setSlot(call argAt(0) name, key)
+				if(call argCount == 3,
+					call sender setSlot(call argAt(1) name, self at(key))
+				)
+			)
+			ss := stopStatus(v := call evalArgAt(call argCount - 1))
+			if(ss isReturn, call setStopStatus(ss); return getSlot("v"))
+			if(ss isBreak, break)
+			if(ss isContinue, continue)
+			if(getSlot("v"),
+				result atPut(key, self at(key))
+			)
+		)
+		result
+	)
+
+	/*doc Map detect(optionalIndex, optionalValue, message)
+		Returns a random value for which message evals to non-nil.
+	*/
+	detect := method(
+		self keys foreach(key,
+			if(call argCount > 1,
+				call sender setSlot(call argAt(0) name, key)
+				if(call argCount == 3,
+					call sender setSlot(call argAt(1) name, self at(key))
+				)
+			)
+			ss := stopStatus(v := call evalArgAt(call argCount - 1))
+			if(ss isReturn, call setStopStatus(ss); return getSlot("v"))
+			if(ss isBreak, break)
+			if(ss isContinue, continue)
+			if(getSlot("v"),
+				return list(key, self at(key))
+			)
+		)
+	)
+
+	//doc Map reverseMap Create a new Map using values as keys and keys as values
+	reverseMap := method(
+		Map clone addKeysAndValues(values, keys)
+	)
+	
+	//doc Map asObject Create a new Object whose slotDescriptionMap will be equal to self
+	asObject := method(
+		o := Object clone
+		self foreach(k, v, o setSlot(k, getSlot("v")))
+		o
+	)
 )

Added: pypy/branch/io-lang/pypy/lang/io/io/bsd_license.txt
==============================================================================
--- (empty file)
+++ pypy/branch/io-lang/pypy/lang/io/io/bsd_license.txt	Wed Jun  3 20:24:01 2009
@@ -0,0 +1,14 @@
+(This is a BSD License)
+
+Copyright (c) 2002, 2003 Steve Dekorte
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+¥  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+¥  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+¥  Neither the name of the author nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+



More information about the Pypy-commit mailing list