This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Converting Functions to Script Position Kathi Fisler, WPI October 2, 2007 Weve seen that in order to write programs that behave properly as scripts, we need to move code around so that scripts start the next part of the computation before they terminate (or, put another way, so that no code depends upon a value returned from a script). The last set of notes did this intuitively. This set of notes shows you a step-by-step method for converting non-web programs to web programs. 1 Script position A call to a script function is in script-position if the return value of the call is the return value of the expression or function that contains it. This is another way of saying that no additional computation in the program relies on the value of the call. Script-position is easiest to understand through examples. Assume we have a function called request-num : 1. In script position because the result of the call is the result of the whole expression (assuming this is the whole program). ( request-num Enter a num ) 2. Not in script position because the + uses the return value ( + ( request-num Enter a num ) 5 ) 3. In script position because the value of request-num is the value of the function that contains it. ( define ( req reqstr ) ( request-num reqstr )) 4. In script position because the cond is the whole expression and the answer of a cond clause is what the cond returns. ( cond [( = 5 4 ) ( request-num Enter a num )] [ else 7 ]) 5. Not in script position because the + uses the return value of the cond. ( + ( cond [( = 5 4 ) ( request-num Enter a num )] [ else 7 ]) 10 ) 6. Not in script position because the = needs the value of the request-num . The question position of a cond is never in script position.in script position....
View Full Document
- Fall '07