The Dink Network

Reply to Re: The Three Pillars of Dink v1.08

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
August 29th 2005, 07:27 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
I didn't create dynamic scoping, I just implemented it. It's available in some programming languages, but most use static scoping (like C). Previous versions of Dink use pseudo-static scoping.

Has it anything to do with the separate int &y in bob()?

Indeed.

Dynamic scoping allows you to have multiple variables with the same name, and they won't interact with each other. You can do this now in Dink if you use seperate scripts or multiple instances of the same script (well, depending on the variable scoping issues).

Here's a slightly different example, where &save_x, &x, and &y are all global variables:

void main(void)
{
int &x = 4;
int &y = 6;
bob();
say_stop("&x, &y, &save_x", 1);
}

void bob()
{
int &y = 8;
function();
}

void function(void)
{
say_stop("&x, &y, &save_x", 1);
&x / 2;
}

What exactly happens in the say_stop statement in 'function'?

It looks for variables starting with the current function ('function'), and if the variable doesn't exist, we look for the variable in the calling function, ad infintum, until we reach the global variables.

function(void)
[No variables]
--------------------
bob(void)
&y = 8 //We use this &y
--------------------
main(void)
&x = 4 //We use this &x
&y = 6
--------------------
global
&x = 9
&y = 7
&save_x = 42 //We use this &save_x