view extendlib.vistxt @ 154:29b479a2ce48

Make memory leak detection controllable by a define
author Mike Pavone <pavone@retrodev.com>
date Tue, 21 Dec 2010 04:11:47 +0000
parents 6202b866d72c
children
line wrap: on
line source


Val(1,1)
|:
	(0) <- (0)
:|

Map Helper(3,1)
|:
	newval <- [
		[worker(2)]Do[  
			[List[]]Append[ [list(0)]Index[index(1)] ]
		]
	]Index[0]
	
	[list(0)]Next[index(1)]
	|:
		out(0) <- [Map Helper[list(0), ~, worker(2)]]Set[index(1), newval]
	:||:
		out(0) <- [list(0)]Set[index(1), newval]
	:|
:|

Map(2,1)
|:
	[list(0)]First
	|:
		out(0) <- Map Helper[list(0), ~, worker(1)]
	:||:
		out(0) <- list(0)
	:|
:|

New Like@List(1,1)
|:
	out(0) <- List[]	
:|

New Like@Dictionary(1,1)
|:
	out(0) <- Dictionary[]
:|

Key Value Map Helper(4,1)
|:
	[worker(3)]Do[  
		[[List[]]Append[ [list(0)]Index[index(1)] ]]Append[index(1)]
	]
	|:
		newval <- [~]Index[0]
		newkey <- [~]Index[1]
	:|
	
	next <- [newlist(2)]Set[newkey, newval]
	
	[list(0)]Next[index(1)]
	|:
		out(0) <- Key Value Map Helper[list(0), ~, next, worker(3)]
	:||:
		out(0) <- Val[next]
	:|
:|

Key Value Map(2,1)
|:
	[list(0)]First
	|:
		out(0) <- Key Value Map Helper[list(0), ~, New Like[list(0)], worker(1)]
	:||:
		out(0) <- New Like[list(0)]
	:|
:|

Dict Split Helper(4,1)
|:
	If[ [i(2)] < [[list(0)]Length@List] ]
	|:
		keyval <- Split@String[ [list(0)]Index@List[i(2)], keydelim(1) ]
		key <- [keyval]Index@List[0]
		val <- [keyval]Index@List[1]
		HelpOut(0) <- Dict Split Helper[ list(0), keydelim(1), [i(2)] + [1], [dict(3)]Set@Dictionary[key, val] ]
	:||:
		HelpOut(0) <- dict(3)
	:|
:|

Dict Split(3,1)
|:
	Out(0) <- Dict Split Helper[ [string(0)]Split@String[entrydelim(2)] , keydelim(1), 0, Dictionary[]]
:|

In Helper(2,1)
|:
	
	,out(0) <- If[ [[haystack(1)]Length] > [0] ]
	|:
		[haystack(1)]Slice[ [needle(0)]Length ]
		|:
			out(0) <- If[ [needle(0)] = [~] ]
			|:
			:||:
				[haystack(1)]Slice[1]
				|: :|
				|:
					out(0) <- In Helper[needle(0), ~]
				:|
			:|
		:|
	:|
:|

In(2,1)
|:
	,out(0) <- If[ [[needle(0)]Length] > [0] ]
	|:
		out(0) <- In Helper[needle(0), haystack(1)]
	:|
:|

Left Trim(2,1)
|:
	If[ [[string(0)]Length] > [0] ]
	|:
		first,rest <- [string(0)]Slice[1]
		If[ [first]In[trim(1)] ]
		|:
			trimmed(0) <- Left Trim[rest, trim(1)]
		:||:
			trimmed(0) <- string(0)
		:|
	:||:
		trimmed(0) <- string(0)
	:|
:|

Right Trim(2,1)
|:
	If[ [[string(0)]Length] > [0] ]
	|:
		rest,last <- [string(0)]Slice[ [[string(0)]Length] - [1]]
		If[ [last]In[trim(1)] ]
		|:
			trimmed(0) <- Right Trim[rest, trim(1)]
		:||:
			trimmed(0) <- string(0)
		:|
	:||:
		trimmed(0) <- string(0)
	:|
:|

Trim(2,1)
|:
	left <- Left Trim[string(0), trim(1)]
	trimmed(0) <- Right Trim[left, trim(1)]
:|

Max(2,1)
|:
	If[[(0)] > [(1)]]
	|:
		(0) <- (0)
	:||:
		(0) <- (1)
	:|
:|

Count Substring(2,1)
|:
	out(0) <- Max[[[[string(0)]Split[sub(1)]]Length] - [1], 0]
:|

