Pass

From Esolang
Jump to navigation Jump to search

Pass is a *practical* language invented by User:A. I am putting this documentation here because I am unsure whether this language is esoteric enough. (It is designed to be small, fast, and easy to read. (Although I feel that this language is very difficult to write useful code in.))

Language quick-reference

  • a:=b We set the variable a to the value of the variable b.
  • a:=1 We set the variable a to the value of 1. Strings also work here.
  • 1:=a This gets a bit trickier. This swaps the values and sets a to the value 1. Strings also work here.
  • All other possible combinations Raises a syntax error because I haven't found a use for this usage yet.

Some basic functionalities

  • (...) A string constant defining the string "...". Internally this is stored as a number converted from base-97 (printable ASCII plus newline plus tab).
  • Numbers Positive integers. They may not contain decimal points.
  • a-z These are variables of arbitary name length. Variables may only consist of lowercase letters and must be at least of length 1.
  • say ... Evaluate the expression in the body and output it to the console. Without a newline.
  • read Read a line from the input and store as a string.

The try function

  • try ... The most important concept of the Pass language. This executes the ... operand as a valid Pass source code (Pass tries to make random-typing valid source code...). The ... operand has to be a string (or a less-readable number) or a variable storing a string.

After the execution, the printed values are returned as values for other functions. A syntax error prints syntax error, hence the name. Expressions auto-print themselves (this can be set using flags of the interpreter as whether you need this thing or not. This can also be applied to the actual source code if you desparately need it.)

If multiple values are printed, the most recent item printed is returned. E.g.

try(1
2
3)+1

The above code snippet returns 4, since the try() returns 3 and 3+1 is 4.


  • pass ... When preceded with a try function, this executes ... before the try function. Otherwise, it is exactly the same as try.

The complex behavior for all of the operators

A full list of all of Pass's operators

There is an operator precedence in Pass. In order to group some values you use try().

! (Bitwise not)
* (Multiplication) / (Division) % (Modulo)
+ (Addition) - (Subtraction)
& (Bitwise and)
| (Bitwise or)
< (Less than) > (Greater than) => (Greater than/equal) <= (Less than/equal)
<> (Not equal) = (Equal)
:= (Assignment)
$ (Convert between numbers and strings)

The behavior of + on different data types.

  • 1+1 Evidently returns 2
  • a+1 You might say that this returns the variable's value plus 1. True, but there is a side-effect that this sets the value to the variable!
    • P.S. Avoid this weird thing by using try a+1.
    • PP.S. If the variable is a string, this converts the number to a string and concatenates it to a variable.
  • 1+a Return the number 1 plus the value of the variable a converted to a number when possible. When the variable is a number, add the number to the left operand. Otherwise if the variable is a string and only contains number characters, this converts the string to its number form and adds it to 1. Otherwise, it converts it from base-96 and adds the number.
  • 1+(!) This returns 4. ! converted from base-96 is 1 (NUL (0x00), Newline(0x01), space(0x02), and exclamation mark (0x03)).
  • (!!)+1 Behavior candidates:
    • (!!1) (The string !! concatenated with 1 to its string form)
    • ("") (Map the above mechanism to the whole string; this will definitely happen once I have lists available.)

Behavior of *

  • 1*1 Evidently returns 1
  • a*1 You might say that this returns the variable's value times 1. True, but there is a side-effect that this sets the value to the variable!
    • P.S. Avoid this weird thing by using try a*1.
    • PP.S. If the variable is a string, this repeats the string number times. OR multiply each value by the number.
  • 1*a Return the number 1 times the value of the variable a converted to a number when possible. When the variable is a number, multiply the number to the left operand. Otherwise if the variable is a string and only contains number characters, this converts the string to its number form and multiplies it to 1. Otherwise, it converts it from base-96 and multiplies the number.
  • 1*(!) This returns 3. ! converted from base-96 is 1 (NUL (0x00), Newline(0x01), space(0x02), and exclamation mark (0x03)).
  • (!!)*1:
    • (!!) (The string !! repeated once)
    • ("") (Map the above mechanism to the whole string; this will definitely happen once I have lists available.)

A sample program (Reverse a given string)

a:=(reverse)
x:=()
try strrev:=(x+try a%256+0*a/256
try strrev unless try a%256=try a/256)
say x

Sample output:

esrever

Explanation:

a:=(reverse)                             (This sets the variable a to the value of the string reverse)
x:=()                                    (Set x to the null string)
try                                      (Execute this thing.)
    strrev:=(                            (Name the executed string as strrev.)
             x+                          (Concatenate the string x with)
               try a                     (The value of the variable a)
                    %256                 (Modulo 256 (This returns the last character of the string))
                        +0*              (Discard the return value after the side-effect)
                           a/256         (Return the string without the last item)
try strrev                               (Execute this strrev string)
           unless try a%256              (Unless the last item of the string)
                            =try a/256   (is equal to the string without the last item))
say x                                    (Say the value of x to the console)

Print all integers

try p:=(say 0-i
say i+1 try p)

Explanation

(i is initially set to 0.)
try p:=         (Initialize a function)
       (say 0-i (Say negative i)
say i+1         (and i after being incremented by 1.)
        try p)  (Execute p.)

Golfed, removing unneccecary whitespace...

tryp:=(say0-isayi+1tryp)