<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Seschro2</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Seschro2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Seschro2"/>
	<updated>2026-05-17T11:48:42Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1405_irw&amp;diff=84194</id>
		<title>CSC/ECE 517 Spring 2014/oss E1405 irw</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1405_irw&amp;diff=84194"/>
		<updated>2014-03-31T22:58:39Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Improve tests &amp;amp; investigate regex warnings for student_task '''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Background ===&lt;br /&gt;
This model allows for much of the functionality the student requires to interact effectively with expertiza. Here a student is able to sign up for topics, form teams, submit assignments, review other students' work, and check his or her own scores.&lt;br /&gt;
&lt;br /&gt;
== Work accomplished ==&lt;br /&gt;
=== Objective 1: Fix existing tests ===&lt;br /&gt;
Initially, there were 26 tests with errors. Many tests required functionality or fixtures that were likely changed by people working on expertiza over the years.&lt;br /&gt;
==== Issues ====&lt;br /&gt;
Many fixtures required to correct the tests were missing, and had to be added or created. Additionally, several tests were referencing deleted elements of fixture files which were added in order to correct test functionality. Finally, there were certain elements of the code itself in the controller file which had to be corrected in order for tests to run.&lt;br /&gt;
&lt;br /&gt;
=== Objective 2: Add additional tests ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Future work ==&lt;br /&gt;
There is no current unit test file for student_task, which means there aren't unit tests. Such tests should be added in the future in order to ensure proper functionality.&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1405_irw&amp;diff=84193</id>
		<title>CSC/ECE 517 Spring 2014/oss E1405 irw</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1405_irw&amp;diff=84193"/>
		<updated>2014-03-31T22:57:51Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: Created page with &amp;quot;'''Improve tests &amp;amp; investigate regex warnings for student_task '''  == Introduction == === Background === This model allows for much of the functionality the student requires to ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Improve tests &amp;amp; investigate regex warnings for student_task '''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Background ===&lt;br /&gt;
