Not

From Esolang
Jump to navigation Jump to search

Not is a esolang made for one task. It only has a few commands

the whole thing

Typing out a 1 will push a 1 onto the stack. A + will combine the top to elements on the stack and a = will duplicate it. And # will pop the top of the stack off and print it. Then [] will loop forever. Also N prints a newline.

Furnished in a tabulated format, the operative sextuple comprehends:

Command Description
1 Pushes the digit 1 onto the stack.
+ Pops the top stack item a and the new top item b, appends b to a, and pushes the result onto the stack.
= Duplicates the top stack item.
# Pops the top stack item and prints it.
N Prints a newline.
[] Loops infinitely.

The one program Not was made for:

1#N1[1+=#N]

This prints:

1
11
111
1111

And so on.

why tho

This was made because in the Black page it says that the above output cannot be done by a pushdown automata. But this is a pushdown automata. i could be wrong though. wait… its not. ok. or is it. aaaaaaah. see my problem is if it really can do the program it does(which it can!!) then it is sub-TC

Implementation

An implementation in Common Lisp shall be proposed:

(defun interpret-Not (code)
  "Interprets the piece of Not source CODE and returns no value."
  (declare (type string code))
  (let ((stack            NIL)
        (loop-start-point NIL))
    (declare (type list             stack))
    (declare (type (or null fixnum) loop-start-point))
    (flet ((pop-from-stack ()
            "Removes and returns the top STACK element, or signals an
             error of an unspecified type upon its disrespondency."
            (the string
              (or (pop stack)
                  (error "Popping from an empty stack is like drinking ~
                          from an empty well: I would not rede ~
                          such."))))
           (peek-into-stack ()
            "Returns without removing the top STACK element, or signals
             an error of an unspecified type upon its disrespondency."
            (the string
              (or (first stack)
                  (error "If you peek into an empty stack, the empty ~
                          stack peeks/pokes back into you.")))))
      (loop
        with ip of-type fixnum = 0 while (< ip (length code)) do
          (case (char code ip)
            (#\1 (push "1" stack))
            (#\+ (push (format NIL "~a~a" (pop-from-stack) (pop-from-stack))
                       stack))
            (#\= (push (peek-into-stack) stack))
            (#\# (format T "~a" (pop-from-stack))
                 (finish-output))
            (#\N (format T "~%"))
            (#\[ (setf loop-start-point ip))
            (#\] (if loop-start-point
                   (setf ip loop-start-point)
                   (error "I do not know where to start... and you, ~
                           excuse my frankness, obviously neither; ~
                           as intimated by the unmatched loop end at ~
                           position ~d." ip)))
            ((#\Space #\Tab #\Newline) NIL)
            (otherwise
              (error "Invalid token \"~c\" at position ~d."
                (char code ip) ip)))
          (incf ip)
        finally
          (when loop-start-point
            (error "Please, never start a loop which you do not ~
                    intend to end---such as that at position ~d."
              loop-start-point)))))
  (values))

see also