KeyVal Helper(5,1)
|:
	new string <- [[[string(4)]Append[key(1)]]Append[key sep(2)]]Append[ [container(0)]Index[key(1)] ]
	[list(0)]Next[index(1)]
	|:
		out(0) <- KeyVal Helper[container(0), ~, key sep(2), val sep(3), [new string]Append[val sep(3)]]
	:||:
		out(0) <- Val[new string]
	:|
:|

Key Value Join(3,1)
|:
	[container(0)]First
	|:
		out(0) <- KeyVal Helper[container(0), ~, key sep(1), val sep(2), ""]
	:||:
		out(0) <- ""
	:|
:|

Combine Helper(3,1)
|:
	new dest <- [dest(1)]Set[key(2), [source(0)]Index[key(2)]]
	[source(0)]Next[key(2)]
	|:
		out(0) <- Combine Helper[source(0), new dest, ~]
	:||:
		out(0) <- Val[new dest]
	:|
:|

Combine(2,1)
|:
	[source(0)]First
	|:
		out(0) <- Combine Helper[source(0), dest(1), ~]
	:||:
		out(0) <- dest(1)
	:|
:|

Fold Helper(4,1)
|:
	newval <- [
		[worker(3)]Do[  
			[[[List[]]Append[ start(2) ]]Append[ [list(0)]Index[index(1)] ]]Append[index(1)]
		]
	]Index[0]
	
	[list(0)]Next[index(1)]
	|:
		out(0) <- Fold Helper[list(0), ~, newval, worker(3)]
	:||:
		out(0) <- Val[newval]
	:|
:|

Fold(3,1)
|:
	[list(2)]First
	|:
		out(0) <- Fold Helper[list(2), ~, start(1), worker(0)]
	:||:
		out(0) <- start(1)
	:|
:|

Previous@List(2,2)
|:
	prev <- [index(1)] - [1]
	If[[prev] < [0]]
	|:
		not found(1) <- list(0)
	:||:
		[list(0)]Index[prev]
		|:
			out(0) <- Val[prev]
		:||:
			out(0), not found(1) <- [list(0)]Previous@List[prev]
		:|
	:|	
:|

Last@List(1,2)
|:
	out(0), not found(1) <- [list(0)]Previous@List[[list(0)]Length]
:|

Reverse Fold Helper(4,1)
|:
	newval <- [
		[worker(3)]Do[  
			[[[List[]]Append[ start(2) ]]Append[ [list(0)]Index[index(1)] ]]Append[index(1)]
		]
	]Index[0]
	
	[list(0)]Previous[index(1)]
	|:
		out(0) <- Reverse Fold Helper[list(0), ~, newval, worker(3)]
	:||:
		out(0) <- Val[newval]
	:|
:|

Reverse Fold(3,1)
|:
	[list(2)]Last
	|:
		out(0) <- Reverse Fold Helper[list(2), ~, start(1), worker(0)]
	:||:
		out(0) <- start(1)
	:|
:|

Join Helper(4,1)
|:
	[list(0)]Next[index(3)]
	|:
		out(0) <- Join Helper[list(0), delim(1), [[current(2)]Append[delim(1)]]Append[[list(0)]Index[~]], ~]
	:||:
		out(0) <- current(2)
	:|
:|

Join(2,1)
|:
	[list(0)]First
	|:
		out(0) <- Join Helper[list(0), delim(1), [list(0)]Index[~], ~]
	:||:
		out(0) <- ""
	:|
:|

Replace(3,1)
|:
	replaced(0) <- [[string(0)]Split[find(1)]]Join[replace(2)]	
:|

Concatenate(2,1)
|:
	out(0) <- Fold[["Append"]<String@Worker, left(0), right(1)]
:|

Serialize@String(1,1)
|:
	out(0) <- [[[[[string(0)]Replace["\\","\\\\"]]Replace[",","\\c"]]Replace["\n","\\n"]]Replace["{","\\l"]]Replace["}","\\r"]
:|

Unserialize@String(1,1)
|:
	out(0) <- [[[[[string(0)]Replace["\\c",","]]Replace["\\n","\n"]]Replace["\\l","{"]]Replace["\\r","}"]]Replace["\\\\","\\"]
:|

Serialize@List(1,1)
|:
	out(0) <- [["{"]Append[[Map[list(0), ["Serialize"]<String@Worker]]Join[","]]]Append["}"]
:|

Starts With(2,1)
|:
	out(0) <- [[thing(0)]Slice[ [starts with(1)]Length ]] = [starts with(1)]
:|

