<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://dikini.net" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>dikini.net - scheming</title>
 <link>http://dikini.net/taxonomy/term/121/0</link>
 <description></description>
 <language>en</language>
<item>
 <title>An exercise with continuations, prompts and scheme macros</title>
 <link>http://dikini.net/03.08.2007/an_exercise_with_continuations_prompts_and_scheme_macros</link>
 <description>&lt;p&gt;&lt;a href=&quot;http://blog.plt-scheme.org/2007/07/control-resumed.html&quot;&gt;control resumed&lt;/a&gt; inspired me to take a small exercise.
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;&quot;Code a minimal approximation of the python yield operator based generators&quot;&lt;/em&gt;
&lt;br /&gt; Here follow the results I managed to get with help from Matthias Felleisen, via the plt mailing list. You can see the non-edited exchange via the &lt;a href=&quot;http://list.cs.brown.edu/pipermail/plt-scheme/2007-August/019841.html&quot;&gt;mailing list archives&lt;/a&gt; and &lt;a href=&quot;http://blog.plt-scheme.org/2007/08/control-and-macros.html&quot;&gt;control and macors&lt;/a&gt;. All control&amp;prompt are forms specific to &lt;a href=&quot;http://www.plt-scheme.org&quot;&gt;plt scheme&lt;/a&gt;&#039;s &lt;em&gt;control.ss&lt;/em&gt; module. The first attempt looks something like this:
&lt;/p&gt;
&lt;code class=&quot;scheme&quot;&gt;(&lt;span class=&quot;keyword&quot;&gt;require&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;lib&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;&quot;control.ss&quot;&lt;/span&gt;))

(&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;make-step&lt;/span&gt;)
  (&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;control-state&lt;/span&gt;)
    (&lt;span class=&quot;variable&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;1&lt;/span&gt;)
    (&lt;span class=&quot;variable&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;2&lt;/span&gt;)
    (&lt;span class=&quot;variable&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;3&lt;/span&gt;)
    &lt;span class=&quot;keyword&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;variable&quot;&gt;finished&lt;/span&gt;)
  (&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;variable&quot;&gt;value&lt;/span&gt;) (&lt;span class=&quot;variable&quot;&gt;control&lt;/span&gt; &lt;span class=&quot;variable&quot;&gt;resume-here&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;set!&lt;/span&gt; &lt;span class=&quot;variable&quot;&gt;control-state&lt;/span&gt; &lt;span class=&quot;variable&quot;&gt;resume-here&lt;/span&gt;) &lt;span class=&quot;variable&quot;&gt;value&lt;/span&gt;))
  (&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;generator&lt;/span&gt;) (&lt;span class=&quot;variable&quot;&gt;prompt&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;control-state&lt;/span&gt;)))
  &lt;span class=&quot;variable&quot;&gt;generator&lt;/span&gt;)

(&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; &lt;span class=&quot;variable&quot;&gt;step&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;make-step&lt;/span&gt;))

(&lt;span class=&quot;variable&quot;&gt;step&lt;/span&gt;) (&lt;span class=&quot;variable&quot;&gt;step&lt;/span&gt;) 
&lt;/code&gt;
&lt;p&gt;
It does the job. Kind of. For me the interesting bit is how the interplay of prompt and control achieve maintaining the current state of execution before the return and allowing to continue from that interruption. It can be done with call/cc but it looks a helluva a lot more complicated and is far more unreadable.
&lt;/p&gt;
&lt;p&gt;There is a problem with the code above though. As Matthias notes in his email:
&lt;blockquote&gt;LESSON: never &#039;test&#039; by running things at the top-level prompt. It IS a prompt. -- Matthias&lt;/blockquote&gt;

&lt;p&gt;So comes version 2:&lt;/p&gt;
&lt;code class=&quot;scheme&quot;&gt;(&lt;span class=&quot;keyword&quot;&gt;require&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;lib&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;&quot;control.ss&quot;&lt;/span&gt;))

