Yes, you can define local variables in a schema using let or define inside a function. Using set! , you can also reassign the variable as you imagine.
Having said that, you probably shouldn't solve your problem this way. In the diagram, it is usually recommended to avoid set! when you donβt need (and in this case you definitely donβt need). Repeating the list using indexes is usually a bad idea, since schema lists are linked lists and O (n) is such random access (makes the last function the way you want to implement it O(n^2) ).
Thus, a simple recursive implementation without indexes will be more idiomatic and faster than what you plan to do and as such is preferable.
sepp2k
source share