#lang planet wrturtle/pyret/bsl # Templates let you get the form of your code right, # before you fill in the details. # Let's try and write a function that consumes a list # of numbers, and produces the list with each number # incremented by 1. In other words, f([1,2,3]) = [2,3,4] # First, let's get the form of the function right with # a template: fun with_templates(l): if is_empty(l): .. else: ... # (At the interactions window, try # > with_templates([1,2,3]) # to see what happens) # Now, we'll fill in the function fun filled_in(l): if is_empty(l): empty else: cons(add1(first(l)), filled_in(rest(l))) # and of course, we test the function test: filled_in([]) is: [] test: filled_in([1,2,3]) is: [2,3,4]