= = = WRIST SCRIPT = = =

Wrist Script is a programming language for the Apple Watch by Jack Eisenmann. Here is a demonstration of Wrist Script:

Demonstration Video

= CREATING A PROGRAM =

To create a program, press the "Create New" button and enter the name of your program. This will lead you to the command list page for the new program. If you force touch on the command list page, you can perform various actions on your program.

To add a command to the end of a program, press the "Add Command" button. This will lead you to a series of menus where you can select the command. After you add the command, it will be displayed on the command list page.

If you press a command on the command list page, the application will display the command page. The command page shows all of the arguments for the command. By default, all of the arguments are unassigned. To assign an argument, tap on the argument and select a value. A command cannot be executed if any of its arguments are unassigned.

If you force touch on the command page, you can perform various actions including clipboard operations. The clipboard can hold a single command at a time.

To run your program, force touch on the command list page and press "Run". You can enter text input by pressing "Input Text". When the program has ended successfully, the application will display "Done". If the program encounters a problem, the application will display an error message.

= WRIST SCRIPT FEATURES =

Wrist script has a variety of data types:

A variable holds a single value. A variable must be declared with Variable before it may be used. Example:

Variable X
Set X "Hello"
Print X

Several commands are followed by a code block terminated by End. Example:

Print "Start of program"
If 1.0
  Print "Will be displayed"
End
Print "Middle of program"
If 0.0
  Print "Will NOT be displayed"
End
Print "End of program"

Wrist Script has a notion of global scope and local scope. Variables declared outside of a function are global. Variables declared inside of a function are local. The example program below will print 0.0 then 1.0:

Function Action Z
  Variable X
  Set X 1.0
  Set Y 1.0
End
Variable X
Variable Y
Variable Z
Set X 0.0
Set Y 0.0
Call Z Action 0.0
Print X
Print Y

= LIST OF COMMANDS =

Input Output

Print (Message): Adds a line of text to the console.

Prompt String (Destination): Waits for the user to enter text in the console.

Prompt Number (Destination): Waits for the user to enter a number in the console.

Variable

Variable (Name): Declares a variable in the current scope.

Set (Destination) (Value): Stores a value in a variable.

Arithmetic

Add (Destination) (Operand 1) (Operand 2): Adds two numbers together.

Subtract (Destination) (Operand 1) (Operand 2): Subtracts operand 2 from operand 1.

Multiply (Destination) (Operand 1) (Operand 2): Multiplies two numbers together.

Divide (Destination) (Operand 1) (Operand 2): Divides operand 1 by operand 2.

Modulus (Value) (Operand 1) (Operand 2): Finds the remainder when dividing operand 1 by operand 2.

Increment (Value): Increments a number by one.

Decrement (Value): Decrements a number by one.

Comparison

Less Than (Destination) (Operand 1) (Operand 2): Determines whether operand 1 is less than operand 2.

Less Or Equal (Destination) (Operand 1) (Operand 2): Determines whether operand 1 is less than or equal to operand 2.

Equal (Destination) (Operand 1) (Operand 2): Determines whether operand 1 equals operand 2. Works for all value types.

Not Equal (Destination) (Operand 1) (Operand 2): Determines whether operand 1 does not equal operand 2. Works for all value types.

Greater Than (Destination) (Operand 1) (Operand 2): Determines whether operand 1 is greater than operand 2.

Greater Or Equal (Destination) (Operand 1) (Operand 2): Determines whether operand 1 is greater than or equal to operand 2.

Boolean

Not (Destination) (Operand): Determines logical NOT of the operand.

Or (Destination) (Operand 1) (Operand 2): Determines logical OR of operand 1 and operand 2.

And (Destination) (Operand 1) (Operand 2): Determines logical AND of operand 1 and operand 2.

Xor (Destination) (Operand 1) (Operand 2): Determines logical XOR of operand 1 and operand 2.

Bitwise

Bitwise Not (Destination) (Operand): Determines bitwise NOT of the operand.

Bitwise Or (Destination) (Operand 1) (Operand 2): Determines bitwise OR of operand 1 and operand 2.

Bitwise And (Destination) (Operand 1) (Operand 2): Determines bitwise AND of operand 1 and operand 2.

Bitwise Xor (Destination) (Operand 1) (Operand 2): Determines bitwise XOR of operand 1 and operand 2.

Conversion

