Welcome to ✨ Spindle's User Documentation ✨

The language used in the AP CSP Exam, now a programming language!

tips_and_updates

Pro Tip: Spindle's syntax mirrors what you'll see on the AP CSP exam, helping you feel confident on test day.

Programming Guide

data_object Variables

Varibles can be assigned a value using "<--" OR "<-" For example, the following code sets a to 10 and then to 13 (a's value plus 3).

variables.spdl
a <- 10
a <-- [1,2,3]

Varibles can be assigned to other varibles!

assignment.spdl
b <-- a / 2

If you added this line to the lines above, it would set b to a's value divided by 2, resulting in 6.5

code Logical Operators

NOT

Negates the condition

AND

Returns TRUE if both conditions are TRUE

OR

Returns TRUE if at least one condition is TRUE

🆚 Comparison Operators:

In this language:
0 is FALSE
1 is TRUE
The supported comparison operators are:

  1. <       4. >=
  2. <=    5. ==
  3. >       6. !=

❔ If Statements:

If Statements can be defined with the keyword IF, and then the expression that must be true. The code that is to be ran when the the condition is met must be wrapred in brackets. If the condition for the IF statement is false, you can write an ELSE statement that will be ran instead

if_statement.spdl
a <-- 5
IF a==5 {
    DISPLAY(1)
} ELSE {
    DISPLAY(0)
}

loop Loops

For Loops (REPEAT TIMES)

For Loops are defined by the keyword REPEAT, followed by the number of times you want it to repeat, the keyword TIMES, and finally the code you want to be repeated.

for_loop.spdl
a <-- 5
REPEAT 10 TIMES {
    a <-- a + 1
}
DISPLAY(a)  # Output: 15

While Loops (REPEAT UNTIL)

While loops use REPEAT UNTIL, followed by a condition in parentheses, and the code block in curly braces. The loop continues until the condition becomes true.

while_loop.spdl
a <-- 10
REPEAT UNTIL (a > 30) { 
    a <-- a + 4
}  # Final value: 34

function Functions

Procedures (Functions)

Functions are defined using the keyword 'PROCEDURE', followed by the function name and arguments in parentheses, with the code block in curly braces.

function.spdl
PROCEDURE SAY_HI(excitement) {
    REPEAT excitement TIMES {
        DISPLAY("Hi!")
    }
}

SAY_HI(3)  # Outputs: Hi! Hi! Hi!

Built-in Functions

display.spdl
DISPLAY(value)

DISPLAY(value): Outputs the value to the console. You can display numbers, strings, lists, or the result of an expression.

input.spdl
INPUT()

INPUT(): Prompts the user for input and returns the value entered. Useful for interactive programs.

is_num.spdl
IS_NUM(value)

IS_NUM(value): Returns 1 if the value is a number, 0 otherwise. Useful for checking data types before performing calculations.

is_str.spdl
IS_STR(value)

IS_STR(value): Returns 1 if the value is a string, 0 otherwise. Use this to check if a variable contains text.

is_list.spdl
IS_LIST(value)

IS_LIST(value): Returns 1 if the value is a list, 0 otherwise. Use this to check if a variable contains a list/array.

is_function.spdl
IS_FUNCTION(value)

IS_FUNCTION(value): Returns 1 if the value is a function/procedure, 0 otherwise. Useful for advanced programming and debugging.

append.spdl
APPEND(list, value)

APPEND(list, value): Adds the value to the end of the list. Use this to grow a list dynamically.

pop.spdl
POP(list, index)

POP(list, index): Removes and returns the element at the specified index from the list. Indexing starts at 1.

extend.spdl
EXTEND(listA, listB)

EXTEND(listA, listB): Adds all elements from listB to the end of listA. Useful for combining lists.

length.spdl
LENGTH(list)

LENGTH(list): Returns the number of elements in the list. Note: List indexing starts at 1, following College Board conventions.

clear.spdl
CLEAR()

CLEAR(): Clears the console. Note: This function is only available in the Native IDE.

run.spdl
RUN("filename")

RUN("filename"): Runs another Spindle file by filename. Note: This function is only available in the Native IDE.

Robot IDE Built-in Functions

robot_example.spdl
# Example: Move forward if possible, then turn left
IF CAN_MOVE("NORTH") {
    MOVE_FORWARD()
}
ROTATE_LEFT()
MOVE_FORWARD()

library_books Additional Resources

description

AP CSP Exam Reference Sheet

Download PDF
play_circle

Video Tutorial by CodePulse

Watch on YouTube