--[[ Data Tagging Module H. Conrad Cunningham, Professor Computer and Information Science University of Mississippi Developed for CSci 658, Software Language Engineering, Fall 2013 1234567890123456789012345678901234567890123456789012345678901234567890 2013-09-22: Separated module from Complex Number Tagged Data module --]] -- Load complex number utilities module local util = require "complexUtilities" -- local definitions for convenience local show_data = util.show_data -- From SICP Section 2.4.2: Tagged Data -- Tagging local function attach_tag(type_tag,contents) return { tag = type_tag, contents = contents } end -- Replaces Scheme function "pair?" on cons list representation local function is_tagged(datum) return type(datum) == "table" and datum.tag and datum.contents end local function type_tag(datum) if is_tagged(datum) then return datum.tag else error("Bad tagged datum -- TYPE_TAG" .. show_data(datum), 2) end end local function contents(datum) if is_tagged(datum) then return datum.contents else error("Bad tagged datum -- CONTENTS" .. show_data(datum), 2) end end -- MODULE EXPORT return { attach_tag = attach_tag, is_tagged = is_tagged, type_tag = type_tag, contents = contents }