function class.update(V)for B in V.dependencySet do B.dependentSet[V]=nil end V._oldDependencySet,V.dependencySet=V.dependencySet,V._oldDependencySet table.clear(V.dependencySet)local B,I,b=Dependencies.captureDependencies(V.dependencySet,V._processor)if B then if not V._destructor and utility.needsDestruction(I)then warn("\100\101\115\116\114\117\099\116\111\114\078\101\101\100\101\100\067\111\109\112\117\116\101\100")end if b then warn("\109\117\108\116\105\082\101\116\117\114\110\067\111\109\112\117\116\101\100")end local B=V._value if V._destructor then V._destructor(B)end V._value=I for B in V.dependencySet do B.dependentSet[V]=true end return not utility.isSimilar(B,I)else warn("\099\111\109\112\117\116\101\100\067\097\108\108\098\097\099\107\069\114\114\111\114",I)V._oldDependencySet,V.dependencySet=V.dependencySet,V._oldDependencySet for B in V.dependencySet do B.dependentSet[V]=true end return false end end return Computed

function class:update()
	-- remove this object from its dependencies' dependent sets
	for dependency in self.dependencySet do
		dependency.dependentSet[self] = nil
	end
	
	-- we need to create a new, empty dependency set to capture dependencies
	-- into, but in case there's an error, we want to restore our old set of
	-- dependencies. by using this table-swapping solution, we can avoid the
	-- overhead of allocating new tables each update.
	self._oldDependencySet, self.dependencySet = self.dependencySet, self._oldDependencySet
	table.clear(self.dependencySet)
	
	local ran, newValue, newMetatable = Dependencies.captureDependencies(self.dependencySet, self._processor)
	
	if ran then
		if not self._destructor and utility.needsDestruction(newValue) then
			warn("destructorNeededComputed")
		end
		
		if newMetatable then
			warn("multiReturnComputed")
		end
		
		local value = self._value
		
		if self._destructor then
			self._destructor(value)
		end
		
		self._value = newValue
		
		-- add this object to the dependencies' dependent sets
		for dependency in self.dependencySet do
			dependency.dependentSet[self] = true
		end
		
		return not utility.isSimilar(value, newValue)
	else
		-- this needs to be non-fatal, because otherwise it'd disrupt the
		-- update process
		warn("computedCallbackError", newValue)
		
		-- restore old dependencies, because the new dependencies may be corrupt
		self._oldDependencySet, self.dependencySet = self.dependencySet, self._oldDependencySet
		
		-- restore this object in the dependencies' dependent sets
		for dependency in self.dependencySet do
			dependency.dependentSet[self] = true
		end
		
		return false
	end
end

return Computed
