General Lock Notation

From Esolang
Jump to navigation Jump to search

The lock value consists of a set of identified rows, each of which consists of a sequence of integers, such that either all of the integers are zero or the first nonzero integer is positive.

The initial value consists of a lock value of this format, and is written as [ followed by the rows and then ] at the end; use ; to separate the rows, and , to separate the numbers within each row. If there are not enough numbers in a row, the rest are automatically assumed to be zero, and any number can be omitted in which case zero is assumed. A number is written in decimal ASCII format, and can have - at first if negative; if it is positive, + is allowed but is not required.

A kind of lock is a similar thing, but the restriction of the numbers mentioned above does not apply (they are still required to be integers), and it is possible for some of the numbers to be only for checking. When it is locked, the values in the kind of lock (other than those that are only for checking) are added to the current value of the lock, and when unlocked, they are subtracted; if this cannot be done while meeting the criteria then the lock is not possible. However, for the purpose of checking if the lock is possible, the numbers that are only for checking do count (but they are ignored for unlocking).

The syntax for a kind of lock is similar, but:

  • There are additional signs * and & which are like - and + but are numbers that are only for checking.
  • The number is optional if one of the signs +-*& is present; in this case, the number 1 is assumed. (If the number and sign are both omitted, then it will be 0.)
  • If the number is present, then the sign also must be present; the plus sign is not optional (unlike the initial value where it is optional).
  • When dealing with multiple separate locks simultaneously, use | to delimit the separate locks; this otherwise works like ;.
  • If an application needs to decide the numbers based on external circumstances, then you can specify the names of parameters in place of any numbers; these are ASCII alphabets and digits and underscores, and must start with alphabets.

It is assumed that all locks are atomic, including conversion from one lock to another.

(Some things are not mentioned yet, such as ordering, priority, etc.)

Examples

Shared/exclusive lock:

  • Initial value is [1]
  • Shared lock is [,-]
  • Exclusive lock is [-]