(&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;make-step&lt;/span&gt;)
  (&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;control-state&lt;/span&gt;)
    (&lt;span class=&quot;variable&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;1&lt;/span&gt;)
    (&lt;span class=&quot;variable&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;2&lt;/span&gt;)
    (&lt;span class=&quot;variable&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;3&lt;/span&gt;)
    &lt;span class=&quot;keyword&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;variable&quot;&gt;finished&lt;/span&gt;)
  (&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;variable&quot;&gt;value&lt;/span&gt;) 
    (&lt;span class=&quot;variable&quot;&gt;control&lt;/span&gt; &lt;span class=&quot;variable&quot;&gt;resume-here&lt;/span&gt; 
             (&lt;span class=&quot;keyword&quot;&gt;set!&lt;/span&gt; &lt;span class=&quot;variable&quot;&gt;control-state&lt;/span&gt; 
                   (&lt;span class=&quot;keyword&quot;&gt;lambda&lt;/span&gt; () (&lt;span class=&quot;variable&quot;&gt;prompt&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;resume-here&lt;/span&gt;)))) 
             &lt;span class=&quot;variable&quot;&gt;value&lt;/span&gt;))
  (&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;generator&lt;/span&gt;) (&lt;span class=&quot;variable&quot;&gt;prompt&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;control-state&lt;/span&gt;)))
  &lt;span class=&quot;variable&quot;&gt;generator&lt;/span&gt;)

(&lt;span class=&quot;keyword&quot;&gt;define&lt;/span&gt; &lt;span class=&quot;variable&quot;&gt;step&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;make-step&lt;/span&gt;))

