<?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 - scheme</title>
 <link>http://dikini.net/taxonomy/term/107/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>LISP cycles</title>
 <link>http://dikini.net/02.08.2007/lisp_cycles</link>
 <description>&lt;p&gt;&lt;a href=&quot;http://xkcd.com/297/&quot; rel=&quot;nofollow&quot;&gt;&lt;img src=&quot;http://imgs.xkcd.com/comics/lisp_cycles.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
from &lt;a href=&quot;http://xkcd.com/&quot; rel=&quot;nofollow&quot;&gt;xkcd&lt;/a&gt;&lt;/p&gt;
</description>
 <comments>http://dikini.net/02.08.2007/lisp_cycles#comment</comments>
 <category domain="http://dikini.net/tags/comics">comics</category>
 <category domain="http://dikini.net/tags/lisp">lisp</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <pubDate>Thu, 02 Aug 2007 05:22:14 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">265 at http://dikini.net</guid>
</item>
<item>
 <title>macro processor - initial notes</title>
 <link>http://dikini.net/30.08.2006/macro_processor_initial_notes</link>
 <description>&lt;p&gt;Most of my work on this is on paper, and some code sketeches. There quite a few non-trivial issues, and hard decisions to be made. Since I have the knack of loosing or recycling the various paper bits lying around, I decided to keep at least some of them in my diary, aka this blog.&lt;/p&gt;
&lt;h3&gt;initial requirements&lt;/h3&gt;
&lt;dl&gt;
&lt;dt&gt;convenient syntax and semantics&lt;/dt&gt;
&lt;dd&gt;convenience matters. The syntax should be obvious. The meaning of the syntax should be easy to grasp.&lt;/dd&gt;
&lt;dt&gt;minimal core&lt;/dt&gt;
&lt;dd&gt;the core of the macro processor should be minimal. This will help managing the code quality. The minimal core should be enriched using macros.&lt;/dd&gt;
&lt;dt&gt;retargetable/multi-targets&lt;/dt&gt;
&lt;dd&gt;using one and the same &#039;surface syntax&#039; to produce different target code. It should be possible to have a one to many code generation. Example application - one definition producing javascript, php and sql code. Alternative example: one definition - three code targets - debug, deployment + a set of autogenerated tests&lt;/dd&gt;
&lt;dt&gt;target and syntax agnostic&lt;/dt&gt;
&lt;dd&gt;no assumptions should be made (at least at top level) about the target or syntax. We should be able to accomodate any theoretically parsable syntax, within reason, of course. Subject to parsing strategy selection, etc...&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/30.08.2006/macro_processor_initial_notes&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/30.08.2006/macro_processor_initial_notes#comment</comments>
 <category domain="http://dikini.net/tags/dylan">dylan</category>
 <category domain="http://dikini.net/tags/lisp">lisp</category>
 <category domain="http://dikini.net/tags/macros">macros</category>
 <category domain="http://dikini.net/tags/php">php</category>
 <category domain="http://dikini.net/tags/programming">programming</category>
 <category domain="http://dikini.net/tags/projects">projects</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <category domain="http://dikini.net/tags/work_in_progress">work in progress</category>
 <pubDate>Wed, 30 Aug 2006 05:46:40 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">217 at http://dikini.net</guid>
</item>
<item>
 <title>macros, higher-order functions, datatypes and design patterns</title>
 <link>http://dikini.net/29.08.2006/macros_higher_order_functions_datatypes_and_design_patterns</link>
 <description>&lt;p&gt;While reading, researching and experimenting for my macros project the terms in the title get mixed a lot. I&#039;ll try to summarise what is my understanding of a lot of the above. To be fair, most of these words are heavily overloaded with sometimes contradictory and or ovelapping meanings, so this short is only about my personal summary, no pretence for a general study or lit review.&lt;/p&gt;
