From Esolang
Jump to navigation Jump to search
The title of this article is incorrect because of technical limitations. The correct title is vv.

vv is an esolang created by User:Username1234.

Brief intro

There are only two useful characters in this language: v and ^. If you want to write annotation, you need to write it behind a )).


^ separates the operators so all you need to care about is the number of v in every operator.

Caption text
Number Meaning
1 Push v into the stack
2 Pop the top of the stack
3 Print the top of the stack
4 Change the ASCII of the top of the stack by one
5 Change the ASCII of the top of the stack by negative one
6 Change the top to (the ASCII of the top element)the ASCII of the top element mod 128
7 End of the programme


Print out "CCF"



The following program in Common Lisp offers an interpreter for the language:

(defun interpret-v^v (code &aux (code-length (length code)) (position 0) (command 0) (stack NIL))
  "Executes the piece of v^v CODE and returns NIL."
  (declare (type string code) (type fixnum code-length position) (type (integer 0 *) command) (type list stack))
  (symbol-macrolet ((finished-p (>= position code-length))
                    (token      (the character (char code position))))
    (flet ((execute-command ()
            (case command
              (1 (push command stack))
              (2 (pop stack))
              (3 (write-char (code-char (first stack))))
              (4 (incf (first stack)))
              (5 (decf (first stack)))
              (6 (setf (first stack) (mod (expt (first stack) (first stack)) 128)))
              (7 (setf position code-length))
              (otherwise (error "Invalid command: ~d." command)))
      (loop until finished-p do
        (case token
            (setf command 0)
            (incf position))
            (setf command
              (loop while (and (not finished-p) (char= token #\v))
                    do (incf position)
                    count 1)))
            (incf position)
            (if (and (not finished-p) (char= token #\)))
              (loop until finished-p do (incf position))
              (error "Invalid token starting with ')'.")))
            (error "Invalid token ~s at position ~d." token position)))
        finally (execute-command)))))

The arduous process of generating a message output program can be alleviated by the following function:

(defun build-message-program (text &key (destination NIL))
  "Creates a v^v program which outputs the TEXT and writes the code to
   the DESTINATION, returning for a non-NIL DESTINATION the NIL value,
   otherwise responding with a fresh string containing the result."
  (declare (type string text) (type (or null (eql T) stream string) destination))
  (the (or null string)
    (if destination
      (loop for character of-type character across text do
          ;; Push the number one (1) unto the stack.
          (format destination "v^")
          ;; Increment the one-valued top stack element until it matches
          ;; the CHARACTER's ASCII code.
          (loop repeat (1- (char-code character)) do
            (format destination "vvvv^"))
          ;; Print the top of the stack as an ASCII character.
          (format destination "vvv^")
          ;; Pop the just printed top of the stack.
          (format destination "vv^")
        ;; Write program end.
        finally (format destination "vvvvvvv"))
      (with-output-to-string (output)
        (declare (type string-stream output))
        (build-message-program text :destination output)))))