(&lt;span class=&quot;builtin&quot;&gt;equal?&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;&#039;&lt;/span&gt;(&lt;span class=&quot;selfeval&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;selfeval&quot;&gt;3&lt;/span&gt;) (&lt;span class=&quot;builtin&quot;&gt;list&lt;/span&gt; (&lt;span class=&quot;variable&quot;&gt;step&lt;/span&gt;) (&lt;span class=&quot;variable&quot;&gt;step&lt;/span&gt;) (&lt;span class=&quot;variable&quot;&gt;step&lt;/span&gt;)))
&lt;/code&gt;
&lt;p&gt;&lt;em&gt;control-state&lt;/em&gt; is a variable holding a reference to a function with no arguments, doing what the python function would do. &lt;em&gt;yield&lt;/em&gt; is a variable holding a reference to a function which does the interrupt magic. &lt;em&gt;generator&lt;/em&gt; is a variable holding a reference to a (sugary) function which does the initial step.
&lt;/p&gt;
&lt;p&gt;The logic of the above algorithm is roughly as follows - mark thy state, do what you need to do, when you encounter control stop, remember your state by wrapping it in a function (resume-here), remember where do you what to continue from ( the set! control-state ...). Notice that the value of control-state is replaced. This is possible since the  &lt;em&gt;resume-here&lt;/em&gt; continuation is a function and a first class value.&lt;/p&gt;
&lt;p&gt;So what next. Boilerplate code is tedious to write. And there is a lot of boilerplate code there. And every function, which needs to follow this recipe, will need to duplicate it.
&lt;/p&gt;
&lt;p&gt;So scheme macros to the rescue. It is not a trivial problem. A &#039;generator&#039; function can look something like this:
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/03.08.2007/an_exercise_with_continuations_prompts_and_scheme_macros&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/03.08.2007/an_exercise_with_continuations_prompts_and_scheme_macros#comment</comments>
 <category domain="http://dikini.net/tags/code">code</category>
 <category domain="http://dikini.net/tags/plt">plt</category>
 <category domain="http://dikini.net/tags/programming">programming</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <category domain="http://dikini.net/tags/scheming">scheming</category>
 <pubDate>Fri, 03 Aug 2007 12:21:39 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">267 at http://dikini.net</guid>
</item>
<item>
 <title>Partial evaluation and generics in php</title>
 <link>http://dikini.net/03.07.2006/partial_evaluation_and_generics_in_php</link>
 <description>&lt;p&gt;This is a followup of a few of my previous posts (&lt;a href=&quot;/22.06.2006/lisp_like_programming_in_php&quot; rel=&quot;nofollow&quot;&gt;lisp-like programming&lt;/a&gt;, &lt;a href=&quot;/14.06.2006/aspects_and_honey_in_php&quot; rel=&quot;nofollow&quot;&gt;aspects and honey&lt;/a&gt;, &lt;a href=&quot;/20.01.2006/learning_lessons_from_lisp_or_patterns_and_languages_in_php&quot; rel=&quot;nofollow&quot;&gt;patterns &amp;amp; languages&lt;/a&gt;,  &lt;a href=&quot;/24.01.2006/emulating_closures_in_php&quot; rel=&quot;nofollow&quot;&gt;closures&lt;/a&gt;), which describe some programming idioms typical for lisp-like languages.&lt;/p&gt;
&lt;h3&gt;simple partial evaluation&lt;/h3&gt;
&lt;p&gt;Here I will add some very short examples for how to do partial evaluation in php. The most straight forward approach would be something like:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/03.07.2006/partial_evaluation_and_generics_in_php&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/03.07.2006/partial_evaluation_and_generics_in_php#comment</comments>
 <category domain="http://dikini.net/tags/php">php</category>
 <category domain="http://dikini.net/tags/programming">programming</category>
 <category domain="http://dikini.net/tags/scheming">scheming</category>
 <category domain="http://dikini.net/tags/very_shorts">very shorts</category>
 <pubDate>Mon, 03 Jul 2006 09:11:49 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">175 at http://dikini.net</guid>
</item>
<item>
 <title>Random thoughts on web application internals</title>
 <link>http://dikini.net/27.04.2006/random_thoughts_on_web_application_internals</link>
 <description>&lt;p&gt;I&#039;ve been playing lately with a lot of different ideas. Part of it is to further my own education, part of it is looking for good software design tips. Although there exist quite a few good applications or frameworks, both open source and closed, I can&#039;t recommend any as really flexible. By really flexible, I mean easy ways to change its behaviour, how it reacts to the outside world. Most frameworks and applications excell at being themselves, and are rarely excelling at being really good citizens, they are inward looking, as far as their configuration and query is concerned. These are bold statements. They are quite subjective and probably useless. I&#039;ll try to explain what I really mean by &lt;em&gt;positive&lt;/em&gt; examples.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/27.04.2006/random_thoughts_on_web_application_internals&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/27.04.2006/random_thoughts_on_web_application_internals#comment</comments>
 <category domain="http://dikini.net/tags/drupal">drupal</category>
 <category domain="http://dikini.net/tags/php">php</category>
 <category domain="http://dikini.net/tags/programmable_web">programmable web</category>
 <category domain="http://dikini.net/tags/programming">programming</category>
 <category domain="http://dikini.net/tags/scheming">scheming</category>
 <pubDate>Thu, 27 Apr 2006 10:16:25 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">147 at http://dikini.net</guid>
</item>
<item>
 <title>da code scheming</title>
 <link>http://dikini.net/25.04.2006/da_code_scheming</link>
 <description>&lt;p&gt;The semantics of this language I&#039;m thinking of are essentially scheme, with layout as opposed to bracket syntax, or more precisely being able to use either. The parallel blocks initially will be implemented using engines. The syncronicity issues can be implemented in a similar fasion, with a proxy function, to mediate between the function proper and it&#039;s return value.&lt;/p&gt;
</description>
 <comments>http://dikini.net/25.04.2006/da_code_scheming#comment</comments>
 <category domain="http://dikini.net/tags/da_code">da code</category>
 <category domain="http://dikini.net/tags/da_la">da la</category>
 <category domain="http://dikini.net/tags/scheming">scheming</category>
 <pubDate>Tue, 25 Apr 2006 04:57:47 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">145 at http://dikini.net</guid>
</item>
<item>
 <title>da code, types of functions</title>
 <link>http://dikini.net/24.04.2006/da_code_types_of_functions</link>
 <description>&lt;p&gt;I&#039;ve been reviewing, scratching and descratching the idease for the language core, which for the time being I&#039;ll be calling da code.&lt;/p&gt;
&lt;p&gt;Everything revolves around a few fundamental questions about functions. What is a function? What is a function behaviour? What is the effect of one function&#039;s evaluation(behaviour) on the overall ecosystem of a program?&lt;/p&gt;
&lt;h3&gt;Function composition&lt;/h3&gt;
&lt;p&gt;In my head there are two fundamental kinds of function composition - sequential and parallel. It is true that they are redundant, since each of them can be expressed by the other, but in an attempt to provide a relatively brief and expressive language, I will consider both. This should help with intuitive application of different computational schematics.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/24.04.2006/da_code_types_of_functions&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/24.04.2006/da_code_types_of_functions#comment</comments>
 <category domain="http://dikini.net/tags/da_code">da code</category>
 <category domain="http://dikini.net/tags/programming">programming</category>
 <category domain="http://dikini.net/tags/scheming">scheming</category>
 <pubDate>Mon, 24 Apr 2006 08:33:55 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">144 at http://dikini.net</guid>
</item>
</channel>
</rss>
