Guide
Your first session
Start to green in seven steps — including getting it wrong twice, which is the part a first session actually consists of. Every step below is executed as a test on every commit, so this walkthrough cannot go stale.
ptc new notes
cd notes
ptc test main.pt # 1 test(s): 1 passed; 0 failedThe scaffold is green before you edit anything: main.pt holds a real function with a real test block, and a README naming the four commands that matter. Nothing to configure, no convention to guess — the files teach the conventions by being correct.
Now write something of your own — and get it wrong the way everyone does, comparing a length to a string:
/// The longest of `words`, or "" when there are none.
fn longest(words: List[Text]) -> Text:
mut best = ""
for w in words:
if w.len() > best:
best = w
return bestcheck type-checks without running anything — which is exactly why the workbench can call it after every pause in your typing and underline the line while you are still on it. Fix the comparison to best.len() and check goes quiet.
The second mistake is the one a type checker cannot catch. Call the new code with an empty list, and it fails at run time — two functions deep:
fn initial(word: Text) -> Text:
return word.slice(0, 1)
fn banner(words: List[Text]) -> Text:
return initial(longest(words))That is the call stack: innermost first, each caller at its own call site. The message alone tells you a slice was out of range; the stack tells you which path got there — banner passed an empty list up from main. Guard the empty case, and the session ends green.