Ends With(2,1)
|:
	,compare <- [thing(0)]Slice[ [[thing(0)]Length] - [[ends with (1)]Length] ]
	out(0) <- [compare] = [ends with(1)]
:|

Unserialize Helper(3,3)
|:
	current <- [parts(0)]Index[index(1)]
	If[[current]Starts With["{"]]
	|:
		,first <- [current]Slice[1]
		list entry, index, bracketnum <- Unserialize Helper[ [parts(0)]Set[index(1), first], index(1), List[]]
		If[[bracketnum] = [0]]
		|:
			[parts(0)]Next[index]
			|:
				out(0), index(1), bracketnum(2) <- Unserialize Helper[parts(0), ~, [destlist(2)]Append[list entry]]
			:||:
				out(0) <- [destlist(2)]Append[list entry]
				index(1) <- index(1)
				bracketnum(2) <- 0
			:|
		:||:
			out(0) <- [destlist(2)]Append[list entry]
			index(1) <- Val[index]
			bracketnum(2) <- [bracketnum] - [1]
		:|
	:||:
		If[[current]Ends With["}"]]
		|:
			parts <- [current]Split["}"]
			entry <- [parts]Index[0]
			If[[[entry]Length] = [0]]
			|:
				out(0) <- destlist(2)
			:||:
				out(0) <- [destlist(2)]Append[ [entry]Unserialize@String ]
			:|
			bracketnum(2) <- [[parts]Length] - [2]
			index(1) <- index(1)
		:||:
			[parts(0)]Next[index(1)]
			|:
				out(0), index(1), bracketnum(2) <- Unserialize Helper[parts(0), ~, [destlist(2)]Append[[current]Unserialize@String]]
			:||:
				out(0) <- [destlist(2)]Append[[current]Unserialize@String]
				index(1) <- index(1)
				bracketnum(2) <- 0
			:|
		:|
	:|		
:|

Generic Unserialize(1,1)
|:
	parts <- [serialized(0)]Split[","]
	[parts]First
	|:
		out(0) <- Unserialize Helper[parts, ~, List[]]
	:||:
		out(0) <- List[]
	:|
:|

_Object to Dict(4,1)
|:
	field <- [field list(1)]Index[index(2)]
	[object(0)]Get Field[field]
	|:
		nextdict <- [dict(3)]Set[field, ~]
	:||:
		nextdict <- dict(3)
	:|
	[field list(1)]Next[index(2)]
	|:
		out(0) <- _Object to Dict[object(0), field list(1), ~, nextdict]
	:||:
		out(0) <- Val[nextdict]
	:|
:|

Get Pretty Print Value(1,5)
|:
	If[[Type Of[value(0)]] = ["List"]]
	|:
		value(4) <- value(0)
		list <- value(0)
		object <- value(0)
	:||:
		If[[Type Of[value(0)]] = ["Dictionary"]]
		|:
			value(4) <- value(0)
			list <- value(0)
			object <- value(0)
		:||:
			If[[Type Of[value(0)]] = ["String"]]
			|:
				value(4) <- value(0)
				print(0) <- value(0)
				done(3) <- 1
			:||:
				If[[Type Of[value(0)]] = ["Whole Number"]]
				|:
					value(4) <- value(0)
					print(0) <- value(0)
					done(3) <- 1
				:||:
					If[[Type Of[value(0)]] = ["Yes No"]]
					|:
						value(4) <- value(0)
						print(0) <- value(0)
						done(3) <- 1
					:||:
						If[[Type Of[value(0)]] = ["Real Number"]]
						|:
							value(4) <- value(0)
							print(0) <- value(0)
							done(3) <- 1
						:||:
							object <- value(0)
							fieldlist <- [Blueprint Of[value(0)]]Get Fields
							[fieldlist]First
							|:
								list <- _Object to Dict[value(0), fieldlist, ~, Dictionary[]]
								value(4) <- Val[list]
							:||:
								value(4) <- value(0)
								done(3) <- 1
							:|
						:|
					:|
				:|
			:|
			
		:|
	:|
	print(0) <- Type Of[object]
	index(1) <- [list]First |::|
	|:
		print indent(2) <- "{Empty}"
	:|
	
:|

Pretty Print Helper(3,1)
|:
	newtabs <- [tabs(1)]Append["    "]
	print,index,indented,done,value <- Get Pretty Print Value[[list(0)]Index[index(2)]]
	Print[ [[[tabs(1)]Append[index(2)]]Append[": "]]Append[print] ]
	|:
		done <- Pretty Print Helper[value,newtabs ,index]
		done <- Print[[newtabs]Append[indented]]
		
		Val[done]
		|:
			[list(0)]Next[index(2)]
			|:
				out(0) <- Pretty Print Helper[list(0), tabs(1), ~]
			:||:
				out(0) <- 1
			:|
		:|
	:|
	
