# PCASTLI version 1.5 # this function generates functions that displays alternatively n results toggle_gen = function(n) { if (n <= 0) return(copytree(`function() {}'.childset[0])) if (n == 1) return(copytree(`function() 1'.childset[0])) a = function() { 1 b = parent.parent.childset[0] print(value(b)) # value substitution if (value(b) == 1) { *b = `2' } else { *b = `1' } {} } # to have a new function returned at each toggle_gen call a = copytree(a) else_pt = a.childset[1].childset[3].childset[2] for (i = 2; i < n; i++) { new_stmt = `if (value(b) == 1) { *b = `2' } else { *b = `1' }'.childset[0] # localization of the first 1 in new_stmt # with no ';', the interpreter will take the '*' as the binary operator num1 = new_stmt.childset[0].childset[1]; *num1 = tonode(i) # localization of the 2 in new_stmt num2 = new_stmt.childset[1].childset[0].childset[1].childset[0]; *num2 = tonode(i + 1) else_pt = (*else_pt = new_stmt) else_pt = else_pt.childset[2] } a } toggle_3 = toggle_gen(3) for(i = 0; i < 5; i++) toggle_3() toggle_4 = toggle_gen(4) for(i = 0; i < 6; i++) toggle_4() toggle_5 = toggle_gen(5) for(i = 0; i < 7; i++) toggle_5()