Main Page News Articles Books Fy++ samples Video Files Album Contact Me
Second sample Test

Fy++ code examples

Delegate


void melody (void (int) how)
{
	how (1200);	// Play the specified frequency
	how (420);	// .. and again
	how (600);
	how (800);
}

void initialize ()	// Entry point
{
		// Set up initial sound delay
	int	delay = 200;
		// Create a delegate playing sound
		// using 'delay' variable from
		// parent's procedure
	void (int) how = delegate (int freq)
			{beep (freq, delay)};
	melody (how);	// Play t
}

Immediate array

int[] manage_array ()
{
	int	a, b, c; // Declare int variables
	any[]	L = {0, 30, 0};	// Create an array
			// with variable type

	// Add some immediate values
	L += {10, 1024, 2801, {20000, 0, 0, 0}};
		// Add some variable values
	L += {a, b, c, 0};
		// ... and again
	L += {'XXXXXX', L, 0.3232, a, b, {a,c}, 0};

	// return an array intialized by three values
	return {0, 100, -1};
}

Option

void copy_file (string file, string path)
{
// Create a progress control to reflect changes
	Progress progress;

	option MaxFileSize = 10000; // Set a temporary option

	option OnFileExists = delegate(string fname)
		{error "The file \$fname already exists"};

	option OnJobProgress = delegate (int done)
		{progress.done = done};

// Copy file. This function indirectly uses three
// global variables that we have just set up.
	progress.total = filesize(file);
	copyfile (file, path);

// At exit all variables refered in option statement
// should be restored, it doesn't metter how this
// function terminates, either by exit or by throw.
}
Copyright (c) Sapunov Vladimir 2006-2008 e-mail: vladimir@fyzor.com :: login