Karma Trail - Persistent Data Metaphor

This code implements a C++ persistent data container that serves as both a technical experiment and a personal metaphor about continuity, cycles, consciousness, experience, and emerging from a coma.

Core Concept: The Karma Trail

"Karma Trail
Simple Concept
Coma
When you break the infinite while loop
you branch out to the greater reality"
- Jared Bruni

The name Per, short for persistent, and the concept of repeatedly writing data to storage became part of a larger metaphor.

Technical Implementation

The code implements a persistent data container using C++ templates and binary file I/O.

#ifndef __PER__H__ #define __PER__H__ #include<iostream> #include<string> #include<fstream> namespace per { template<typename T> class Data { public: Data() = default; static void write(std::fstream &file, const T &type) { if(file.is_open()) file.write(reinterpret_cast<const char *>(&type), sizeof(type)); } static void read(std::fstream &file, T &type) { if(file.is_open()) file.read(reinterpret_cast<char *>(&type), sizeof(type)); } }; class StringData { public: StringData() = default; static void write(std::fstream &file, const std::string &type) { if(file.is_open()) { int len = type.length(); file.write(reinterpret_cast<const char *>(&len), sizeof(len)); file.write(reinterpret_cast<const char *>(type.c_str()), len); } } static void read(std::fstream &file, std::string &type) { if(file.is_open()) { int len; file.read(reinterpret_cast<char *>(&len), sizeof(len)); char *buf = new char[len + 1]; file.read(buf, len); buf[len] = 0; type = buf; delete [] buf; } } }; template<typename C> class StringContainerData { public: StringContainerData() = default; static void write(std::fstream &file, const C &type) { if(file.is_open()) { for(auto it = type.begin(); it != type.end(); ++it) { int len = it->length(); file.write(reinterpret_cast<const char *>(&len), sizeof(len)); file.write(reinterpret_cast<const char *>(it->c_str()), len); } } } static void read(std::fstream &file, C &type) { if(file.is_open()) { while(!file.eof()) { int len; file.read(reinterpret_cast<char *>(&len), sizeof(len)); if(file) { char *buf = new char[len + 1]; file.read(buf, len); buf[len] = 0; std::string t{buf}; delete [] buf; type.push_back(t); } } } } }; template<typename C, typename T> class ContainerData { public: ContainerData() = default; static void write(std::fstream &file, const C &type) { if(file.is_open()) { for(auto i = type.begin(); i != type.end(); ++i) { file.write(reinterpret_cast<const char *>(&*i), sizeof(*i)); } } } static void read(std::fstream &file, C &type) { if(file.is_open()) { while(!file.eof()) { T t; file.read(reinterpret_cast<char *>(&t), sizeof(t)); if(file) type.push_back(t); else break; } } } }; template<typename T, typename D = Data<T>> class Per { public: Per(std::string name) : file_name{name} { load(); } Per(std::string name, const T &i) : file_name{name} { std::fstream file_in; file_in.open(file_name, std::ios::in | std::ios::binary); if(!file_in.is_open()) { type = i; } else { file_in.close(); load(); } } Per(const Per<T,D> &p, const std::string &file_n) : file_name{file_n}, type{p.type} {} Per(const Per<T,D> &&p, const std::string &file_n) : file_name{file_n}, type{std::move(p.type)} {} Per<T,D> &operator=(const Per<T,D> &p) = delete; Per<T,D> &operator=(const Per<T,D> &&p) = delete; Per(const Per<T,D> &) = delete; Per(const Per<T,D> &&) = delete; Per<T,D> &operator=(const T &t) { type = t; return *this; } Per<T,D> &operator=(const T &&t) { type = std::move(t); return *this; } void setFileName(const std::string &fn) { file_name = fn; } std::string getFileName() const { return file_name; } void save() { std::fstream file_in; file_in.open(file_name, std::ios::out | std::ios::binary | std::ios::trunc); if(!file_in.is_open()) { std::cerr << "Error could not open: " << file_name << " for output...\n"; exit(EXIT_FAILURE); } D::write(file_in, type); file_in.close(); } void load() { std::fstream file_in; file_in.open(file_name, std::ios::in | std::ios::binary); if(file_in.is_open()) { D::read(file_in, type); file_in.close(); } } void set(const T &t) { type = t; } void reset() { type = T(); } void clear() { reset(); save(); } ~Per() { save(); } T &data() { return type; } T &operator*() { return type; } private: T type; std::string file_name; }; } #endif
/* Karma Trail Simple Concept Coma When you break the infinite while loop you branch out to the greater reality - Jared Bruni */ #include<iostream> #include<string> #include<algorithm> #include "per.hpp" class Escape {}; std::string give() { std::string data; std::cout << "Enter: "; std::getline(std::cin, data); return data; } std::string get(std::string data) { if(data == "love") std::cout << "love sent...\n"; else if(data == "fear") std::cout << "fear sent...\n"; else if(data == "break") throw Escape(); return data; } int main() { try { per::Per<std::string, per::StringData> trail("karma_trail.txt", ""); while(1) { *trail += get(give()) + "\n"; std::cout << "karma trail: " << *trail << "\n"; } } catch(Escape &e) { std::cout << "freedom..\n"; } return 0; }

