2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,5 +1,8 @@
The task is to explain or demonstrate the levels of visibility of function names and labels within the language.
;Task:
Explain or demonstrate the levels of visibility of function names and labels within the language.
;See also
;See also:
* [[Variables]] for levels of scope relating to visibility of program variables
* [[Scope modifiers]] for general scope modification facilities
<br><br>

View file

@ -0,0 +1,12 @@
IF PROC x = ...;
...
THEN
# can call x here #
PROC y = ...;
...
GO TO l1 # invalid!! #
ELSE
# can call x here, but not y #
...
l1: ...
FI

View file

@ -1,44 +1,52 @@
/*Abhishek Ghosh, 8th November 2013, Rotterdam*/
#include<stdio.h>
/* Abhishek Ghosh, 8th November 2013, Rotterdam */
#include <stdio.h>
#define sqr(x) x*x
#define greet printf("\nHello There !");
#define sqr(x) ((x) * (x))
#define greet printf("Hello There!\n")
int twice(int x)
{
return 2*x;
return 2 * x;
}
int main()
int main(void)
{
int x;
printf("\nThis will demonstrate function and label scopes.");
printf("\nAll output is happening throung printf(), a function declared in the header file stdio.h, which is external to this program.");
printf("\nEnter a number : ");
scanf("%d",&x);
printf("This will demonstrate function and label scopes.\n");
printf("All output is happening throung printf(), a function declared in the header stdio.h, which is external to this program.\n");
printf("Enter a number: ");
if (scanf("%d", &x) != 1)
return 0;
switch(x%2){
default:printf("\nCase labels in switch statements have scope local to the switch block.");
case 0: printf("\nYou entered an even number.");
printf("\nIt's square is %d, which was computed by a macro. It has global scope within the program file.",sqr(x));
break;
case 1: printf("\nYou entered an odd number.");
goto sayhello;
jumpin: printf("\n2 times %d is %d, which was computed by a function defined in this file. It has global scope within the program file.",x,twice(x));
printf("\nSince you jumped in, you will now be greeted, again !");
sayhello: greet
if(x==-1)goto scram;
break;
};
printf("\nWe now come to goto, it's extremely powerful but it's also prone to misuse. It's use is discouraged and it wasn't even adopted by Java and later languages.");
if(x!=-1){
x = -1; /*To break goto infinite loop.*/
goto jumpin;
}
scram: printf("\nIf you are trying to figure out what happened, you now understand goto.");
return 0;
switch (x % 2) {
default:
printf("Case labels in switch statements have scope local to the switch block.\n");
case 0:
printf("You entered an even number.\n");
printf("Its square is %d, which was computed by a macro. It has global scope within the translation unit.\n", sqr(x));
break;
case 1:
printf("You entered an odd number.\n");
goto sayhello;
jumpin:
printf("2 times %d is %d, which was computed by a function defined in this file. It has global scope within the translation unit.\n", x, twice(x));
printf("Since you jumped in, you will now be greeted, again!\n");
sayhello:
greet;
if (x == -1)
goto scram;
break;
}
printf("We now come to goto, it's extremely powerful but it's also prone to misuse. Its use is discouraged and it wasn't even adopted by Java and later languages.\n");
if (x != -1) {
x = -1; /* To break goto infinite loop. */
goto jumpin;
}
scram:
printf("If you are trying to figure out what happened, you now understand goto.\n");
return 0;
}

View file

@ -0,0 +1,5 @@
c_thingy_=: 3
d=: <'test'
e__d=: 4
b + e_test_
6

View file

@ -0,0 +1,8 @@
verb define ''
f=. 6
g=: 7
g=. 8
g=: 9
)
|domain error
| g =:9

View file

@ -0,0 +1,4 @@
function global:Get-DependentService
{
Get-Service | Where-Object {$_.DependentServices}
}

View file

@ -0,0 +1 @@
Get-Help about_Scopes

View file

@ -1,17 +1,15 @@
/*REXX program demonstrates use of labels and a CALL statement. */
zz=4
signal do_add /*transfer program control to a label.*/
ttt=sinD(30) /*this REXX statement is never executed.*/
/* [↓] Note the case doesn't matter. */
do_Add: /*coming here from the SIGNAL statement.*/
/*REXX program demonstrates the use of labels and also a CALL statement. */
blarney = -0 /*just a blarney & balderdash statement*/
signal do_add /*transfer program control to a label.*/
ttt = sinD(30) /*this REXX statement is never executed*/
/* [↓] Note the case doesn't matter. */
DO_Add: /*coming here from the SIGNAL statement*/
say 'calling the sub: add.2.args'
call add.2.args 1,7 /*pass two arguments: 1 and a 7 */
say 'sum =' result
exit /*stick a fork in it, 'cause we're done.*/
/*────────────────────────────────subroutines (or functions)────────────*/
add.2.args: procedure; parse arg x,y; return x+y
add.2.args: say 'Whoa Nelly!! Has the universe run amok?'
/* [↑] dead code, never XEQed*/
add.2.args: return arg(1) + arg(2) /*concise, but never executed.*/
call add.2.args 1, 7 /*pass two arguments: 1 and a 7 */
say 'sum =' result /*display the result from the function.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
add.2.args: procedure; parse arg x,y; return x+y /*first come, first served ···*/
add.2.args: say 'Whoa Nelly!! Has the universe run amok?' /*didactic, but never executed*/
add.2.args: return arg(1) + arg(2) /*concise, " " " */