 :: mutable-example ( -- quot1 quot2 )
     5 :> a! [ a ]
     6 a! [ a ] ;
-rebinding-example [ call . ] bi@
-mutable-example [ call . ] bi@"
-"5
-6
-6
-6"
+rebinding-example [ call( -- x ) ] bi@
+mutable-example [ call( -- x ) ] bi@"
+"\n--- Data stack:\n5\n6\n6\n6"
 }
     "In " { $snippet "rebinding-example" } ", the binding of " { $snippet "a" } " to " { $snippet "5" } " is closed over in the first quotation, and the binding of " { $snippet "a" } " to " { $snippet "6" } " is closed over in the second, so calling both quotations results in " { $snippet "5" } " and " { $snippet "6" } " respectively. By contrast, in " { $snippet "mutable-example" } ", both quotations close over a single binding of " { $snippet "a" } ". Even though " { $snippet "a" } " is assigned to " { $snippet "6" } " after the first quotation is made, calling either quotation will output the new value of " { $snippet "a" } "."
 { $heading "Lexical variables in literals" }
 "Some kinds of literals can include references to lexical variables as described in " { $link "locals-literals" } ". For example, the " { $link 3array } " word could be implemented as follows:"
 { $example
-"USING: locals prettyprint ;
+"USING: locals ;
 IN: scratchpad
 
 :: my-3array ( x y z -- array ) { x y z } ;
-1 \"two\" 3.0 my-3array ."
-"{ 1 \"two\" 3.0 }"
+1 \"two\" 3.0 my-3array"
+"\n--- Data stack:\n{ 1 \"two\" 3.0 }"
 } ;
 
 ARTICLE: "locals-literals" "Lexical variables in literals"

{ $heading "Quotations with lexical variables, and closures" }
"These next two examples demonstrate lexical variable bindings in quotations defined with " { $link POSTPONE: [| } ". In this example, the values " { $snippet "5" } " and " { $snippet "3" } " are put on the datastack. When the quotation is called, it takes those values as inputs and binds them respectively to " { $snippet "m" } " and " { $snippet "n" } " before executing the quotation:"
{ $example
    "USING: kernel locals math prettyprint ;"
    "IN: scratchpad"
    "5 3 [| m n | m n - ] call ."
    "2"
}
$nl

"In this example, the " { $snippet "adder" } " word creates a quotation that closes over its argument " { $snippet "n" } ". When called, the result quotation of " { $snippet "5 adder" } " pulls " { $snippet "3" } " off the datastack and binds it to " { $snippet "m" } ", which is added to the value " { $snippet "5" } " bound to " { $snippet "n" } " in the outer scope of " { $snippet "adder" } ":"
{ $example
    "USING: kernel locals math prettyprint ;"
    "IN: scratchpad"
    ":: adder ( n -- quot ) [| m | m n + ] ;"
    "3 5 adder call ."
    "8"
}
$nl

{ $heading "Mutable bindings" }
"This next example demonstrates closures and mutable variable bindings. The " { $snippet "<counter>" } " word outputs a tuple containing a pair of quotations that respectively increment and decrement an internal counter in the mutable " { $snippet "value" } " variable and then return the new value. The quotations close over the counter, so each invocation of the word gives new quotations with a new internal counter."
{ $example
"USING: locals kernel math ;
IN: scratchpad

TUPLE: counter adder subtractor ;

:: quadratic-roots ( a b c -- x y )
    b sq 4 a c * * - sqrt :> disc
    b neg disc [ + ] [ - ] 2bi [ 2 a * / ] bi@ ;
1.0 1.0 -6.0 quadratic-roots"
"\n--- Data stack:\n2.0\n-3.0"
}
"If you wanted to perform the quadratic formula interactively from the listener, you could use " { $link POSTPONE: [let } " to provide a scope for the variables:"
{ $example "USING: locals math math.functions kernel ;