Metaphorical Interpretation

Each line entered by the user becomes part of a growing trail.

The trail persists across program runs through disk storage. What happened previously is not automatically erased.

The loop continues until the user types "break". At that point, the normal flow of the program is interrupted and the cycle ends.

The code was written after a coma as an attempt to express an experience that was difficult to describe with ordinary language. Programming concepts such as loops, persistence, state, exceptions, and control flow became a vocabulary for representing that experience.

Symbolic Meaning Behind Key Elements

1. Per<T,D> Class

The Per<T,D> class is essentially a wrapper around a value that persists on disk:

per::Per<std::string, per::StringData> trail("karma_trail.txt", "");

The persistence mechanism gives the metaphor an important additional meaning. The program can stop and later begin again without necessarily beginning from nothing. The previous state can still exist and be loaded again.

Symbolically, this can represent continuity. A change in conscious state does not necessarily erase everything that came before it. History, memory, consequence, and identity can continue forward.

2. Infinite Loop & Escape Mechanism

while(1) { *trail += get(give()) + "\n"; }

The infinite loop represents a state that continues without an ordinary endpoint.

The use of an exception makes the metaphor stronger than a normal loop termination. The program does not simply proceed through the ordinary execution path. Instead, the existing flow is interrupted and execution jumps outside the entire cycle.

else if(data == "break") throw Escape();

The exception is caught outside the loop:

catch(Escape &e) { std::cout << "freedom..\n"; }

Symbolically, this represents an abrupt transition from one state into another.

3. File Persistence

The save() and load() functions preserve the state of the object across program executions:

void save() { ... } void load() { ... }

The trail does not simply vanish when the program stops. It can survive the termination of one execution and become part of the next.

In the metaphor, this persistence represents the continuation of history and identity. The system changes state, but what happened before remains part of what comes afterward.

The Coma Metaphor

The central line of the program is:

"When you break the infinite while loop
you branch out to the greater reality"

This idea came from trying to describe the experience of emerging from a coma.

The infinite loop can be understood as a closed state of consciousness. While inside that state, it is the only state available to the system. There is no ordinary path leading outside it.

Breaking the loop represents the sudden transition out of that state.

The phrase "greater reality" is important. The metaphor is not about escaping reality. It is about discovering that what appeared to be the complete reality was actually only one state inside something larger.

In programming terms, execution leaves one control-flow structure and continues somewhere that could not be reached while remaining inside the loop itself.

Metaphorical Framework

What's the Metaphor?

Element Metaphorical Meaning
Per<T,D> Persistence of state, memory, history, and continuity
Infinite Loop A closed state that continues without an ordinary endpoint
Writing to File Experience and history accumulating over time
karma_trail.txt The persistent record of the journey
Escape Exception An abrupt interruption of the existing control flow
Breaking the Loop Leaving the closed state
Greater Reality Awareness of a larger reality beyond the previous state

Control Flow as Metaphor

The underlying structure of the program can be reduced to a simple sequence:

state -> action -> persistent consequence -> state -> action -> persistent consequence ...

The cycle continues until an event changes the control flow:

escape condition -> control-flow interruption -> new state

Because of this, the metaphor is larger than simply saying that karma is like information stored in a file.

The program describes a system whose history continually accumulates while it remains inside a repeating state. The transition occurs when something changes the structure of execution itself.

Final Interpretation

This code can be read as a small program about persistence, consciousness, continuity, and transition.

A system exists inside a repeating state.
Its experiences accumulate and become part of a persistent trail.
The state appears endless while the system remains inside it.
Then the normal control flow is interrupted.
The loop ends.
What existed before is not necessarily erased.
The system continues into a greater reality.

Written after a coma, the program uses the technical language of C++ to express an experience that ordinary language can have difficulty representing.

Loops describe repetition. Persistence describes continuity. State represents the condition of the system. The Escape exception represents a sudden discontinuity in normal execution. Branching outside the loop represents becoming aware of something larger than the state that came before it.

In that sense, the code is not simply an illustration of a philosophical idea. It is a personal metaphor expressed through the concepts of computer programming.