Jump to content

Module:Logic

From RPI Wiki
Revision as of 04:29, 28 May 2026 by Oliveg2 (talk | contribs) (New module just dropped)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Logic/doc

local p = {}
local function empty(s)
	return s == nil or s == ''
end
local function pcs(s)
	if s then
		return "1"
	end
	return ""
end
function p.f_not(frame)
	return pcs(empty(frame.args[1]))
end
function p.f_and(frame)
	val = true
	for i, a in ipairs( frame.args ) do
		val = val and not empty(a)
	end
	return pcs(val)
end

function p.f_nand(frame)
	val = true
	for i, a in ipairs( frame.args ) do
		val = val and not empty(a)
	end
	return pcs(not val)
end

function p.f_or(frame)
	for i, a in ipairs( frame.args ) do
		if not isempty(a) then
			return pcs(true)
		end
	end
	return pcs(false)
end

function p.f_nor(frame)
	for i, a in ipairs( frame.args ) do
		if not isempty(a) then
			return pcs(false)
		end
	end
	return pcs(true)
end

function p.f_xor(frame)
	v1 = true
	v2 = false
	for i, a in ipairs( frame.args ) do
		v1 = v1 and not empty(a)
		if not empty(a) then
			v2 = true
		end
	end
	return pcs(v2 and not v1)
end

function p.f_xnor(frame)
	v1 = true
	v2 = false
	for i, a in ipairs( frame.args ) do
		v1 = v1 and not empty(a)
		if not empty(a) then
			v2 = true
		end
	end
	return pcs(not (v2 and not v1))
end

return p