To String (Destination) (Operand): Converts the operand to a string.

To Number (Destination) (Operand): Converts the operand to a number.

Control

If (Condition): Ignores the following code block if the condition is 0.0.

Else: Inverts whether an If code block is being ignored.

End: Ends a code block.

While (Condition): Repeats execution of the code block until the condition is 0.0.

Break: Skips to after the end of a While code block.

Continue: Skips to the beginning of a While code block.

Function (Function Name) (Argument Name): Declares a function with the following code block. Upon invocation, the argument will be placed in a variable with the given name.

Return (Value): Stores the value in the invocation destination, then exits the function.

Call (Destination) (Function) (Value): Calls the function, passing the value as the argument. Stores the return value in the given destination.

Math

Random (Destination) (Minimum) (Maximum): Generates a random integer between the given values inclusive.

Round (Destination) (Operand): Rounds the operand to the nearest integer.

Sine (Destination) (Operand): Computes the sine of the operand.

Cosine (Destination) (Operand): Computes the cosine of the operand.

Tangent (Destination) (Operand): Computes the tangent of the operand.

Power (Destination) (Base) (Exponent): Raises the base to the exponent.

Log (Destination) (Base) (Operand): Computes log of the operand in the given base.

Collection

Merge (Destination) (Operand 1) (Operand 2): Creates a new value containing all of the elements of the operands.

Concatenate (Destination) (Operand 1) (Operand 2): Creates a new value containing operand 1 concatenated with operand 2.

Get Size (Destination) (Collection): Retrieves the size of the value.

Set Size (Collection) (Size): Sets the size of the value.

Shallow Copy (Destination) (Collection): Copies the value one level deep.

Deep Copy (Destination) (Collection): Copies the value recursively.

Shallow Equal (Destination) (Operand 1) (Operand 2): Determines value equality one level deep.

Deep Equal (Destination) (Operand 1) (Operand 2): Determines value equality recursively.

Has Key (Destination) (Map) (Key): Determines whether the map contains the key.

Get Keys (Destination) (Map) (Key): Retrieves a list of keys in the map.

Element

Get Element (Destination) (Collection) (Index): Retrieves a value from the collection.

Set Element (Collection) (Index) (Value): Sets a value in the collection.

Find Element (Destination) (Collection) (Value): Determines the index of the value in the collection. If the value could not be found, returns -1.0.

Push Element (Collection) (Value): Adds the value to the end of the sequence.

Pop Element (Destination) (Collection): Removes the value from the end of the sequence.

Insert Element (Collection) (Index) (Value): Inserts a value into the collection.

Remove Element (Collection) (Index): Removes a value from the collection.

Subsequence

Get Subsequence (Destination) (Collection) (End Index) (Start Index): Retrieves a subsequence from the collection.

Set Subsequence (Collection) (Start Index) (End Index) (Value): Sets a subsequence in the collection.

Find Subsequence (Destination) (Collection) (Value): Determines the index of the subsequence in the collection. If the subsequence could not be found, returns -1.0.

Push Subsequence (Collection) (Value): Adds the subsequence to the end of the sequence.

Pop Subsequence (Destination) (Collection) (Length): Removes the subsequence from the end of the sequence.

Insert Subsequence (Collection) (Index) (Value): Inserts a subsequence into the collection.

Remove Subsequence (Collection) (Start Index) (End Index): Removes a subsequence from the collection.

= EXAMPLE PROGRAMS =

Greet the user:

Print "What is your name?"
Variable X
Prompt String X
Concatenate X "Hello, " X
Concatenate X X ", nice to meet you!"
Print X

Print numbers between 1 and 10:

Variable X
Variable Z
Set X 1.0
Set Z 1.0
While Z
  Print X
  Increment X
  Less Or Equal Z X 10
End

Print prime numbers:

Function IsPrime X
  Variable Y
  Variable Z
  Set Y 2.0
  While 1.0
    Modulus Z X Y
    Not Z Z
    If Z
      Return 0.0
    End
    Increment Y
    Greater Or Equal Z Y X
    If Z
      Return 1.0
    End
  End
End
Variable X
Variable Z
While 1.0
  Call Z IsPrime X
  If Z
    Print X
  End
  Increment X
  Greater Z X 50
  If Z
    Break
  End
End

If you find any problems with Wrist Script, please send a message to esperantanaso at gmail.

Return to the Ostracod Pond