January 25, 4092
Jump to navigation
Jump to search
January 25, 4092 is a joke esoteric language that can only be compiled on the specific date January 25, 4092.
This is the only valid program:
CheckDate(01254092) => True = {
Execute(main);
};
Interpreter
The following implementation is realized in Common Lisp:
(defstruct (Date
(:constructor make-date (year month day)))
"The Date class encapsulates a specific date, specified by its
year, month, and day, in a Gregorian date."
(year (error "Missing year.") :type (integer * *) :read-only T)
(month (error "Missing month.") :type (integer 1 12) :read-only T)
(day (error "Missing day.") :type (integer 1 31) :read-only T))
(defun make-date-from-year-month-and-day (year month day)
"Returns a fresh Date whose days are appropriated from the
specified YEAR, MONTH, and DAY."
(declare (type (integer * *) year)
(type (integer 1 12) month)
(type (integer 1 31) day))
(the Date (make-date year month day)))
(defun decode-date (timestamp)
"Returns a fresh Date derived from the TIMESTAMP, this
specifying the non-negative tally of seconds having elapsed since
January 1st, 1900 GMT, at 00:00:00 of time."
(declare (type (integer 0 *) timestamp))
(multiple-value-bind
(second minute hour day month year day-of-week
uses-daylight-saving-time-p time-zone)
(decode-universal-time timestamp)
(declare (type (integer 0 59) second) (ignore second)
(type (integer 0 59) minute) (ignore minute)
(type (integer 0 23) hour) (ignore hour)
(type (integer 1 31) day)
(type (integer 1 12) month)
(type integer year)
(type (integer 0 6) day-of-week) (ignore day-of-week)
(type boolean uses-daylight-saving-time-p)
(ignore uses-daylight-saving-time-p)
(type integer time-zone) (ignore time-zone))
(the Date (make-date year month day))))
(defun make-current-date ()
"Returns a fresh Date initialized with the current date."
(the Date (decode-date (get-universal-time))))
(defun equal-dates-p (first-date second-date)
"Determines whether the FIRST-DATE and the SECOND-DATE specify
the same point in time, returning on confirmation a boolean value
of T, otherwise NIL."
(declare (type Date first-date) (type Date second-date))
(the boolean
(not (null
(and (= (date-year first-date) (date-year second-date))
(= (date-month first-date) (date-month second-date))
(= (date-day first-date) (date-day second-date)))))))
;;; -------------------------------------------------------
(declaim (type (simple-string 43) +MINIMAL-VALID-PROGRAM+))
(declaim (type Date +VALID-COMPILATION-DATE+))
(defparameter +MINIMAL-VALID-PROGRAM+
"CheckDate(01254092)=>True={Execute(main);};"
"A valid \"January 25, 4092\" program without whitespaces.")
(defparameter +VALID-COMPILATION-DATE+
(make-date-from-year-month-and-day 4092 1 25)
"A \"January 25, 4092\" program's valid compilation date.")
;;; -------------------------------------------------------
(defun whitespace-character-p (candidate)
"Determines whether the CANDIDATE represents a whitespace, returning
on confirmation a boolean value of T, otherwise NIL."
(declare (type character candidate))
(the boolean
(not (null
(member candidate '(#\Space #\Tab #\Newline) :test #'char=)))))
(defun remove-whitespaces (source)
"Expunges all whitespaces from the SOURCE and returns the result."
(declare (type string source))
(the string (remove-if #'whitespace-character-p source)))
(defun validate-program (source)
"Determines the SOURCE's compliance with the sole
\"January 25, 4092\" program format, returning no value on
affirmation; otherwise signaling an error of an unspecified type."
(declare (type string source))
(unless (string= source +MINIMAL-VALID-PROGRAM+)
(error "Invalid program: ~s." source))
(values))
(defun validate-date (date)
"Determines the DATE's validity for a \"January 25, 4092\" program's
execution, returning no value on affirmation; otherwise signaling an
error of an unspecified type."
(declare (type Date date))
(unless (equal-dates-p date +VALID-COMPILATION-DATE+)
(error "Invalid compilation date: ~s." date))
(values))
(defun interpret-January-25-4092 (code &key (simulated-date (make-current-date)))
"Interprets the piece of \"January 25, 4092\" source CODE, optionally
imputing the SIMULATED-DATE in lieu of the current one, and returns
no value."
(declare (type string code) (type Date simulated-date))
(validate-program (remove-whitespaces code))
(validate-date simulated-date)
(values))