12
Inspired by this question.
Create a program that prompts the user to store some data, and when the program is quitting, spit out the program itself, except the session data changed.
The user then open the newly generated program, and can recall the data from the previous program.
Commands
KEY VALUE
: sets session variableKEY
toVALUE
*
: clear all data! KEY
: deleteKEY
? KEY
: queryKEY
(if not exist: print nothing and move on)- otherwise, quit the program
Neither key or value cannot contain any spaces. The newly generated program's filename must identify the version of the program, you can use dates or counters.
Example interaction:
name test store name = test
data is now { name: test }
0 1 data is now { name: test, 0: 1 }
? name output: test
! 0 delete 0
data is now { name: test }
hello good world data is now { name: test, hello: good }
the extra word "world" is ignored
egiwiwegiuwe the "otherwise" case: quit program
The user opens the newly generated program
? name output: test
name retest data is now { name: retest }
* clear
data is now { }
Sample implementation: https://gist.github.com/1128876
Rules
- You do not need to preserve comments or insignificant whitespaces in the quined program: just preserve the functionality and the data
- You cannot use any external storage.
- No cheating quines, like any other quine problems.
- Shortest code wins.
This reminds me of the time that I wrote a view in SQL Server that acted just like a table by using INSERT/UPDATE/DELETE triggers and storing the data in the view itself as
SELECT 1 AS ID, NAME AS BLAH UNION...
– mellamokb – 2011-08-06T05:10:11.493What's considered a cheating quine? – Casey Chu – 2011-08-08T07:58:36.097
Casey, reading own source code, usually. – Joey – 2011-08-08T08:21:40.047
Ah. My JS solution comes close to doing that, whoops. Oh well, since the spec isn't that clear about that, I'll leave it up at the risk of being downvoted. – Casey Chu – 2011-08-08T08:29:51.350