From Esolang
Jump to navigation Jump to search

Tomagotcha! is a set of semantics describing the construction of an interpreter for a "pseudo-esolang" whose only "instruction" is the mere execution of its interpreter.

"Language" overview

A Tomagotcha! interpreter's behavior is dependent upon what time it is when the program is executed. Upon invocation, the hours, minutes, and seconds of the current 12-hour time are obtained and summed. The resultant value's corresponding ASCII character must then be written to the interpreter's "memory" (the mechanics of which are the implementer's prerogative) such that it may be recalled upon subsequent runs. In this manner, a Tomagotcha! "program" accrues sequentially over the course of repeated invocations.

However, if it is the case upon execution that a given Tomagotcha! interpreter has not been invoked within the last four hours, the whole of its memory is recalled and evaluated as a program under the rules of the host language, thereby achieving computation, the "class" of which is simply inherited from the parent language except in extremely rare (read: as yet undiscovered) circumstances.

Finally, if the child program was evaluated without error, the interpreter discards its memory and terminates. Otherwise and alas, it must intentionally destroy itself. Thus, a conforming Tomagotcha! interpreter must be diligently interacted with at least six times daily in order to perform meaningful work.

Reference implementation

Though not strictly required, a Tomagotcha! interpreter is advised to perform the elegant optimization of keeping its brain in its tail.

#!/usr/bin/env ruby

if (t = - File.mtime($0) > 14400
  eval rescue `rm #$0` and exit
  exit IO.write($0, `head -n #{DATA.lineno - 1} #$0`)

`echo -n '#{eval(t.strftime '%H+%M+%S').chr}' >> #$0`