5-logic

From Esolang
Jump to navigation Jump to search

Description

+-------+    Adjacent  Opposite
|       | !    @%        #$
|   !   | @    #!        $%
| %   @ | #    $@        %!
|  $ #  | $    %#        !@
|       | %    !$        @#
+-------+

A value can be:

  • 5-value: one of ! @ # $ %
  • List: list of zero or more values inside square brackets. For example: [![Zero@@][[]]{2_0_Take}]
  • Variable name: Name of a variable, first letter uppercase rest lowercase (only letters).
  • Program code: A program code with curly brackets. Use semicolons to separate commands. Example: {A=!;B=%;2AB}

Commands:

  • value - Return this value from this function
  • var=value - Set a value of a variable
  • \name - External system function
  • /*comment*/ - Comment
  • -var - Makes a new variable local to this block of program code and sub-calls
  • --var - Same as above but initial value is argument of this function-call.
  • value:code - For each element in list(value), execute code, element is argument, return value exits loop and returns from parent code. (Error if value is not a list or the name of a variable containing a list)
  • ?value - Return this value from the function if previous line changed a value of a variable to a 5-value adjacent to its previous value. (Error if either value isn't a 5-value. Even error if new or old value is a variable name.)

Operators:

  • 2xy - 2-logic on values. 2-logic on adjacent values = common opposite value. 2-logic on opposite values = common adjacent value. 2-logic on 2 same values = value.
  • 3xyz - 3-logic on values. 3-logic on xyz = (x if x=2yz, y if y=2xz, z if z=2xy). 3-logic on xxy = y. 3-logic on xxx = x.
  • `xy - Apply function x to argument y.
  • +xy - Concatenate 2 lists.
  • ^x - Include contents of a list inline. Example: 2^[!%] --> 2!% --> # and [!2^[###]!] --> [!2###!] --> [!##!]
  • 0 - Uses argument of this function.
  • 1 - Uses argument of parent function.

When evaluating parameters to 2 or 3, convert variable names to their values. If one or more parameters is a list, they must all be of the same length, then iterates through list in order using non-lists as well. For example: 2[ab]c = 2[ab][cc] and 3[[!@]$][%[$]]% --> [[3!%%3@%%][3$$%]] --> [[!@][%]] (If variables are undefined or lists of not matching size, or are program codes, then is error.)

For ^ and + commands, variable names are converted to values of variabled. Errors if 5-value or program-codes or undefined variabled.

For ` command, the function x is converted to its value if is a variable name. If x is a 5-value or a list or undefined variable, then is error.

Examples

If you want to use binary functions, and you use !=1 and @=0 then you can do:

NOT x = 22x$$
x XOR y = 3xy@
x AND y = 2!`{320$20@0}2$2xy
x OR y = 2@`{320$20!0}2$2xy

For example:

Not={220$$};
A=`NotB;