&lt;p&gt;Generic programming intuitevely corresponds to design patterns, or a tool to implement them. There should be a distinction between the functional or algorithmic side of the term and the structural or data (type) genericity.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/29.08.2006/macros_higher_order_functions_datatypes_and_design_patterns&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/29.08.2006/macros_higher_order_functions_datatypes_and_design_patterns#comment</comments>
 <category domain="http://dikini.net/tags/design_patterns">design patterns</category>
 <category domain="http://dikini.net/tags/dylan">dylan</category>
 <category domain="http://dikini.net/tags/haskell">haskell</category>
 <category domain="http://dikini.net/tags/macros">macros</category>
 <category domain="http://dikini.net/tags/php">php</category>
 <category domain="http://dikini.net/tags/programming">programming</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <pubDate>Tue, 29 Aug 2006 10:09:21 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">215 at http://dikini.net</guid>
</item>
<item>
 <title>Poor man&#039;s macro programming in php</title>
 <link>http://dikini.net/26.07.2006/poor_mans_macro_programming_in_php</link>
 <description>Jonnay&#039;s post I &lt;a href=&quot;http://dikini.net/26.07.2006/googles_summer_of_yawn&quot;&gt;mentioned before&lt;/a&gt; started me thinking - what do you need to have macros in php. What is the closest we can get to that without actually changing anything in php (poor man&#039;s version? What minimal sugar does php need to make it comfy? What is the natural syntax for macros in php?

I definitely don&#039;t know the answers to these questions but let&#039;s try:

&lt;code&gt;
  macro delay() {
     match { delay( $func, ... ) } : 
       { $varname = $func . random();
         $$varname = array(new promise( $func, ... ), &#039;evaluate&#039;); 
         return $varname;
       }
     match { $func( ... ) } :
       { return call_user_func($$varname, ... }; }
  }
&lt;/code&gt;
&lt;p&gt;This looks kind of allright, phpish. It has problems, but the above dream code demonstrates the idea enough - match the left-hand-side code and substitute it with the right hand side. The difference from C macros is that this macro is a program fragment/function/..., the result of which is substituted in the AST, as opposed to simple string pattern matching + substitution&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://dikini.net/26.07.2006/poor_mans_macro_programming_in_php&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/26.07.2006/poor_mans_macro_programming_in_php#comment</comments>
 <category domain="http://dikini.net/tags/macros">macros</category>
 <category domain="http://dikini.net/tags/php">php</category>
 <category domain="http://dikini.net/tags/programming">programming</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <pubDate>Wed, 26 Jul 2006 11:43:44 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">203 at http://dikini.net</guid>
</item>
<item>
 <title>Googles Summer of yawn.</title>
 <link>http://dikini.net/26.07.2006/googles_summer_of_yawn</link>
 <description>&lt;blockquote&gt;&lt;p&gt;&lt;a href=&quot;http://blog.jonnay.net/archives/739-Googles-Summer-of-yawn..html&quot; rel=&quot;nofollow&quot;&gt;Googles Summer of yawn.&lt;/a&gt; - &lt;em&gt;Google&#039;s &amp;quot;Summer of Code&amp;quot; has started and they have announced a few PHP projects. Some of them look interesting and useful.  However, I am going to pick apart one in particular, that to be honest, looks neither interesting or useful: &lt;a href=&quot;http://code.google.com/soc/php/appinfo.html?csaid=3752FBA8CFFCD528&quot; rel=&quot;nofollow&quot;&gt;The PHP Macro Preprocessor&lt;/a&gt;.&lt;br /&gt;
....&lt;br /&gt;
&lt;br /&gt;
Why does the PHP Preprocessor need to be stuck in a world of #ifdefs and #includes?  Instead of blindly copying what the C preprocessor does, why not focus on the languages strengths and deficiencies?  The object system of PHP needs to be looked at, and see if it can be improved upon through a method of code transformation.&lt;br /&gt;
&lt;br /&gt;&lt;/em&gt; [&lt;a href=&quot;http://blog.jonnay.net/&quot; rel=&quot;nofollow&quot;&gt;sacrificial rabbit&lt;/a&gt;]
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I sooo totally agree with Jonnay on this. In fact it is simply like reading my own thoughts, just put it better english, , ok, nearly. But what to do about it? I don&#039;t really know, I&#039;m afraid I chicken out from digging into the guts of php. When I last looked there it was really scary.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/26.07.2006/googles_summer_of_yawn&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/26.07.2006/googles_summer_of_yawn#comment</comments>
 <category domain="http://dikini.net/tags/design_patterns">design patterns</category>
 <category domain="http://dikini.net/tags/php">php</category>
 <category domain="http://dikini.net/tags/rants">rants</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <pubDate>Wed, 26 Jul 2006 09:07:08 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">202 at http://dikini.net</guid>
</item>
<item>
 <title>LISP-like programming in php</title>
 <link>http://dikini.net/22.06.2006/lisp_like_programming_in_php</link>
 <description>&lt;p&gt;My obsession with things schemish and lispish and having to use php on a daily basis leads to the usual comparison and how would I do this in ... style questions. So here comes another go at how would I program lisp style in php. How much is possible? What is possible? Mind you not everything is really useful or the best way to do it. It is just an intellectual excersise, a study on using some of the php&#039;f features to program in not a typical php (imperative) style.&lt;/p&gt;

&lt;h3&gt;the compulsory conses, car, cdr in php&lt;/h3&gt;

&lt;p&gt;Well for the benefit of non-lispers I will use head and tail instead of car and cdr respectively.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://dikini.net/22.06.2006/lisp_like_programming_in_php&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/22.06.2006/lisp_like_programming_in_php#comment</comments>
 <category domain="http://dikini.net/tags/lisp">lisp</category>
 <category domain="http://dikini.net/tags/php">php</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <category domain="http://dikini.net/tags/scribbles">scribbles</category>
 <pubDate>Thu, 22 Jun 2006 09:12:04 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">174 at http://dikini.net</guid>
</item>
<item>
 <title>Lisp  without Parenthesis</title>
 <link>http://dikini.net/04.05.2006/lisp_without_parenthesis</link>
 <description>&lt;blockquote&gt;&lt;p&gt;Well itâ€™s impossible to remove all of the parentheses in Lisp, ..... One alternative to parentheses is being sensitive to white space, in a way that is reminiscent of Python. &lt;a href=&quot;http://pschombe.wordpress.com/2006/04/16/lisp-without-parentheses&quot;&gt;Lisp  without Parenthesis&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;A good post, which goes along the lines of what I&#039;m playing with as well.   He (Peter Schombert) suggests using \ as line continuation mark, which is in line with tradition. I would probably prefer it in the end, as opposed to the beginning of a line, but that&#039;s sugar.&lt;/p&gt;
&lt;p&gt;I wonder, how hard it would be to add such a language extention to mzscheme.&lt;/p&gt;
&lt;p&gt;Me being a noobie, I haven&#039;t had a clue that there is an SRFI, which implements that already.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/04.05.2006/lisp_without_parenthesis&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/04.05.2006/lisp_without_parenthesis#comment</comments>
 <category domain="http://dikini.net/tags/lisp">lisp</category>
 <category domain="http://dikini.net/tags/programming">programming</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <pubDate>Thu, 04 May 2006 08:11:15 -0400</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">156 at http://dikini.net</guid>
</item>
<item>
 <title>a sample testsuite for the (any/type) base types</title>
 <link>http://dikini.net/14.02.2006/a_sample_testsuite_for_the_any_type_base_types</link>
 <description>&lt;p&gt;Here comes a sample test suite (it is too long, so only the beginning features in here) for the any/types, I described earlier. I like the clenliness of the schemeunit library. It features a rich set of assertions, simple but powerful grouping and both text and gui result interfaces. In order to use it you need &lt;a href=&quot;http://www.plt-scheme.org&quot; title=&quot;PLT scheme&quot;&gt;plt scheme&lt;/a&gt;. Then you can grab the unit test suite from planet:
&lt;code&gt;(require (planet &quot;test.ss&quot; (&quot;schematics&quot; &quot;schemeunit.plt&quot; 1 2)))&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;The code here shows testing only the &lt;em&gt;any/text&lt;/em&gt; type and all relevant auxilary functions, using this datatatype. Looking at the code, it could be turned into a macro, so we could generate type tests automatically, rather than writing this long code..&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://dikini.net/14.02.2006/a_sample_testsuite_for_the_any_type_base_types&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/14.02.2006/a_sample_testsuite_for_the_any_type_base_types#comment</comments>
 <category domain="http://dikini.net/tags/code">code</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/work_in_progress">work in progress</category>
 <pubDate>Tue, 14 Feb 2006 08:25:32 -0500</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">128 at http://dikini.net</guid>
</item>
<item>
 <title>scheming anything/anytype - creating base types experiment</title>
 <link>http://dikini.net/14.02.2006/scheming_anything_anytype_creating_base_types_experiment</link>
 <description>&lt;p&gt;This is an experiment to some &#039;atomic&#039; types in scheme. It was tested only in plt scheme.&lt;/p&gt;

&lt;p&gt;The basic idea is that we need some &#039;atomic&#039; types, from wich to construct everything else in a web cms - users, content nodes, etc... The base &lt;em&gt;field&lt;/em&gt; types defined here are - text, stext (short text), date, integer and float.Each field type is a closure, in which some properties, getters, setters and type-checkers are defined.&lt;/p&gt;

&lt;p&gt;To define a new field type use the &lt;em&gt;make/any/type&lt;/em&gt; macro. In the second part of this code snippet you will find a series of type definitions and helper functions. I quite like how this looks in scheme. I&#039;m surprised actually. This ended up as a very cute OO-like code.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://dikini.net/14.02.2006/scheming_anything_anytype_creating_base_types_experiment&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/14.02.2006/scheming_anything_anytype_creating_base_types_experiment#comment</comments>
 <category domain="http://dikini.net/tags/code">code</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <category domain="http://dikini.net/tags/work_in_progress">work in progress</category>
 <pubDate>Tue, 14 Feb 2006 07:18:16 -0500</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">127 at http://dikini.net</guid>
</item>
<item>
 <title>still scheming away</title>
 <link>http://dikini.net/03.02.2006/still_scheming_away</link>
 <description>&lt;p&gt;In &lt;a href=&quot;/freelinking/scheming_away&quot;&gt;scheming_away&lt;/a&gt; I started exploring &lt;em&gt;things&lt;/em&gt; and stopped somewhere in the middle. Strated with defining things as structures, then as a tree structure. Now comes a third attempt at the same height. Thank god I&#039;m not competing.&lt;/p&gt;
&lt;h3&gt;Take 3, or coming back to structures&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
;a tuple is a structure with an id and a value
(define-struct tuple (id value))

;tuple + -&amp;gt; list of tuples
(define make-thing (lambda( head . rest)
  (map (lambda(x)
          (make-tuple 
            (car x) 
            (cdr x))) 
          (cons head rest))))

;just print the bleeding thing&lt;p&gt;&lt;a href=&quot;http://dikini.net/03.02.2006/still_scheming_away&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/03.02.2006/still_scheming_away#comment</comments>
 <category domain="http://dikini.net/tags/articles">articles</category>
 <category domain="http://dikini.net/tags/code">code</category>
 <category domain="http://dikini.net/tags/draft">draft</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/study">study</category>
 <pubDate>Fri, 03 Feb 2006 08:45:56 -0500</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">123 at http://dikini.net</guid>
</item>
<item>
 <title>scheming away</title>
 <link>http://dikini.net/01.02.2006/scheming_away</link>
 <description>&lt;p&gt;In yesterday&#039;s &lt;a href=&quot;/freelinking/scheming%252520templates&quot;&gt;write-up&lt;/a&gt; I started touching scheme. It is part of my attempt to study the language. It might be a bit ambitious as a first &quot;real&quot; problem, though. So until I reach a solution for that, I will try and solve a few randomly selected different problems. Most of them will be something I already know how to say in other languages, the aim for most of them should be a cleaner solution. In the end I must prove to myself that it is worth learning scheme.&lt;/p&gt;
&lt;h3&gt;Today&#039;s problem&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Things or the theory of anything&lt;/strong&gt;&lt;br /&gt;
There were a lot of discussions going in the Drupal development circles around what is a node, what is a user, is a user a node, is a taxonomy term a node, etc... In Amsterdam a few of us were really impressed my anymeta by mediamatic, where everything is a thing.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/01.02.2006/scheming_away&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/01.02.2006/scheming_away#comment</comments>
 <category domain="http://dikini.net/tags/articles">articles</category>
 <category domain="http://dikini.net/tags/code">code</category>
 <category domain="http://dikini.net/tags/draft">draft</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/study">study</category>
 <pubDate>Wed, 01 Feb 2006 04:37:49 -0500</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">122 at http://dikini.net</guid>
</item>
<item>
 <title>scheming templates</title>
 <link>http://dikini.net/31.01.2006/scheming_templates</link>
 <description>&lt;p&gt;I&#039;m intrigued. You might have noticed that I like Lisp. Itellectually, that is. I don&#039;t really speak it. I finally decided to dive and try and learn it. On the surface it is not that hard - the language is extremely simple, essentially it has brackets and white space as separators, a couple of special forms - something like built in functions or language constructs in other language terminology, and a few really cool features like &lt;em&gt;quote&lt;/em&gt;, &lt;em&gt;unquote&lt;/em&gt;, &lt;em&gt;quasiquote&lt;/em&gt;, (precious special forms actually), oh, yes, it has an &lt;em&gt;eval&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In order to go forward with the learning I shall try and implement a simple web-design friendly template for xml applications. The idea is similar to TAL, or taglibs, etc...&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/31.01.2006/scheming_templates&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/31.01.2006/scheming_templates#comment</comments>
 <category domain="http://dikini.net/tags/articles">articles</category>
 <category domain="http://dikini.net/tags/code">code</category>
 <category domain="http://dikini.net/tags/lisp">lisp</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/webdesign">webdesign</category>
 <pubDate>Tue, 31 Jan 2006 06:09:53 -0500</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">121 at http://dikini.net</guid>
</item>
<item>
 <title>Some ways to use saved state with closures in php</title>
 <link>http://dikini.net/25.01.2006/some_ways_to_use_saved_state_with_closures_in_php</link>
 <description>&lt;p&gt;In a &lt;a href=&quot;http://dikini.net/24.01.2006/emulating_closures_in_php&quot;&gt;previous short post&lt;/a&gt; Idescribe a way to emulate closures in php. Using that technique execution environment, otherwise known as a call stack can be saved for future use. This can be put to good use. A couple of patterns or programming techniques could be useful in practice.&lt;/p&gt;
&lt;h3&gt;State pattern&lt;/h3&gt;
&lt;p&gt;A closure represents a state =&amp;gt; implemenation of a state pattern. This is a bit rich. Usually in OO programming the state pattern is implemented by encapsulating different protocols, for denoted states. This is simple to implement by substituting your protocol specification with a different name. Drupal hooks are a good example implementation of this. The following is a simplisting example implementation of a state pattern based on closures. The last argument of the deduced function is the closure itself.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
class function_object {
  var $scope;
  function __get($name) {
    return $this-&amp;gt;$scope-&amp;gt;$name;
  }
  function __call($name,$args) {
    $func =$this-&amp;gt;$state.&quot;_$name&quot;;
    $args[]=$this;
    return call_user_func_args($func,$args);
  }
  function __constructor($scope) {
    $this-&amp;gt;scope=$scope;
  }
  function __clone() {
    $this-&amp;gt;scope = clone($this-&amp;gt;scope);
  }
  function state($state) {
    $this-&amp;gt;state=$state;
  }
  function call() {
    //the function body - do some work
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To save the state for future use, for example as part of an undo cycle:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
  $saved = clone($closure);
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Call/cc or call with current continuation in php&lt;/h3&gt;
&lt;p&gt;Closure effectively represent the future of computation. This means that we can say what we want to do, by where we are. Since php doesn&#039;t implement any call stack optimisation, the call/cc style of programming makes sense in a limited number of cases. To use this style of programming we need to redefine our functions to use the continuation&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
 f(x,c) : c(f,x);&lt;br /&gt;
(var, continuation) -&amp;gt; continuation&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
and in php&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;br /&gt;
 //the function closure call method&lt;br /&gt;
 ...&lt;br /&gt;
 function call($x, $continuation) {&lt;br /&gt;
   $this-&amp;gt;scope=$continuation; // emulate c(f,x)&lt;br /&gt;
   ...&lt;br /&gt;
   do whatever you want here&lt;br /&gt;
 }&lt;br /&gt;
 ...&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
OK, this is rather crude. In reality this is very limited - it is assumed that the function is defined in a &#039;global&#039; scope, so we are putting it in some exhisting stack. It will be cleaner if the continuation implements the stack assignment, rather than rely on the function.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/25.01.2006/some_ways_to_use_saved_state_with_closures_in_php&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/25.01.2006/some_ways_to_use_saved_state_with_closures_in_php#comment</comments>
 <category domain="http://dikini.net/tags/articles">articles</category>
 <category domain="http://dikini.net/tags/code">code</category>
 <category domain="http://dikini.net/tags/design_patterns">design patterns</category>
 <category domain="http://dikini.net/tags/lisp">lisp</category>
 <category domain="http://dikini.net/tags/php">php</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/scribbles">scribbles</category>
 <category domain="http://dikini.net/taxonomy/term/105">shorts</category>
 <pubDate>Wed, 25 Jan 2006 05:23:50 -0500</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">120 at http://dikini.net</guid>
</item>
<item>
 <title>Emulating closures in PHP</title>
 <link>http://dikini.net/24.01.2006/emulating_closures_in_php</link>
 <description>&lt;blockquote&gt;In programming languages, a closure is an abstraction that combines a function and a special lexical environment bound to that function (scope). The variables in the lexical environment are designed to retain state information between function calls. Unlike garden-variety functions which retain no memory of what happened in previous calls, closures are &lt;strong&gt;capable of storing information across function calls&lt;/strong&gt;.&lt;a href=&quot;http://en.wikipedia.org/wiki/Closure_(computer_science)&quot;&gt;closulres in computer science (wikipedia)&lt;/a&gt;&lt;/blockquote&gt;
&lt;p&gt;PHP doesn&#039;t have closures as an element of the language. What can we do to emulate it?&lt;/p&gt;
&lt;p&gt;We need to be able to encapsulate in one entity scope, state and execution. The most obvious candidate will be a PHP object.&lt;/p&gt;

&lt;p&gt;With the introduction of the __get(), __set() and __call() magic functions for PHP classes, something the manual calls overloading, PHP opens the gate to transparently enhance a class to add variables and methods to an object&#039;s body. We can abuse the __get() to implemet nested scopes. The state is preserved as part of the object body. The default function (call()) is a protocol to add a uniformity of execution between different function objects.&lt;/p&gt;
&lt;code&gt;
class function_object {
  var $scope;
  function __get($name) {
    return $this-&gt;$scope-&gt;$name;
  }
  function __constructor($scope) {
    $this-&gt;scope=$scope;
  }
  function call() {
    //the function body - do some work
  }
}
&lt;/code&gt;

If all $scope objects are function objects we get a closure emulation in PHP. This opens the doors to such fancy ideas as namespaces, modules et.al. This technique opens the possibilities for functional style programming techniques and idioms as delayed evaluation, continuation, ...
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; I&#039;ve added &lt;a href=&quot;http://dikini.net/closure&quot;&gt;closures&lt;/a&gt; to my &lt;a href=&quot;http://dikini.net/php_design_patterns&quot;&gt;design patterns collection&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/24.01.2006/emulating_closures_in_php&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/24.01.2006/emulating_closures_in_php#comment</comments>
 <category domain="http://dikini.net/tags/articles">articles</category>
 <category domain="http://dikini.net/tags/code">code</category>
 <category domain="http://dikini.net/tags/design_patterns">design patterns</category>
 <category domain="http://dikini.net/tags/lisp">lisp</category>
 <category domain="http://dikini.net/tags/php">php</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/scribbles">scribbles</category>
 <category domain="http://dikini.net/taxonomy/term/105">shorts</category>
 <pubDate>Tue, 24 Jan 2006 04:03:26 -0500</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">119 at http://dikini.net</guid>
</item>
<item>
 <title>Learning lessons from Lisp  or patterns and languages in PHP</title>
 <link>http://dikini.net/20.01.2006/learning_lessons_from_lisp_or_patterns_and_languages_in_php</link>
 <description>In Lisp and its dialects everything is a first class language construct, that is it can be evaluated and changed from within the language. This gives a few very powerful abstractions, which help in constructing short but still readable programs. There are a few very powerful patterns coming from this single concept. 
&lt;h3&gt;A function is a first class variable. It can be assigned to.&lt;/h3&gt;
This is directly applicable in PHP. Since the php symbol table is a big hash (roughly), you can access the function by it&#039;s name - for example: 
&lt;code&gt;
$func = &#039;a_function&#039;;
$var = $func();
&lt;/code&gt;
&lt;h3&gt;A program is a data structure, a list, so you can manipulate it using the language&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/20.01.2006/learning_lessons_from_lisp_or_patterns_and_languages_in_php&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/20.01.2006/learning_lessons_from_lisp_or_patterns_and_languages_in_php#comment</comments>
 <category domain="http://dikini.net/tags/articles">articles</category>
 <category domain="http://dikini.net/tags/code">code</category>
 <category domain="http://dikini.net/tags/design_patterns">design patterns</category>
 <category domain="http://dikini.net/tags/php">php</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <category domain="http://dikini.net/tags/scribbles">scribbles</category>
 <pubDate>Thu, 19 Jan 2006 09:48:26 -0500</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">117 at http://dikini.net</guid>
</item>
<item>
 <title>A pause for thought and some cut backs</title>
 <link>http://dikini.net/11.01.2006/a_pause_for_thought_and_some_cut_backs</link>
 <description>&lt;p&gt;I&#039;ve been reading. Scheming. And I stumpled upon &lt;a href=&quot;http://schematics.sourceforge.net/schemeunit-schemeql.ps&quot;&gt;SchemeUnit and SchemeQL: Two Little Languages&lt;/a&gt;. I liked the paper. Especially the SchemeQL part. It does state my (intellectual) motivation behind writing relations/sqlgen.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SQL statements are not checked until execution time. That is error prone.&lt;/li&gt;
&lt;li&gt;SQL statements are not host language statements. They can&#039;t be used in the same way or manipulated as the host language statements. Except by using crude text processing, one cannot programatically compose, abstract and refine embedded SQL statements. Code quality and productivity suffers.&lt;/li&gt;
&lt;p&gt;&lt;a href=&quot;http://dikini.net/11.01.2006/a_pause_for_thought_and_some_cut_backs&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://dikini.net/11.01.2006/a_pause_for_thought_and_some_cut_backs#comment</comments>
 <category domain="http://dikini.net/tags/drupal">drupal</category>
 <category domain="http://dikini.net/tags/programming">programming</category>
 <category domain="http://dikini.net/tags/projects">projects</category>
 <category domain="http://dikini.net/tags/relations">relations</category>
 <category domain="http://dikini.net/tags/scheme">scheme</category>
 <pubDate>Wed, 11 Jan 2006 06:05:00 -0500</pubDate>
 <dc:creator>vlado</dc:creator>
 <guid isPermaLink="false">114 at http://dikini.net</guid>
</item>
</channel>
</rss>
