Hi Dan,
I would be interested in some less model-like example to see the use of shadowing, do you have any link by hand?
Regarding your problem, that is, achieving shadowing, I think PowerBASIC multiline MACROs could come handy.
Complete explanation of what MACRO is you can find in the help file, your model case would look like this, let me know:
#COMPILE EXE
#DIM ALL
MACRO s2()
x += 1
END MACRO
MACRO s1()
LOCAL x AS LONG
x = 1
s2()
TXT.PRINT x
END MACRO
FUNCTION PBMAIN () AS LONG
DIM hWin AS DWORD
TXT.WINDOW("Dan example", 10, 10 ,25, 80) TO hWin
s1()
TXT.WAITKEY$
TXT.END
END FUNCTION
And here the conversion of PERL sample:
#COMPILE EXE
#DIM ALL
MACRO f1
LOCAL x AS LONG
x = 1
f2()
TXT.PRINT "x=", x
END MACRO
MACRO f2
LOCAL y AS LONG
y = 4
x += 1
f3()
TXT.PRINT "y=",y
END MACRO
MACRO f3
x += 1
y += 1
END MACRO
FUNCTION PBMAIN()
DIM hWin AS DWORD
TXT.WINDOW("Perl 2 PB", 10, 10 ,25, 80) TO hWin
f1()
TXT.WAITKEY$
TXT.END
END FUNCTION
Please note I used TXT pseudoconsole, as I do not have PB/CC but just PB/WIN 10. The TXT pseudoconsole works in both, so it is easier to port code from one language to other.
I must admit I am a bit scared by the shadowing, I can see it causing debugging hell when used improperly or by accident, but that is up to the programmer how he manages the order in his code, I guess
(Incidentally, you cannot copy the above compiler output to the clipboard.)
Ctrl-C does not work, but when you mark the text via mouse and use right click/Copy, it is placed in the clipboard, just tried it.
Petr
Bookmarks