This model allows for much of the functionality the student requires to interact effectively with expertiza. Here a student is able to sign up for topics, form teams, submit assignments, review other students' work, and check his or her own scores.&lt;br /&gt;
&lt;br /&gt;
== Work accomplished ==&lt;br /&gt;
=== Objective 1: Fix existing tests ===&lt;br /&gt;
Initially, there were 26 tests with errors. Many tests required functionality or fixtures that were likely changed by people working on expertiza over the years.&lt;br /&gt;
==== Issues ====&lt;br /&gt;
Many fixtures required to correct the tests were missing, and had to be added or created. Additionally, several tests were referencing deleted elements of fixture files which were added in order to correct test functionality. Finally, there were certain elements of the code itself in the controller file which had to be corrected in order for tests to run.&lt;br /&gt;
&lt;br /&gt;
=== Objective 2: Add additional tests ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Future work ==&lt;br /&gt;
There is no current unit test file for student_task.&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014&amp;diff=84189</id>
		<title>CSC/ECE 517 Spring 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014&amp;diff=84189"/>
		<updated>2014-03-31T22:04:56Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2012/example_page]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1a 1e rm]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1h jg ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1b np]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1f mj]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1a 1d mm]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1a 1c yj]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1l m]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1m bm]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1a 1p fy]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss E1401 lmn]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss E1402 mmb]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss E1404 mnp]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss E1405 irw]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss E1406 st]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss S1402 jyy]]&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83595</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1l m</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83595"/>
		<updated>2014-02-24T03:17:37Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: /* Blocks in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Design Patterns Involving Closures =&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
=== Explanation of Closures ===&lt;br /&gt;
&lt;br /&gt;
====Blocks in Ruby====&lt;br /&gt;
A block is a segment of code that can be used as an argument for a method. These segments of code may have their own initialized variables only able to be referenced locally in the block, much like in a method. Single line blocks are commonly encapsulated in curly braces after a method call, and multi-line blocks are between &amp;quot;do&amp;quot; and &amp;quot;end&amp;quot; statements. A block's code is not executed when it is encountered, but rather after all instances of the yield statement within the method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 =begin  &lt;br /&gt;
  Ruby Code blocks are chunks of code between braces or  &lt;br /&gt;
  between do- end that you can associate with method invocations  &lt;br /&gt;
 =end  &lt;br /&gt;
 def call_block  &lt;br /&gt;
  puts 'Start of method'  &lt;br /&gt;
  # you can call the block using the yield keyword  &lt;br /&gt;
  yield  &lt;br /&gt;
  yield  &lt;br /&gt;
  puts 'End of method'  &lt;br /&gt;
 end  &lt;br /&gt;
 # Code blocks may appear only in the source adjacent to a method call  &lt;br /&gt;
 call_block {puts 'In the block'}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
The above code outputs the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
    &amp;gt;ruby p022codeblock.rb  &lt;br /&gt;
    Start of method  &lt;br /&gt;
    In the block  &lt;br /&gt;
    In the block  &lt;br /&gt;
    End of method  &lt;br /&gt;
    &amp;gt;Exit code: 0  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====So what's a closure?====&lt;br /&gt;
Very simply, a closure is a function that can use a variable that was valid within the scope that the closure was defined, but need not be in-scope where the closure is called. A quick example is very illustrative.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def closure_builder(message=&amp;quot;Default&amp;quot;):&lt;br /&gt;
     def closure():&lt;br /&gt;
         # Message is in-scope here&lt;br /&gt;
         print message&lt;br /&gt;
     return closure&lt;br /&gt;
 &lt;br /&gt;
 # Build two functions&lt;br /&gt;
 default_closure = closure_builder()&lt;br /&gt;
 custom_closure = closure_builder(&amp;quot;Custom&amp;quot;)&lt;br /&gt;
 del closure_builder&lt;br /&gt;
 &lt;br /&gt;
 # Call the closures you built&lt;br /&gt;
 default_closure()  # Amazingly, prints &amp;quot;Default&amp;quot;&lt;br /&gt;
 custom_closure()  # Amazingly, prints &amp;quot;Custom&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Decorators ===&lt;br /&gt;
&lt;br /&gt;
Decorators are an interesting and powerful language feature that can be implemented elegantly with closures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 #!/usr/bin/env python&lt;br /&gt;
 &lt;br /&gt;
 def decorate(func):&lt;br /&gt;
     def decorated_func():&lt;br /&gt;
         print &amp;quot;About to call func&amp;quot;&lt;br /&gt;
         func()&lt;br /&gt;
         print &amp;quot;Back from calling func&amp;quot;&lt;br /&gt;
     return decorated_func&lt;br /&gt;
 &lt;br /&gt;
 @decorate&lt;br /&gt;
 def func_to_decorate():&lt;br /&gt;
     print &amp;quot;In func_to_decorate&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 func_to_decorate()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 [~517/wiki]$ chmod ug+x decorator.py&lt;br /&gt;
 [~517/wiki]$ ./decorator.py&lt;br /&gt;
 About to call func&lt;br /&gt;
 In func_to_decorate&lt;br /&gt;
 Back from calling func&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Command Pattern===&lt;br /&gt;
The command Pattern can be implemented using proc objects, which are the closure of an object&lt;br /&gt;
&lt;br /&gt;
In the command pattern, commands for objects to be implemented are queued and can be executed at any time. Arguments are considered passed when the method is called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 count = 0&lt;br /&gt;
 &lt;br /&gt;
 commands = []&lt;br /&gt;
 (1..10).each do |i|&lt;br /&gt;
   commands &amp;lt;&amp;lt; proc { count +=i }&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 puts &amp;quot;Count is initially #{count}&amp;quot;&lt;br /&gt;
 commands.each { |cmd| cmd.call }&lt;br /&gt;
 puts &amp;quot;Performed all commands. count is #{count}&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
The Strategy Pattern allows an algorithms behavior to be determined at runtime. It describes the definition of a family of interchangeable algorithm classes whose functionality is different for identically named methods. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Fighter&lt;br /&gt;
  def initialize(&amp;amp;fighting_behavior)&lt;br /&gt;
    @finish_move = fighting_behavior&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def finish_opponent&lt;br /&gt;
    @finish_move.call&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 boxer = Fighter.new { puts 'Left hook to the body!' }&lt;br /&gt;
 boxer.finish_opponent #=&amp;gt; Left hook to the body!&lt;br /&gt;
  &lt;br /&gt;
 mortal_kombat_warrior = Fighter.new { puts 'Blast him with a lighting bolt' }&lt;br /&gt;
 mortal_kombat_warrior.finish_opponent #=&amp;gt; Blast him with a lighting bolt&lt;br /&gt;
  &lt;br /&gt;
 mma = Fighter.new { puts 'Put you to sleep, Good Night!' }&lt;br /&gt;
 mma.finish_opponent #=&amp;gt; Put you to sleep, Good Night!&lt;br /&gt;
  &lt;br /&gt;
 lion = Fighter.new { puts 'Bites your head off' }&lt;br /&gt;
 lion.finish_opponent #=&amp;gt; Bites your head off!&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83592</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1l m</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83592"/>
		<updated>2014-02-24T03:16:32Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: /* Explanation of Closures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Design Patterns Involving Closures =&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
=== Explanation of Closures ===&lt;br /&gt;
&lt;br /&gt;
====Blocks in Ruby====&lt;br /&gt;
A block is a segment of code that can be used as an argument for a method. These segments of code may have their own initialized variables only able to be referenced locally in the block, much like in a method. Blocks are commonly between &amp;quot;do&amp;quot; and &amp;quot;end&amp;quot; statements. A block's code is not executed when it is encountered, but rather after all instances of the yield statement within the method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 =begin  &lt;br /&gt;
  Ruby Code blocks are chunks of code between braces or  &lt;br /&gt;
  between do- end that you can associate with method invocations  &lt;br /&gt;
 =end  &lt;br /&gt;
 def call_block  &lt;br /&gt;
  puts 'Start of method'  &lt;br /&gt;
  # you can call the block using the yield keyword  &lt;br /&gt;
  yield  &lt;br /&gt;
  yield  &lt;br /&gt;
  puts 'End of method'  &lt;br /&gt;
 end  &lt;br /&gt;
 # Code blocks may appear only in the source adjacent to a method call  &lt;br /&gt;
 call_block {puts 'In the block'}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
The above code outputs the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
    &amp;gt;ruby p022codeblock.rb  &lt;br /&gt;
    Start of method  &lt;br /&gt;
    In the block  &lt;br /&gt;
    In the block  &lt;br /&gt;
    End of method  &lt;br /&gt;
    &amp;gt;Exit code: 0  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====So what's a closure?====&lt;br /&gt;
Very simply, a closure is a function that can use a variable that was valid within the scope that the closure was defined, but need not be in-scope where the closure is called. A quick example is very illustrative.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def closure_builder(message=&amp;quot;Default&amp;quot;):&lt;br /&gt;
     def closure():&lt;br /&gt;
         # Message is in-scope here&lt;br /&gt;
         print message&lt;br /&gt;
     return closure&lt;br /&gt;
 &lt;br /&gt;
 # Build two functions&lt;br /&gt;
 default_closure = closure_builder()&lt;br /&gt;
 custom_closure = closure_builder(&amp;quot;Custom&amp;quot;)&lt;br /&gt;
 del closure_builder&lt;br /&gt;
 &lt;br /&gt;
 # Call the closures you built&lt;br /&gt;
 default_closure()  # Amazingly, prints &amp;quot;Default&amp;quot;&lt;br /&gt;
 custom_closure()  # Amazingly, prints &amp;quot;Custom&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Decorators ===&lt;br /&gt;
&lt;br /&gt;
Decorators are an interesting and powerful language feature that can be implemented elegantly with closures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 #!/usr/bin/env python&lt;br /&gt;
 &lt;br /&gt;
 def decorate(func):&lt;br /&gt;
     def decorated_func():&lt;br /&gt;
         print &amp;quot;About to call func&amp;quot;&lt;br /&gt;
         func()&lt;br /&gt;
         print &amp;quot;Back from calling func&amp;quot;&lt;br /&gt;
     return decorated_func&lt;br /&gt;
 &lt;br /&gt;
 @decorate&lt;br /&gt;
 def func_to_decorate():&lt;br /&gt;
     print &amp;quot;In func_to_decorate&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 func_to_decorate()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 [~517/wiki]$ chmod ug+x decorator.py&lt;br /&gt;
 [~517/wiki]$ ./decorator.py&lt;br /&gt;
 About to call func&lt;br /&gt;
 In func_to_decorate&lt;br /&gt;
 Back from calling func&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Command Pattern===&lt;br /&gt;
The command Pattern can be implemented using proc objects, which are the closure of an object&lt;br /&gt;
&lt;br /&gt;
In the command pattern, commands for objects to be implemented are queued and can be executed at any time. Arguments are considered passed when the method is called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 count = 0&lt;br /&gt;
 &lt;br /&gt;
 commands = []&lt;br /&gt;
 (1..10).each do |i|&lt;br /&gt;
   commands &amp;lt;&amp;lt; proc { count +=i }&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 puts &amp;quot;Count is initially #{count}&amp;quot;&lt;br /&gt;
 commands.each { |cmd| cmd.call }&lt;br /&gt;
 puts &amp;quot;Performed all commands. count is #{count}&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
The Strategy Pattern allows an algorithms behavior to be determined at runtime. It describes the definition of a family of interchangeable algorithm classes whose functionality is different for identically named methods. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Fighter&lt;br /&gt;
  def initialize(&amp;amp;fighting_behavior)&lt;br /&gt;
    @finish_move = fighting_behavior&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def finish_opponent&lt;br /&gt;
    @finish_move.call&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 boxer = Fighter.new { puts 'Left hook to the body!' }&lt;br /&gt;
 boxer.finish_opponent #=&amp;gt; Left hook to the body!&lt;br /&gt;
  &lt;br /&gt;
 mortal_kombat_warrior = Fighter.new { puts 'Blast him with a lighting bolt' }&lt;br /&gt;
 mortal_kombat_warrior.finish_opponent #=&amp;gt; Blast him with a lighting bolt&lt;br /&gt;
  &lt;br /&gt;
 mma = Fighter.new { puts 'Put you to sleep, Good Night!' }&lt;br /&gt;
 mma.finish_opponent #=&amp;gt; Put you to sleep, Good Night!&lt;br /&gt;
  &lt;br /&gt;
 lion = Fighter.new { puts 'Bites your head off' }&lt;br /&gt;
 lion.finish_opponent #=&amp;gt; Bites your head off!&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83591</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1l m</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83591"/>
		<updated>2014-02-24T02:44:18Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Design Patterns Involving Closures =&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
=== Explanation of Closures ===&lt;br /&gt;
&lt;br /&gt;
Very simply, a closure is a function that can use a variable that was valid within the scope that the closure was defined, but need not be in-scope where the closure is called. A quick example is very illustrative.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def closure_builder(message=&amp;quot;Default&amp;quot;):&lt;br /&gt;
     def closure():&lt;br /&gt;
         # Message is in-scope here&lt;br /&gt;
         print message&lt;br /&gt;
     return closure&lt;br /&gt;
 &lt;br /&gt;
 # Build two functions&lt;br /&gt;
 default_closure = closure_builder()&lt;br /&gt;
 custom_closure = closure_builder(&amp;quot;Custom&amp;quot;)&lt;br /&gt;
 del closure_builder&lt;br /&gt;
 &lt;br /&gt;
 # Call the closures you built&lt;br /&gt;
 default_closure()  # Amazingly, prints &amp;quot;Default&amp;quot;&lt;br /&gt;
 custom_closure()  # Amazingly, prints &amp;quot;Custom&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Decorators ===&lt;br /&gt;
&lt;br /&gt;
Decorators are an interesting and powerful language feature that can be implemented elegantly with closures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 #!/usr/bin/env python&lt;br /&gt;
 &lt;br /&gt;
 def decorate(func):&lt;br /&gt;
     def decorated_func():&lt;br /&gt;
         print &amp;quot;About to call func&amp;quot;&lt;br /&gt;
         func()&lt;br /&gt;
         print &amp;quot;Back from calling func&amp;quot;&lt;br /&gt;
     return decorated_func&lt;br /&gt;
 &lt;br /&gt;
 @decorate&lt;br /&gt;
 def func_to_decorate():&lt;br /&gt;
     print &amp;quot;In func_to_decorate&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 func_to_decorate()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 [~517/wiki]$ chmod ug+x decorator.py&lt;br /&gt;
 [~517/wiki]$ ./decorator.py&lt;br /&gt;
 About to call func&lt;br /&gt;
 In func_to_decorate&lt;br /&gt;
 Back from calling func&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Command Pattern===&lt;br /&gt;
The command Pattern can be implemented using proc objects, which are the closure of an object&lt;br /&gt;
&lt;br /&gt;
In the command pattern, commands for objects to be implemented are queued and can be executed at any time. Arguments are considered passed when the method is called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 count = 0&lt;br /&gt;
 &lt;br /&gt;
 commands = []&lt;br /&gt;
 (1..10).each do |i|&lt;br /&gt;
   commands &amp;lt;&amp;lt; proc { count +=i }&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 puts &amp;quot;Count is initially #{count}&amp;quot;&lt;br /&gt;
 commands.each { |cmd| cmd.call }&lt;br /&gt;
 puts &amp;quot;Performed all commands. count is #{count}&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
The Strategy Pattern allows an algorithms behavior to be determined at runtime. It describes the definition of a family of interchangeable algorithm classes whose functionality is different for identically named methods. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Fighter&lt;br /&gt;
  def initialize(&amp;amp;fighting_behavior)&lt;br /&gt;
    @finish_move = fighting_behavior&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def finish_opponent&lt;br /&gt;
    @finish_move.call&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 boxer = Fighter.new { puts 'Left hook to the body!' }&lt;br /&gt;
 boxer.finish_opponent #=&amp;gt; Left hook to the body!&lt;br /&gt;
  &lt;br /&gt;
 mortal_kombat_warrior = Fighter.new { puts 'Blast him with a lighting bolt' }&lt;br /&gt;
 mortal_kombat_warrior.finish_opponent #=&amp;gt; Blast him with a lighting bolt&lt;br /&gt;
  &lt;br /&gt;
 mma = Fighter.new { puts 'Put you to sleep, Good Night!' }&lt;br /&gt;
 mma.finish_opponent #=&amp;gt; Put you to sleep, Good Night!&lt;br /&gt;
  &lt;br /&gt;
 lion = Fighter.new { puts 'Bites your head off' }&lt;br /&gt;
 lion.finish_opponent #=&amp;gt; Bites your head off!&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83590</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1l m</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83590"/>
		<updated>2014-02-24T02:10:42Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Design Patterns Involving Closures =&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
=== Explanation of Closures ===&lt;br /&gt;
&lt;br /&gt;
Very simply, a closure is a function that can use a variable that was valid within the scope that the closure was defined, but need not be in-scope where the closure is called. A quick example is very illustrative.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def closure_builder(message=&amp;quot;Default&amp;quot;):&lt;br /&gt;
     def closure():&lt;br /&gt;
         # Message is in-scope here&lt;br /&gt;
         print message&lt;br /&gt;
     return closure&lt;br /&gt;
 &lt;br /&gt;
 # Build two functions&lt;br /&gt;
 default_closure = closure_builder()&lt;br /&gt;
 custom_closure = closure_builder(&amp;quot;Custom&amp;quot;)&lt;br /&gt;
 del closure_builder&lt;br /&gt;
 &lt;br /&gt;
 # Call the closures you built&lt;br /&gt;
 default_closure()  # Amazingly, prints &amp;quot;Default&amp;quot;&lt;br /&gt;
 custom_closure()  # Amazingly, prints &amp;quot;Custom&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Decorators ===&lt;br /&gt;
&lt;br /&gt;
Decorators are an interesting and powerful language feature that can be implemented elegantly with closures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 #!/usr/bin/env python&lt;br /&gt;
 &lt;br /&gt;
 def decorate(func):&lt;br /&gt;
     def decorated_func():&lt;br /&gt;
         print &amp;quot;About to call func&amp;quot;&lt;br /&gt;
         func()&lt;br /&gt;
         print &amp;quot;Back from calling func&amp;quot;&lt;br /&gt;
     return decorated_func&lt;br /&gt;
 &lt;br /&gt;
 @decorate&lt;br /&gt;
 def func_to_decorate():&lt;br /&gt;
     print &amp;quot;In func_to_decorate&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 func_to_decorate()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 [~517/wiki]$ chmod ug+x decorator.py&lt;br /&gt;
 [~517/wiki]$ ./decorator.py&lt;br /&gt;
 About to call func&lt;br /&gt;
 In func_to_decorate&lt;br /&gt;
 Back from calling func&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Command Pattern===&lt;br /&gt;
The command Pattern can be implemented using proc objects, which are the closure of an object&lt;br /&gt;
&lt;br /&gt;
In the command pattern, commands for objects to be implemented are queued and can be executed at any time. Arguments are considered passed when the method is called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 count = 0&lt;br /&gt;
 &lt;br /&gt;
 commands = []&lt;br /&gt;
 (1..10).each do |i|&lt;br /&gt;
   commands &amp;lt;&amp;lt; proc { count +=i }&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 puts &amp;quot;Count is initially #{count}&amp;quot;&lt;br /&gt;
 commands.each { |cmd| cmd.call }&lt;br /&gt;
 puts &amp;quot;Performed all commands. count is #{count}&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 class Report&lt;br /&gt;
  attr_reader :title, :text&lt;br /&gt;
  attr_accessor :formatter&lt;br /&gt;
  def initialize(&amp;amp;formatter)&lt;br /&gt;
   @title = 'Monthly Report'&lt;br /&gt;
   @text = [ 'Things are going', 'really, really well.' ]&lt;br /&gt;
   @formatter = formatter&lt;br /&gt;
  end&lt;br /&gt;
  def output_report&lt;br /&gt;
   @formatter.call( self )&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 HTML_FORMATTER = lambda do |context|&lt;br /&gt;
  puts('&amp;lt;html&amp;gt;')&lt;br /&gt;
  puts(' &amp;lt;head&amp;gt;')&lt;br /&gt;
  puts(&amp;quot; &amp;lt;title&amp;gt;#{context.title}&amp;lt;/title&amp;gt;&amp;quot;)&lt;br /&gt;
  puts(' &amp;lt;/head&amp;gt;')&lt;br /&gt;
  puts(' &amp;lt;body&amp;gt;')&lt;br /&gt;
  context.text.each do |line|&lt;br /&gt;
   puts(&amp;quot; &amp;lt;p&amp;gt;#{line}&amp;lt;/p&amp;gt;&amp;quot; )&lt;br /&gt;
  end&lt;br /&gt;
  puts(' &amp;lt;/body&amp;gt;')&lt;br /&gt;
  puts(' &amp;lt;/html&amp;gt;')&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83589</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1l m</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83589"/>
		<updated>2014-02-24T02:08:57Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Design Patterns Involving Closures =&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
=== Explanation of Closures ===&lt;br /&gt;
&lt;br /&gt;
Very simply, a closure is a function that can use a variable that was valid within the scope that the closure was defined, but need not be in-scope where the closure is called. A quick example is very illustrative.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def closure_builder(message=&amp;quot;Default&amp;quot;):&lt;br /&gt;
     def closure():&lt;br /&gt;
         # Message is in-scope here&lt;br /&gt;
         print message&lt;br /&gt;
     return closure&lt;br /&gt;
 &lt;br /&gt;
 # Build two functions&lt;br /&gt;
 default_closure = closure_builder()&lt;br /&gt;
 custom_closure = closure_builder(&amp;quot;Custom&amp;quot;)&lt;br /&gt;
 del closure_builder&lt;br /&gt;
 &lt;br /&gt;
 # Call the closures you built&lt;br /&gt;
 default_closure()  # Amazingly, prints &amp;quot;Default&amp;quot;&lt;br /&gt;
 custom_closure()  # Amazingly, prints &amp;quot;Custom&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Decorators ===&lt;br /&gt;
&lt;br /&gt;
Decorators are an interesting and powerful language feature that can be implemented elegantly with closures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 #!/usr/bin/env python&lt;br /&gt;
 &lt;br /&gt;
 def decorate(func):&lt;br /&gt;
     def decorated_func():&lt;br /&gt;
         print &amp;quot;About to call func&amp;quot;&lt;br /&gt;
         func()&lt;br /&gt;
         print &amp;quot;Back from calling func&amp;quot;&lt;br /&gt;
     return decorated_func&lt;br /&gt;
 &lt;br /&gt;
 @decorate&lt;br /&gt;
 def func_to_decorate():&lt;br /&gt;
     print &amp;quot;In func_to_decorate&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 func_to_decorate()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 [~517/wiki]$ chmod ug+x decorator.py&lt;br /&gt;
 [~517/wiki]$ ./decorator.py&lt;br /&gt;
 About to call func&lt;br /&gt;
 In func_to_decorate&lt;br /&gt;
 Back from calling func&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Command Pattern===&lt;br /&gt;
The command Pattern can be implemented using proc objects, which are the closure of an object&lt;br /&gt;
&lt;br /&gt;
In the command pattern, commands for objects to be implemented are queued and can be executed at any time. Arguments are considered passed when the method is called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 count = 0&lt;br /&gt;
 &lt;br /&gt;
 commands = []&lt;br /&gt;
 (1..10).each do |i|&lt;br /&gt;
   commands &amp;lt;&amp;lt; proc { count +=i }&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 puts &amp;quot;Count is initially #{count}&amp;quot;&lt;br /&gt;
 commands.each { |cmd| cmd.call }&lt;br /&gt;
 puts &amp;quot;Performed all commands. count is #{count}&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 class Report&lt;br /&gt;
  attr_reader :title, :text&lt;br /&gt;
  attr_accessor :formatter&lt;br /&gt;
  def initialize(&amp;amp;formatter)&lt;br /&gt;
   @title = 'Monthly Report'&lt;br /&gt;
   @text = [ 'Things are going', 'really, really well.' ]&lt;br /&gt;
   @formatter = formatter&lt;br /&gt;
  end&lt;br /&gt;
  def output_report&lt;br /&gt;
   @formatter.call( self )&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 HTML_FORMATTER = lambda do |context|&lt;br /&gt;
  puts('&amp;lt;html&amp;gt;')&lt;br /&gt;
  puts(' &amp;lt;head&amp;gt;')&lt;br /&gt;
  puts(&amp;quot; &amp;lt;title&amp;gt;#{context.title}&amp;lt;/title&amp;gt;&amp;quot;)&lt;br /&gt;
  puts(' &amp;lt;/head&amp;gt;')&lt;br /&gt;
  puts(' &amp;lt;body&amp;gt;')&lt;br /&gt;
  context.text.each do |line|&lt;br /&gt;
   puts(&amp;quot; &amp;lt;p&amp;gt;#{line}&amp;lt;/p&amp;gt;&amp;quot; )&lt;br /&gt;
  end&lt;br /&gt;
  puts(' &amp;lt;/body&amp;gt;')&lt;br /&gt;
  puts(' &amp;lt;/html&amp;gt;')&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83588</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1l m</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83588"/>
		<updated>2014-02-24T01:58:13Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Design Patterns Involving Closures =&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
=== Explanation of Closures ===&lt;br /&gt;
&lt;br /&gt;
Very simply, a closure is a function that can use a variable that was valid within the scope that the closure was defined, but need not be in-scope where the closure is called. A quick example is very illustrative.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def closure_builder(message=&amp;quot;Default&amp;quot;):&lt;br /&gt;
     def closure():&lt;br /&gt;
         # Message is in-scope here&lt;br /&gt;
         print message&lt;br /&gt;
     return closure&lt;br /&gt;
 &lt;br /&gt;
 # Build two functions&lt;br /&gt;
 default_closure = closure_builder()&lt;br /&gt;
 custom_closure = closure_builder(&amp;quot;Custom&amp;quot;)&lt;br /&gt;
 del closure_builder&lt;br /&gt;
 &lt;br /&gt;
 # Call the closures you built&lt;br /&gt;
 default_closure()  # Amazingly, prints &amp;quot;Default&amp;quot;&lt;br /&gt;
 custom_closure()  # Amazingly, prints &amp;quot;Custom&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Decorators ===&lt;br /&gt;
&lt;br /&gt;
Decorators are an interesting and powerful language feature that can be implemented elegantly with closures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 #!/usr/bin/env python&lt;br /&gt;
 &lt;br /&gt;
 def decorate(func):&lt;br /&gt;
     def decorated_func():&lt;br /&gt;
         print &amp;quot;About to call func&amp;quot;&lt;br /&gt;
         func()&lt;br /&gt;
         print &amp;quot;Back from calling func&amp;quot;&lt;br /&gt;
     return decorated_func&lt;br /&gt;
 &lt;br /&gt;
 @decorate&lt;br /&gt;
 def func_to_decorate():&lt;br /&gt;
     print &amp;quot;In func_to_decorate&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 func_to_decorate()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 [~517/wiki]$ chmod ug+x decorator.py&lt;br /&gt;
 [~517/wiki]$ ./decorator.py&lt;br /&gt;
 About to call func&lt;br /&gt;
 In func_to_decorate&lt;br /&gt;
 Back from calling func&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Command Pattern===&lt;br /&gt;
The command Pattern can be implemented using proc objects, which are the closure of an object&lt;br /&gt;
&lt;br /&gt;
In the command pattern, commands for objects to be implemented are queued and can be executed at any time. Arguments are considered passed when the method is called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 count = 0&lt;br /&gt;
 &lt;br /&gt;
 commands = []&lt;br /&gt;
 (1..10).each do |i|&lt;br /&gt;
   commands &amp;lt;&amp;lt; proc { count +=i }&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 puts &amp;quot;Count is initially #{count}&amp;quot;&lt;br /&gt;
 commands.each { |cmd| cmd.call }&lt;br /&gt;
 puts &amp;quot;Performed all commands. count is #{count}&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83587</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1l m</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83587"/>
		<updated>2014-02-24T01:37:49Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Design Patterns Involving Closures =&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
=== Explanation of Closures ===&lt;br /&gt;
&lt;br /&gt;
Very simply, a closure is a function that can use a variable that was valid within the scope that the closure was defined, but need not be in-scope where the closure is called. A quick example is very illustrative.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def closure_builder(message=&amp;quot;Default&amp;quot;):&lt;br /&gt;
     def closure():&lt;br /&gt;
         # Message is in-scope here&lt;br /&gt;
         print message&lt;br /&gt;
     return closure&lt;br /&gt;
 &lt;br /&gt;
 # Build two functions&lt;br /&gt;
 default_closure = closure_builder()&lt;br /&gt;
 custom_closure = closure_builder(&amp;quot;Custom&amp;quot;)&lt;br /&gt;
 del closure_builder&lt;br /&gt;
 &lt;br /&gt;
 # Call the closures you built&lt;br /&gt;
 default_closure()  # Amazingly, prints &amp;quot;Default&amp;quot;&lt;br /&gt;
 custom_closure()  # Amazingly, prints &amp;quot;Custom&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Decorators ===&lt;br /&gt;
&lt;br /&gt;
Decorators are an interesting and powerful language feature that can be implemented elegantly with closures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 #!/usr/bin/env python&lt;br /&gt;
 &lt;br /&gt;
 def decorate(func):&lt;br /&gt;
     def decorated_func():&lt;br /&gt;
         print &amp;quot;About to call func&amp;quot;&lt;br /&gt;
         func()&lt;br /&gt;
         print &amp;quot;Back from calling func&amp;quot;&lt;br /&gt;
     return decorated_func&lt;br /&gt;
 &lt;br /&gt;
 @decorate&lt;br /&gt;
 def func_to_decorate():&lt;br /&gt;
     print &amp;quot;In func_to_decorate&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 func_to_decorate()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 [~517/wiki]$ chmod ug+x decorator.py&lt;br /&gt;
 [~517/wiki]$ ./decorator.py&lt;br /&gt;
 About to call func&lt;br /&gt;
 In func_to_decorate&lt;br /&gt;
 Back from calling func&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Command Pattern===&lt;br /&gt;
The command Pattern can be implemented using proc objects, which are the closure of an object&lt;br /&gt;
&lt;br /&gt;
In the command pattern, commands for objects to be implemented are queued and can be executed at any time. Arguments are considered passed when the method is called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
count = 0&lt;br /&gt;
&lt;br /&gt;
commands = []&lt;br /&gt;
(1..10).each do |i|&lt;br /&gt;
   commands &amp;lt;&amp;lt; proc { count +=i }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
puts &amp;quot;Count is initially #{count}&amp;quot;&lt;br /&gt;
commands.each { |cmd| cmd.call }&lt;br /&gt;
puts &amp;quot;Performed all commands. count is #{count}&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83585</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1l m</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1l_m&amp;diff=83585"/>
		<updated>2014-02-23T18:33:42Z</updated>

		<summary type="html">&lt;p&gt;Seschro2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Design Patterns Involving Closures =&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
=== Explanation of Closures ===&lt;br /&gt;
&lt;br /&gt;
Very simply, a closure is a function that can use a variable that was valid within the scope that the closure was defined, but need not be in-scope where the closure is called. A quick example is very illustrative.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def closure_builder(message=&amp;quot;Default&amp;quot;):&lt;br /&gt;
     def closure():&lt;br /&gt;
         # Message is in-scope here&lt;br /&gt;
         print message&lt;br /&gt;
     return closure&lt;br /&gt;
 &lt;br /&gt;
 # Build two functions&lt;br /&gt;
 default_closure = closure_builder()&lt;br /&gt;
 custom_closure = closure_builder(&amp;quot;Custom&amp;quot;)&lt;br /&gt;
 del closure_builder&lt;br /&gt;
 &lt;br /&gt;
 # Call the closures you built&lt;br /&gt;
 default_closure()  # Amazingly, prints &amp;quot;Default&amp;quot;&lt;br /&gt;
 custom_closure()  # Amazingly, prints &amp;quot;Custom&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Decorators ===&lt;br /&gt;
&lt;br /&gt;
Decorators are an interesting and powerful language feature that can be implemented elegantly with closures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 #!/usr/bin/env python&lt;br /&gt;
 &lt;br /&gt;
 def decorate(func):&lt;br /&gt;
     def decorated_func():&lt;br /&gt;
         print &amp;quot;About to call func&amp;quot;&lt;br /&gt;
         func()&lt;br /&gt;
         print &amp;quot;Back from calling func&amp;quot;&lt;br /&gt;
     return decorated_func&lt;br /&gt;
 &lt;br /&gt;
 @decorate&lt;br /&gt;
 def func_to_decorate():&lt;br /&gt;
     print &amp;quot;In func_to_decorate&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 func_to_decorate()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 [~517/wiki]$ chmod ug+x decorator.py&lt;br /&gt;
 [~517/wiki]$ ./decorator.py&lt;br /&gt;
 About to call func&lt;br /&gt;
 In func_to_decorate&lt;br /&gt;
 Back from calling func&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Command Pattern===&lt;br /&gt;
The command Pattern can be implemented using proc objects, which are the closure of an object&lt;br /&gt;
&lt;br /&gt;
In the command pattern, commands for objects to be implemented are queued and can be executed at any time. Arguments are considered passed when the method is called.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Seschro2</name></author>
	</entry>
</feed>