:|

Pretty Print(2,1)
|:
	newtabs <- [tabs(1)]Append["    "]
	,index,indented,,value <- Get Pretty Print Value[toprint(0)]
	|:
		Print[[tabs(1)]Append[~]]
		|:
			Pretty Print Helper[value,newtabs ,index]
			Print[[newtabs]Append[indented]]
		:|
	:|
	out(0) <- 1
:|

As List@String(1,1)
|:
	out(0) <- [List[]]Append[string(0)]
:|

As List@List(1,1)
|:
	(0) <- (0)
:|

Check Starts(3,1)
|:
	If[ [prev(1)] = [""] ]
	|:
		If[ [string(0)]Starts With[el(2)] ]
		|:
			out(0) <- el(2)
		:||:
			out(0) <- prev(1)
		:|
	:||:
		out(0) <- prev(1)
	:|
:|

_Get DString@String(2,4)
|:
	If[ [[string(0)]Length] = [0]]
	|:
		nomatch(3) <- Yes
		before delim(1) <- ""
	:||:
		match <- Fold[["Check Starts"]Set Input[0, string(0)], "", delims(1)]
		If[ [match] = [""] ]
		|:
			first,rest <- [string(0)]Slice[1]
			rest(0),before,delim(2),nomatch(3) <- _Get DString@String[rest, delims(1)]
			before delim(1) <- [first]Append[before]
		:||:
			junk,rest(0) <- [string(0)]Slice[ [match]Length ]
			before delim(1) <- ""
			delim(2) <- Val[match]
		:|
	:|
:|

//Get DString@String(2,4)
//|:
//	delims <- [delim(1)]As List
//	rest(0), before delim(1), delim(2), nomatch(3) <- _Get DString@String[string(0), delims]
//:|

Filter Helper(4,1)
|:
	filter? <- [
		[worker(2)]Do[  
			[List[]]Append[ [list(0)]Index[index(1)] ]
		]
	]Index[0]
	If[filter?]
	|:
		newlist <- [newlist(3)]Append[[list(0)]Index[index(1)]]
	:||:
		newlist <- newlist(3)
	:|
	
	[list(0)]Next[index(1)]
	|:
		out(0) <- Filter Helper[list(0), ~, worker(2), newlist]
	:||:
		out(0) <- Val[newlist]
	:|
:|

Filter(2,1)
|:
	[list(0)]First
	|:
		out(0) <- Filter Helper[list(0), ~, worker(1), List[]]
	:||:
		out(0) <- list(0)
	:|
:|

Pop@List(1,1)
|:
	[list(0)]Last
	|:
		out(0) <- [list(0)]Remove[~]
	:||:
		out(0) <- list(0)
	:|
:|

Peek@List(1,2)
|:
	[list(0)]Last
	|:
		out(0) <- [list(0)]Index[~]
	:||:
		empty(1) <- list(0)
	:|
:|

Contains(2,1)
|:
	[haystack(0)]Get DString[needle(1)]
	|:
		out(0) <- Yes
	:| |::| |::| |:
		out(0) <- No
	:|
:|

_Find(3,2)
|:
	If[[[haystack(0)]Index[index(2)]] = [needle(1)]]
	|:
		index(0) <- index(2)
	:||:
		[haystack(0)]Next[index(2)]
		|:
			index(0),notfound(1) <- _Find[haystack(0),needle(1),~]
		:||:
			notfound(1) <- needle(1)
		:|	
	:|
:|

Find(2,2)
|:
	[haystack(0)]First
	|:
		index(0),not found(1) <- _Find[haystack(0), needle(1), ~]
	:||:
		not found(1) <- needle(1)
	:|

:|

_Tail(3,1)
|:
	[list(0)]Next[current(1)]
	|:
		out(0) <- _Tail[list(0), ~, [newlist(2)]Append[[list(0)]Index[~]]]
	:||:
		out(0) <- newlist(2)
	:|
:|

Tail(2,1)
|:
	newlist <- [list(0)]New Like
	[list(0)]Index[start(1)]
	|:
		out(0) <- _Tail[list(0), start(1), [newlist]Append[~]]
	:||:
		out(0) <- Val[newlist]
	:|
:|

_Keys(3,1)
|:
	out(0) <- [list(0)]Append[key(2)]
:|

Keys(1,1)
|:
	out(0) <- Fold["_Keys", List[], container(0)]
:|