<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-34156343</id><updated>2011-08-26T20:02:24.816+08:00</updated><category term='Objective-C bridge'/><category term='experimental'/><category term='Symbols'/><category term='Exceptions'/><category term='API'/><category term='Language'/><category term='Data structures'/><category term='Examples'/><category term='Processes'/><category term='macros'/><title type='text'>muSE - muvee Symbolic Expressions</title><subtitle type='html'>A small footprint embeddable open-source Scheme dialect.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>44</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-34156343.post-1429739908540634305</id><published>2010-11-29T11:13:00.004+08:00</published><updated>2010-11-29T11:22:11.741+08:00</updated><title type='text'>Saying "hello world!" on MacOSX ..</title><content type='html'>Here is a different "hello world!" by muSE on MacOSX :)&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span class="scm"&gt;&lt;br /&gt;&lt;span class="comment"&gt;; Load the AppKit framework containing the NSSpeechSynthesizer class&lt;/span&gt;&lt;br /&gt;[[NSBundle bundleWithPath: "/System/Library/Frameworks/AppKit.framework"] &lt;br /&gt;   load]&lt;br /&gt;&lt;br /&gt;&lt;span class="comment"&gt;; Initialize the "hysterical" voice and say "Hello world!" with it.&lt;/span&gt;&lt;br /&gt;(define hysterical &lt;br /&gt;  [[[NSSpeechSynthesizer alloc] initWithVoice: "com.apple.speech.synthesis.voice.Hysterical"] &lt;br /&gt;    autorelease])&lt;br /&gt;&lt;br /&gt;[hysterical startSpeakingString: "Hello world!"]&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-1429739908540634305?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/1429739908540634305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=1429739908540634305' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1429739908540634305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1429739908540634305'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2010/11/saying-hello-world-on-macosx.html' title='Saying &quot;hello world!&quot; on MacOSX ..'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-4143851830772782878</id><published>2009-07-12T17:23:00.003+08:00</published><updated>2009-07-12T17:36:48.924+08:00</updated><title type='text'>r580 release</title><content type='html'>Alright! r580 it is! ... just 'cuz I have to say &lt;b&gt;STOP!&lt;/b&gt; at some point, actually.&lt;br /&gt;&lt;br /&gt;All things considered, r580 should be a more usable and more robust release than most earlier ones. Apart from the usual features and bug fixes, the &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/trunk/examples/"&gt;examples&lt;/a&gt; have also been updated to this release and placed in the trunk folder along with the source code for added convenience.&lt;br /&gt;&lt;br /&gt;For details, see the &lt;a href="http://code.google.com/p/muvee-symbolic-expressions/wiki/AboutRelease580"&gt;AboutRelease580&lt;/a&gt; wiki page.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-4143851830772782878?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/4143851830772782878/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=4143851830772782878' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4143851830772782878'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4143851830772782878'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2009/07/r580-release.html' title='r580 release'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-400155241280274586</id><published>2009-07-08T10:11:00.005+08:00</published><updated>2009-07-08T10:49:03.499+08:00</updated><title type='text'>Candidate for next release</title><content type='html'>&lt;a href="http://code.google.com/p/muvee-symbolic-expressions/source/detail?r=535"&gt;r535&lt;/a&gt; is a likely candidate for the next binary build. It is also the version that I hope to synchronize with muvee's own use of muSE in muvee Reveal in the upcoming mid-August update. I've already updated the generated documentation to reflect r535. &lt;br /&gt;&lt;br /&gt;So far, its looking good and r535 solves many of the problems that existed before. I'm finally at the point including &lt;span class="scm"&gt;the&lt;/span&gt; and &lt;span class="scm"&gt;it&lt;/span&gt; (see &lt;a href="http://code.google.com/p/muvee-symbolic-expressions/wiki/TheAndIt"&gt;TheAndIt&lt;/a&gt;) in the language. Need to iron out a few kinks regarding them in conjunction with &lt;span class="scm"&gt;finally&lt;/span&gt; before I can say I'm done with that feature. So there'll surely be at least one more tag after r535. Also, I haven't tested on linux just yet - only macosx and win32.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-400155241280274586?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/400155241280274586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=400155241280274586' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/400155241280274586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/400155241280274586'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2009/07/candidate-for-next-release.html' title='Candidate for next release'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-98011685746697885</id><published>2009-04-17T10:14:00.005+08:00</published><updated>2009-04-17T10:32:06.505+08:00</updated><title type='text'>Announcing muvee-style-authoring public beta</title><content type='html'>What a long interval from the previous post, but I'm very excited about this one and have waited a long time for it.&lt;br /&gt; &lt;br /&gt;As I've claimed earlier, both &lt;a href="http://www.muvee.com/en/products/ap/ap6"&gt;muvee autoProducer 6.x&lt;/a&gt; and &lt;a href="http://www.muvee.com/en/products/reveal/"&gt;muvee Reveal&lt;/a&gt; use muSE as the core language for their styles, but told you nothing about how to create these styles yourself. Now we at muvee are opening up everything you need to create your own styles.&lt;br /&gt;&lt;br /&gt;Project page: &lt;a href="http://muvee-style-authoring.googlecode.com"&gt;muvee-style-authoring&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We've put up lots of documentation, a few tutorials to get you started (the set will grow), and have a helper tool to work with the styles you create. So go ahead, play around and &lt;bold&gt;give us feedback&lt;/bold&gt;. If you get the latest version of muvee Reveal, all the code for the built-in styles is open for you to explore and copy for your own styles.&lt;br /&gt;&lt;br /&gt;Note that the documentation and examples are all about muvee Reveal - i.e. you can only create your own styles for muvee Reveal.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-98011685746697885?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/98011685746697885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=98011685746697885' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/98011685746697885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/98011685746697885'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2009/04/announcing-muvee-style-authoring-public.html' title='Announcing muvee-style-authoring public beta'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-7957732188043969629</id><published>2008-07-19T11:15:00.001+08:00</published><updated>2008-07-19T11:15:23.164+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='experimental'/><title type='text'>Experimental 'the' and 'it' primitives</title><content type='html'>Version 437 introduces a couple of experimental primitives &lt;span class="scm"&gt;the&lt;/span&gt; and &lt;span class="scm"&gt;it&lt;/span&gt; aimed at minimising the need for local variables created to hold intermediate results.&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Main page &lt;a href="http://code.google.com/p/muvee-symbolic-expressions/"&gt;muvee-symbolic-expressions&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Description on the wiki page &lt;a href="http://code.google.com/p/muvee-symbolic-expressions/wiki/TheAndIt"&gt;TheAndIt&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Experimental win32 executable - &lt;a href="http://muvee-symbolic-expressions.googlecode.com/files/muse-v437-experimental-win32.zip"&gt;muse-v437-experimental-win32.zip&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class="flockcredit" style="text-align: right; color: #CCC; font-size: x-small;"&gt;Blogged with the &lt;a href="http://www.flock.com/blogged-with-flock" style="color: #999; font-weight: bold;" target="_new" title="Flock Browser"&gt;Flock Browser&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-7957732188043969629?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/7957732188043969629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=7957732188043969629' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7957732188043969629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7957732188043969629'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2008/07/experimental-and-primitives.html' title='Experimental &amp;#39;the&amp;#39; and &amp;#39;it&amp;#39; primitives'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-1903245635825181060</id><published>2008-06-12T13:44:00.001+08:00</published><updated>2008-06-12T13:46:26.215+08:00</updated><title type='text'>muvee Reveal</title><content type='html'>&lt;a href="http://www.muvee.com/en/products/reveal/"&gt;muvee Reveal&lt;/a&gt; - the latest incarnation of &lt;a href="http://www.muvee.com/"&gt;muvee&lt;/a&gt;'s flagship product - has just been released on 11 June 2008! The behaviours of the 8 bundled &lt;em&gt;styles&lt;/em&gt; are specified using muSE, in addition to all the styles developed for the now discontinued muvee autoProducer 6.1.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-1903245635825181060?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/1903245635825181060/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=1903245635825181060' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1903245635825181060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1903245635825181060'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2008/06/muvee-reveal.html' title='muvee Reveal'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-8655145002623075601</id><published>2007-12-29T10:59:00.000+08:00</published><updated>2007-12-29T11:36:20.466+08:00</updated><title type='text'>muSE v372 ...</title><content type='html'>Download - for &lt;a href="http://muvee-symbolic-expressions.googlecode.com/files/muse-v372-macosx.tar.gz"&gt;macosx&lt;/a&gt;, for &lt;a href="http://muvee-symbolic-expressions.googlecode.com/files/muse-v372-win32.zip"&gt;win32&lt;/a&gt;.&lt;br /&gt;Summary of changes between v343 and v372 -&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Features&lt;/b&gt;: Simple module support, more flexible xml reader, polymorphic &lt;tt&gt;get&lt;/tt&gt; and &lt;tt&gt;put&lt;/tt&gt;.&lt;/li&gt;&lt;li&gt;&lt;b&gt;APIs&lt;/b&gt;: memports, &lt;tt&gt;muse_read_xml_node&lt;/tt&gt; and &lt;tt&gt;muse_raise_error&lt;/tt&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;Bug fixes&lt;/b&gt;: GC fixes, &lt;tt&gt;muse_pread()&lt;/tt&gt; and anonymous symbols.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Detailed changes -&lt;br /&gt;&lt;h4&gt;Features&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;Support for simple modules.&lt;/li&gt;&lt;li&gt;The xml reader has been made slightly flexible in dealing with non-standard input. In xml tag attributes, &lt;tt&gt;attrib="value"&lt;/tt&gt; and &lt;tt&gt;attrib='value'&lt;/tt&gt; are standard but &lt;tt&gt;attrib=value&lt;/tt&gt; is not. Since a lot of html code uses &lt;tt&gt;attrib=value&lt;/tt&gt; form, this is also now accepted by the parser. Note that this is still not enough to accept old html files because they might contain non-xhtml tags such as &lt;tt&gt;&amp;lt;br&amp;gt;&lt;/tt&gt; which should be &lt;tt&gt;&amp;lt;br/&amp;gt;&lt;/tt&gt; in xhtml.&lt;/li&gt;&lt;li&gt;Added a notion of a &lt;tt&gt;'prop'&lt;/tt&gt; view for getting and setting properties of arbitrary native objects. Properties are accessed and modified using &lt;span class="scm"&gt;(get obj prop)&lt;/span&gt; and &lt;span class="scm"&gt;(put obj prop value)&lt;/span&gt;. i.e. &lt;tt&gt;get&lt;/tt&gt; and &lt;tt&gt;put&lt;/tt&gt; are now polymorphic over all object types that support the &lt;tt&gt;'prop'&lt;/tt&gt; view. See &lt;tt&gt;muse_prop_view_t&lt;/tt&gt; struct for the interface.&lt;/li&gt;&lt;li&gt;Added new "box" type in the same spirit as R5RS boxes.&lt;/li&gt;&lt;li&gt;A symbol of the form ".name" will be expanded into the  expression &lt;span class="scm"&gt;(-&amp;gt; self 'name)&lt;/span&gt; at read time. This makes it easy to refer to object properties from within method bodies.&lt;/li&gt;&lt;li&gt;Made module names behave like "do", except that within the scope of the module expression's body, symbols are interpreted in the scope of the module - irrespective&lt;br /&gt;of whether the module expression is at the global level or within a closure creating expression.&lt;br /&gt;This feature is made possible by the introduction of a new "scope view" - id &lt;tt&gt;'scop'&lt;/tt&gt; - which lets an object provide a hook into the closure creation code to introduce local bindings that aren't visible in the s-expression itself.&lt;br /&gt;The scope view lets us define context sensitive forms. Ultimately, all binding introducing forms - &lt;span class="scm"&gt;define&lt;/span&gt;, &lt;span class="scm"&gt;let&lt;/span&gt;, &lt;span class="scm"&gt;case&lt;/span&gt;, &lt;span class="scm"&gt;fn&lt;/span&gt;, &lt;span class="scm"&gt;fn:&lt;/span&gt; and &lt;span class="scm"&gt;gfn&lt;/span&gt; - can be implemented by providing a different scope view for each so that there is a constant testing overhead during closure creation instead of depending on the number of such special forms that need to be supported.&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;New APIs&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;Memport objects can be created from the C api.&lt;/li&gt;&lt;li&gt;&lt;tt&gt;muse_read_xml_node&lt;/tt&gt; is now exposed in the C api.&lt;/li&gt;&lt;li&gt;Added &lt;tt&gt;muse_raise_error()&lt;/tt&gt; for raising muSE exceptions in native code.&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Bug fixes&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;(major): The main process structure was being prematurely destroyed before the gc function call returned. As a consequence, the area around the process's stack got corrupted and &lt;tt&gt;muse_destroy_env()&lt;/tt&gt; won't exit cleanly. This went undetected because the primary use was via the repl which can be exited only using (exit) which terminates the whole process.&lt;/li&gt;&lt;li&gt;(major): Major GC bug that crept in from a process related tweak to make the gc run atomically. Ever since the tweak (to wrap &lt;tt&gt;muse_gc_impl()&lt;/tt&gt; within an atomic block) the gc never ran but simply grew the heap. FIXED! Whew! (I'd been wondering for a while why a gc never got triggered and the heap was grown instead during several large data set experiments, but didn't probe further. Lesson learnt - pay attention to your hunches!)&lt;/li&gt;&lt;li&gt;(minor): &lt;tt&gt;muse_pread()&lt;/tt&gt; wouldn't return EOF if there were only spaces or comments before end of file (or port in general). Modified it so that if only spaces and/or comments are found before it hits EOF, it dutifully fails.&lt;br /&gt;* (minor): Anonymous symbols cannot have the sym itself as the head value any more due to process architecture. So changed the head value of anonymous symbols to &lt;tt&gt;()&lt;/tt&gt; (or MUSE_NIL). Since this affects the gensym operator which converts an anonymous symbol into a permanently interned symbol, muse_intern_symbol was also modified to change the head value of an interned anonymous symbol to refer to the proper symbol location in the symbol vectors of all processes. &lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Other changes&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;Native objects are no longer evaluated lazily when they appear in the function position. They are treated like any other native function. This allows us to define native objects which evaluate their arguments inside a special kind of context.&lt;br /&gt;To compensate for this loss, the "lazy" operator's definition has been modified (and simplified) to cause a function application (native or user defined) to be&lt;br /&gt;postponed until forced. Using the new "lazy" operator, you can use tail recursion with native functions too.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-8655145002623075601?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/8655145002623075601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=8655145002623075601' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8655145002623075601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8655145002623075601'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/12/muse-v372.html' title='muSE v372 ...'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-172451913220854046</id><published>2007-11-03T17:06:00.001+08:00</published><updated>2007-11-04T23:28:37.452+08:00</updated><title type='text'>New v338 of muSE available</title><content type='html'>&lt;blockquote&gt;&lt;small&gt;Note that v338 has been replaced by v343, which contains a minor fix to the exception handling code. Prior to the introduction of &lt;tt&gt;finally&lt;/tt&gt;, an expresion such as &lt;tt&gt;(try (raise 'error))&lt;/tt&gt; probably indicated a programming error since no handlers were specified. With &lt;tt&gt;finally&lt;/tt&gt; however, a &lt;tt&gt;try&lt;/tt&gt; without handlers is valid since it may install finalizers using &lt;tt&gt;finally&lt;/tt&gt;.&lt;/small&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/muvee-symbolic-expressions/downloads/list" style="text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline; -webkit-text-decorations-in-effect: underline; "&gt;Downloads page&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;Summary of changes between v285 and v338 -&lt;br /&gt;&lt;h4&gt;Language and library features&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/api/group__PortIO.html#g37e83b916a8efe013243af6058b9a953"&gt;mickey&lt;/a&gt; processing support - turns muSE into a scheme-based macro expander.&lt;/li&gt;&lt;li&gt;Added native implementations of &lt;span class="scm"&gt;reverse&lt;/span&gt; and &lt;span class="scm"&gt;reverse!&lt;/span&gt; functions.&lt;/li&gt;&lt;li&gt;&lt;span class="scm"&gt;with-connection-to-server&lt;/span&gt; has been replaced with &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/api/group__Networking.html#g6a422d7cbe61ac3955b517347fe93ea4"&gt;open&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Added &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/api/muse__builtin__misc_8c.html#8d9114496c87b2b39ea7b06549acc9fd"&gt;split&lt;/a&gt; function to split a string at given separator characters.&lt;/li&gt;&lt;li&gt;&lt;span class="scm"&gt;[MAJOR!]&lt;/span&gt; Added &lt;span class="scm"&gt;(finally ...)&lt;/span&gt; to the exception mechanism. See &lt;a href="http://code.google.com/p/muvee-symbolic-expressions/wiki/ExceptionHandling"&gt;ExceptionHandling&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Invocation of &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/api/group__Processes.html#g2f4e9d486714febb8a76e75dff231fb1"&gt;spawn&lt;/a&gt; has been changed.&lt;/li&gt;&lt;/ol&gt;&lt;h4&gt;Bugfixes and enhancements&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;muSE can now be built as a dll.&lt;/li&gt;&lt;li&gt;Bug fixes in hashtable object.&lt;/li&gt;&lt;li&gt;Fixes to lazy evaluation mechanism. Incorrect behaviour in certain obscure circumstances.&lt;/li&gt;&lt;li&gt;Fixes to networking functions - particularly &lt;span class="scm"&gt;read&lt;/span&gt; will now return &lt;span class="scm"&gt;()&lt;/span&gt; when the socket it is reading from is closed at the other end.&lt;/li&gt;&lt;li&gt;Some fixes to exception handling implementation.&lt;/li&gt;&lt;li&gt;&lt;span class="scm"&gt;list-files&lt;/span&gt; now usable under unix using same (but limited) wild-card syntax like windows.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-172451913220854046?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/172451913220854046/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=172451913220854046' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/172451913220854046'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/172451913220854046'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/11/new-v338-of-muse-for-win32-available.html' title='New v338 of muSE available'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-4855542134433364214</id><published>2007-10-20T01:18:00.000+08:00</published><updated>2007-10-20T17:13:12.941+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exceptions'/><title type='text'>Finally!</title><content type='html'>&lt;a href="http://muvee-symbolic-expressions.blogspot.com/2007/03/exceptions-redux.html"&gt;A while ago&lt;/a&gt;, I'd written about raising and handling exceptions in muSE. The key idea, borrowed from Common Lisp, is that when an exception is raised, the execution context should not be unwound to the point where the exception can be handled. This allows an exception handler to resume execution from the point the exception occurred or try another handler, starting again from the inner most context. The current try-raise-retry facility in muSE manages to capture this requirement fairly well. However, there was one glaring omission - the inability to specify scope limited cleanup operations. In v332, muSE gets a cleanup mechanism ... finally ... I mean literally a &lt;span class="scm"&gt;finally&lt;/span&gt; block .. and this post is all about it. If you're going "oh yeah I know all about finally, Java has it", I humbly urge you to read on. You'll wish you had this in Java.&lt;br /&gt;&lt;br /&gt;In muSE, you can now place a code in a &lt;span class="scm"&gt;finally&lt;/span&gt; block that can feature &lt;em&gt;anywhere&lt;/em&gt; within an expression protected by a &lt;span class="scm"&gt;try&lt;/span&gt;. "Anywhere" doesn't just mean the &lt;em&gt;visible&lt;/em&gt; lexical scope, but the entire &lt;em&gt;execution&lt;/em&gt; scope. Not only can you have &lt;tt&gt;finally&lt;/tt&gt; anywhere, you can have as many of it as you need - you can even accumulate finalizing actions in a loop. The &lt;tt&gt;finally&lt;/tt&gt; block gets captured into a thunk that gets evaluated at the end of the scope of the &lt;tt&gt;try&lt;/tt&gt; context in which the block occurs. The thunks execute in the reverse order in which they are created. The thunks can refer to any variable in its lexical context, since a closure is created when evaluating a &lt;tt&gt;finally&lt;/tt&gt; block. &lt;br /&gt;&lt;br /&gt;Here is a simple example that reads a number from file F, multiples it by a given value and returns the result.&lt;br /&gt;&lt;pre&gt;&lt;span class="scm"&gt;&lt;br /&gt;&lt;span class="comment"&gt;; Raises an exception if the file couldn't be opened.&lt;/span&gt;&lt;br /&gt;(define (safe-open file)&lt;br /&gt;  (let ((f (open-file file 'for-reading)))&lt;br /&gt;    (if (eof? f)&lt;br /&gt;      (raise 'FileOpenError file)&lt;br /&gt;      (do (finally (print "Closing file" file) (close f))&lt;br /&gt;          f))))&lt;br /&gt;&lt;br /&gt;&lt;span class="comment"&gt;; Read a number from a file&lt;/span&gt;&lt;br /&gt;(define (read-number file)&lt;br /&gt;  (define F (safe-open file))&lt;br /&gt;    (let ((n (read F)))&lt;br /&gt;      (if (number? n) n (raise 'NotANumber n))))&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Here is a way to read a number from "F.scm" and if you don't get a number, use a default value -&lt;br /&gt;&lt;pre&gt;&lt;span class="scm"&gt;&lt;br /&gt;(try (read-number "F.scm")&lt;br /&gt;  (fn (ex 'NotANumber n)&lt;br /&gt;    42))&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Here is a way to read a number from "F.scm" and if the file doesn't exist, use "Default.scm" instead -&lt;br /&gt;&lt;pre&gt;&lt;span class="scm"&gt;&lt;br /&gt;(try (read-number "F.scm")&lt;br /&gt;  (fn (cont 'FileOpenError file)&lt;br /&gt;    (cont (safe-open "Default.scm"))))&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When do exceptional conditions occur?&lt;br /&gt;&lt;br /&gt;In pure computations, they can happen when an unsupported - "unexpected" - input value is encountered when calculating the result. Let us call these p-type exceptions. The other type is when dealing with side-effecting computations, of which IO is arguably the most dominant case. Let us call these s-type exceptions. &lt;br /&gt;&lt;br /&gt;p-type exceptions can be dealt with in a language which allows one to substitute another expression for one containing the exceptional case, when the case does happen. muSE does this fairly well with its try-raise-retry operators. The example function in the &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2007/03/exceptions-redux.html"&gt;earlier article&lt;/a&gt; shows how a pure function with an exceptional condition can be tamed by the calling context, given an expression substitution mechanism.&lt;br /&gt;&lt;br /&gt;s-type exceptions cannot be dealt with adequately with a pure-expression substitution mechanism. In the interest of composability, it is often desirable to wrap side-effecting expressions into what feels like a pure function - for example, a data structure lookup that appears to never fail might be implemented via a connection to a remote database. To do that, we need to be able to execute one or more side-effecting cleanup operation, such as closing the database connection, before the wrapper function returns to its calling context. &lt;br /&gt;&lt;br /&gt;With the new finally block, I believes muSE satisfies both these cases.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-4855542134433364214?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/4855542134433364214/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=4855542134433364214' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4855542134433364214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4855542134433364214'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/10/finally.html' title='Finally!'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-8225586099497044182</id><published>2007-10-01T11:55:00.000+08:00</published><updated>2007-10-01T11:58:44.831+08:00</updated><title type='text'>muSE on MacOSX Intel</title><content type='html'>Now I have an Intel MacOSX machine and can build and verify muSE on it.&lt;br /&gt;The v285 build was broken on OSX Intel machines and I've fixed it (&lt;a href="http://code.google.com/p/muvee-symbolic-expressions/issues/detail?id=32&amp;can=1"&gt;Issue 32&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;Here is a build with the fixes - &lt;a href="http://muvee-symbolic-expressions.googlecode.com/files/muse-v316-objc-macosx.tar.gz"&gt;muSE-v316-objc-macosx.tar.gz"&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-8225586099497044182?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/8225586099497044182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=8225586099497044182' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8225586099497044182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8225586099497044182'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/10/muse-on-macosx-intel.html' title='muSE on MacOSX Intel'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-7859545741537426863</id><published>2007-08-15T07:31:00.000+08:00</published><updated>2007-08-19T11:50:53.986+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Examples'/><title type='text'>Curry Howard isomorphism</title><content type='html'>&lt;a href="http://en.wikipedia.org/wiki/Curry-Howard_isomorphism"&gt;Curry Howard isomorphism&lt;/a&gt; states that every logical proposition corresponds to a type. (See also &lt;a href="http://www.haskell.org/haskellwiki/Curry-Howard-Lambek_correspondence"&gt;Curry-Howard-Lambek correspondence&lt;/a&gt;.) I've been fascinated by this recently, in the context of Haskell, 'cos it yields very interesting and powerful functions. Often you can just take the type expression in Haskell and write a function that has the type.&lt;br /&gt;&lt;br /&gt;For example, consider the trivial logic "theorem" - &lt;blockquote&gt;If it is true that proposition A implies proposition B, then A is provable implies B is provable. &lt;/blockquote&gt; If you notate provability by the symbol &lt;span class="scm"&gt;#&lt;/span&gt;, you can write that as - &lt;blockquote&gt;(A =&gt; B) =&gt; (#A =&gt; #B)&lt;/blockquote&gt; If you consider &lt;span class="scm"&gt;=&gt;&lt;/span&gt; to be the function type constructor (in Haskell), this gives you the type of &lt;span class="scm"&gt;fmap&lt;/span&gt; where &lt;span class="scm"&gt;#&lt;/span&gt; is any &lt;em&gt;functor&lt;/em&gt;. It looks like you can uniformly map "is provable" to some kind of containment - like a list or a set.&lt;br /&gt;&lt;br /&gt;Here's a very interesting function derived from another logic proposition - &lt;a href="http://sigfpe.blogspot.com/2006/11/from-l-theorem-to-spreadsheet.html"&gt;From Löb's Theorem to Spreadsheet Evaluation&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Here's an implementation of the &lt;span class="scm"&gt;loeb&lt;/span&gt; function in muSE -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;&lt;font color="#7F7F7F"&gt;; Limitation - fmap over lists only&lt;/font&gt;&lt;br /&gt;(define (fmap f x) &lt;br /&gt;    (if x &lt;br /&gt;        (lcons (f (first x)) &lt;br /&gt;               (fmap f (rest x))) &lt;br /&gt;        ()))&lt;br /&gt;(define (loeb x) (fmap (fn (a) (a (loeb x))) x))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;.. and a variant on the author's example -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(define test&lt;br /&gt;    (list   (fn (x) 17)&lt;br /&gt;            (fn (x) (apply + (drop 3 x)))&lt;br /&gt;            (fn (x) (* 2 (nth 3 x)))&lt;br /&gt;            (fn (x) (+ (nth 4 x) (nth 5 x)))&lt;br /&gt;            (fn (x) 3)&lt;br /&gt;            (fn (x) (nth 0 x))))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-7859545741537426863?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/7859545741537426863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=7859545741537426863' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7859545741537426863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7859545741537426863'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/08/curry-howard-isomorphism.html' title='Curry Howard isomorphism'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-3046529150622514374</id><published>2007-08-15T07:19:00.000+08:00</published><updated>2007-08-19T11:50:31.087+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Examples'/><title type='text'>The stair climbing robot</title><content type='html'>An interesting problem called "the stair climbing robot" was recently &lt;a href="http://lambda-the-ultimate.org/node/1872"&gt;posted on LtU&lt;/a&gt;. &lt;br /&gt;&lt;blockquote&gt;Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a boolean flag: true on success, false on failure. Write a function "step_up" that climbs one step up (by repeating "step" attempts if necessary). Assume that the robot is not already at the top of the stairs, and neither does it ever reach the bottom of the stairs. How small can you make "step_up"? Can you avoid using variables (even immutable ones) and numbers?&lt;/blockquote&gt;&lt;br /&gt;I thought I'll try to solve it using muSE's &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2007/05/getting-lazy.html"&gt;lcons lazy function&lt;/a&gt;. Here's a solution -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;&lt;font color="#7F7F7F"&gt;; A step function which fails 50% of the time.&lt;/font&gt;&lt;br /&gt;(define (step) &lt;br /&gt;    (if (= 0 (rand 2)) &lt;br /&gt;        (do (print "DOWN") ()) &lt;br /&gt;        (do (print "UP") T)))&lt;br /&gt; &lt;br /&gt;&lt;font color="#7F7F7F"&gt;; Gets the second element of a list s,&lt;br /&gt;; forcing the value of the first element if&lt;br /&gt;; the list happens to be lazy.&lt;/font&gt;       &lt;br /&gt;(define (forced-next s) (first s) (first (rest s)))&lt;br /&gt;&lt;br /&gt;&lt;font color="#7F7F7F"&gt;; (steps) generates a sequence of&lt;br /&gt;; successful upward steps. To climb N steps,&lt;br /&gt;; just take N elements from (steps).&lt;/font&gt;&lt;br /&gt;(define (steps)&lt;br /&gt;    (lcons (if (step)&lt;br /&gt;                T&lt;br /&gt;                (forced-next (rest (steps))))&lt;br /&gt;            (steps)))&lt;br /&gt;&lt;br /&gt;&lt;font color="#7F7F7F"&gt;; Climb 1 step&lt;/font&gt;&lt;br /&gt;(take 1 (steps))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-3046529150622514374?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/3046529150622514374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=3046529150622514374' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/3046529150622514374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/3046529150622514374'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/08/stair-climbing-robot.html' title='The stair climbing robot'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-1034070221393365152</id><published>2007-07-31T21:12:00.000+08:00</published><updated>2007-08-19T11:52:30.289+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Processes'/><title type='text'>spawn behaviour changed in v295</title><content type='html'>The &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/12/erlang-style-processes-in-muse.html"&gt;spawn&lt;/a&gt; function has different semantics from v295 of muSE. &lt;br /&gt;&lt;br /&gt;Prior to v295, &lt;tt&gt;spawn&lt;/tt&gt; took a thunk and evaluated it in a separate process repeatedly until the thunk evaluated to a non-&lt;tt&gt;()&lt;/tt&gt; value. This was done to make it simpler to write server processes that run the same code over and over until some condition occurs that makes it terminate.&lt;br /&gt;&lt;br /&gt;Since v250, muSE has had support for &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2007/05/getting-lazy.html"&gt;stack optimized tail recursion and lazy evaluation&lt;/a&gt;. This means we can now write server processes as tail recursive functions that never terminate. Therefore we don't need the extra help provided by the &lt;tt&gt;spawn&lt;/tt&gt; function any more. &lt;br /&gt;&lt;br /&gt;From v295, &lt;span class="scm"&gt;(spawn thunk)&lt;/span&gt; will cause &lt;span class="scm"&gt;(thunk)&lt;/span&gt; to be evaluated only once and it will discard the result. &lt;br /&gt;&lt;br /&gt;Expressing server processes as tail recursive functions, besides stating the obvious, gives you new ways to modularize parts of the server. If your server needs to be placed into modes when it receives certain input, each of these modes can be expressed as tail recursive functions that revert back to the main server function whenever an exit mode message is received.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-1034070221393365152?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/1034070221393365152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=1034070221393365152' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1034070221393365152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1034070221393365152'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/07/spawn-behaviour-changed-in-v295.html' title='spawn behaviour changed in v295'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-7231639570068577341</id><published>2007-07-17T02:15:00.000+08:00</published><updated>2007-07-17T21:33:54.920+08:00</updated><title type='text'>XML processing</title><content type='html'>muSE now (in v285) has support for parsing and generating simple XML structures. See -&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/api/group__PortIO.html#g43e20503d130213a336ab78e7d64f28d"&gt;read-xml&lt;/a&gt; and &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/api/group__PortIO.html#g1e609c18047e7fcd3bfb12bf012c5145"&gt;write-xml&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/examples/xml-v271.scm"&gt;xml-v271.scm&lt;/a&gt; for useful predicates and combinators&lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/muvee-symbolic-expressions/wiki/XMLProcessing"&gt;XMLProcessing&lt;/a&gt; wiki page&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-7231639570068577341?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/7231639570068577341/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=7231639570068577341' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7231639570068577341'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7231639570068577341'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/07/xml-processing.html' title='XML processing'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-7694415069119120535</id><published>2007-05-23T04:30:00.000+08:00</published><updated>2007-08-19T11:51:29.123+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Language'/><category scheme='http://www.blogger.com/atom/ns#' term='Data structures'/><category scheme='http://www.blogger.com/atom/ns#' term='Examples'/><title type='text'>Getting lazy</title><content type='html'>Recently, in v250 of the muSE core library, I added support for stack optimization of tail calls - finally! &lt;br /&gt;&lt;br /&gt;muSE has been missing the ability to do tail recursion for ever and now its finally there. The absence of tail recursion support had a rather ugly but practical consequence for the language - the &lt;tt&gt;while&lt;/tt&gt; and &lt;tt&gt;for&lt;/tt&gt; looping constructs had a reason to exist because you couldn't loop otherwise without blowing the stack top. I'm glad to note that they can now be safely RIP-d.&lt;br /&gt;&lt;br /&gt;Tail call optimization as implemented does not apply to tail calls of native functions. It only applies to applications of user defined functions that appear in the tail position in a block.&lt;br /&gt;&lt;br /&gt;As a by-product of the tail call optimization, I was surprised to find it easy to implement lazy evaluation. There's an experimental primitive &lt;span class="scm"&gt;lcons&lt;/span&gt; which can be used to construct a list lazily. This operator is inspired by Dan Friedman's &lt;a href="http://www.cs.indiana.edu/cgi-bin/techreports/TRNNN.cgi?trnum=TR44"&gt;TR44: CONS should not evaluate its arguments&lt;/a&gt; technical report. Some classic examples can be found in &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/examples/lcons-v238.scm"&gt;examples/lcons-v238.scm&lt;/a&gt; in the source tree.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-7694415069119120535?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/7694415069119120535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=7694415069119120535' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7694415069119120535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7694415069119120535'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/05/getting-lazy.html' title='Getting lazy'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-5473896992206010383</id><published>2007-03-30T21:28:00.000+08:00</published><updated>2007-04-12T13:40:10.899+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exceptions'/><title type='text'>Exceptions redux</title><content type='html'>&lt;small&gt;(Ref to muSE v234)&lt;/small&gt;&lt;br /&gt;Although I've written about it a bit &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/12/exception-mechanism.html"&gt;earlier&lt;/a&gt;, I did not do muSE's version of exception handling and recovery enough justice then. I simply described how to use it, that too incompletely. &lt;br /&gt;&lt;br /&gt;The bigger picture here is the question - &lt;blockquote&gt;What interface does a function exactly provide its user?&lt;/blockquote&gt; In languages such as C, functions as computation specifications are used only via their arguments, or via side effects on the environment. A function's documentation will typically tell you what it will do when you pass it certain arguments, what its "return value" will be and what side effect, if any, it will have on the environment at the time it is called. No facility was provided in the language to deal with exceptional conditions. Programmers usually used the "return value" to flag error conditions, which are expected to be "handled" by the caller, usually propagating the condition up the stack until something can be done about it.&lt;br /&gt;&lt;br /&gt;C++ introduced (let's assume for simplicity) into the mainstream programmer's consciousness the notion that a function might "throw" an "exception" rather than return a value. The "throw" construct indicated that the function's computation was being terminated and it was not going to return to its caller as expected to do so under normal conditions. Instead, it was going to bounce around into "catch" blocks higher and higher in the stack of calls until one block can "handle" the exception - with the hope that it will somehow be able to recover from it. The stack would be unwound until such a willing handler is found or the program is terminated.&lt;br /&gt;&lt;br /&gt;Java dutifully formalized this mechanism and declared that a function's signature is not only about its arguments and the return value, but is also about the exceptions that it can throw to its caller. &lt;br /&gt;&lt;br /&gt;To summarize, a function can either return to its caller normally, or throw an exception. In both Java and C++, once a function terminates either by returning or by throwing an exception, all information about the intermediate state of the computation that was being performed when the exceptional condition occurred is destroyed. C++'s stack unwinding mechanism calls object destructors along the way and Java, since it doesn't keep objects on the stack, provides a &lt;tt&gt;finally&lt;/tt&gt; block where you can do your own cleanup before the exception is passed to the caller.&lt;br /&gt;&lt;br /&gt;Hmmm ... now, what can you really do in a catch block in C++ or Java? It is a good exercise to scour the net for C++ and Java code examples that purport to teach the reader the exception mechanism in these languages. I mean do that right now. See if you come up with anything more sophisticated than -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;try {&lt;br /&gt;  // Call function which throws exception ..&lt;br /&gt;  int hex = 355, spell = 113;&lt;br /&gt;  abracadabra( hex/(double)spell, "hocus pocus" );&lt;br /&gt;} catch ( IncantationFailedException &amp;ex ) {&lt;br /&gt;  // Handle the exception&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;or maybe&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;try {&lt;br /&gt;  ...&lt;br /&gt;} catch ( IncantationFailedException &amp;ex ) {&lt;br /&gt;  std::cerr &lt;&lt; "Incantation 'abracadabra' didn't work!\n";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Even in Herb Sutter's insight filled book &lt;a href="http://www.gotw.ca/publications/xc++.htm"&gt;Exceptional C++&lt;/a&gt;, the pages 25 to 68 on &lt;em&gt;Exception Safety : Issues and Techniques&lt;/em&gt; fail to cite a single useful case for the &lt;tt&gt;catch&lt;/tt&gt; clause, let alone recommend typical usage. Though it can be argued that the chapter is on exception safety and not exception handling, all I'm asking for is one good example. If you do find a good case or description of "recommended practice" anywhere, I'd appreciate links as comments to this post.&lt;br /&gt;&lt;br /&gt;Is it then a consequence of instructional failure that decent bodies of C++ code hardly ever use the &lt;tt&gt;catch&lt;/tt&gt; mechanism and only use the destructor calls that happen when the stack unwinds? I dare a conjecture here - &lt;blockquote&gt;The reason &lt;tt&gt;catch&lt;/tt&gt; blocks that do something more substantial than code like the above are hard to find is that the &lt;tt&gt;catch&lt;/tt&gt; mechanism is impotent and consequently nearly useless as a design tool.&lt;/blockquote&gt;&lt;br /&gt;The Common Lisp folks have provided a more flexible definition of a function - that its not just about the arguments and the "return value", but can be &lt;em&gt;an arbitrary protocol&lt;/em&gt; in which control can pass between the caller and a particular invocation multiple times before the task is done. Peter Seibel talks in detail about the Common Lisp &lt;em&gt;conditions&lt;/em&gt; facility in &lt;a href="http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html"&gt;Beyond&amp;nbsp;Exception&amp;nbsp;Handling&amp;nbsp;:&amp;nbsp;Conditions&amp;nbsp;and&amp;nbsp;Restarts&lt;/a&gt; and provides a concrete example where a function is useful in more than one context because it exposes such a protocol to its caller.&lt;br /&gt;&lt;br /&gt;Having experienced deep frustration on several occasions along the lines of - "if only this function would let me customize the way it treats this condition differently, I won't have to write my own", I realized that the exception mechanism was standing in the way of a significant amount of code reusability. Library functions were deciding too much for me. It is cumbersome to keep passing protocol handlers via arguments for every function, so nobody does that either.&lt;br /&gt;&lt;br /&gt;I use muSE as a platform for experimenting with the language features I'd like to have, so I decided to &lt;tt&gt;try&lt;/tt&gt; something more flexible than C++/Java and less cumbersome to use than CL - a mechanism with which you can ignore exceptions when you call a function or go all out to customize the way a function should behave - the former case not requiring any additional work on your part, as it should be. Along the way, I figured that pattern matching dispatch works very well to achieve this goal and makes the handling of exceptions and restarts much simpler than the Common Lisp approach.&lt;br /&gt;&lt;br /&gt;Syntactically, the muSE approach is similar to C++/Java - an expression that might not evaluate successfully is wrapped into a &lt;tt&gt;try&lt;/tt&gt; expression and a set of &lt;em&gt;handlers&lt;/em&gt; are provided to try when the expression failed to evaluate normally. In order to signal an abnormal condition, a function uses the &lt;tt&gt;raise&lt;/tt&gt; function, supplying it an arbitrary set of arguments that get passed on to the handlers. Here's a simple, though contrived, example &lt;a href="#exceptions-redux-appendix-efficiency"&gt;(*)&lt;/a&gt;-&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(define H (fn (x y)&lt;br /&gt;             (try (/ (+ x y)&lt;br /&gt;                     (if (= x y)&lt;br /&gt;                         (raise 'DivideByZeroDiff x y)&lt;br /&gt;                         (- x y)))&lt;br /&gt;               (fn ('ForceResult r) r))))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;The above function tries to compute the value &lt;tt&gt;(x + y)/(x - y)&lt;/tt&gt;. It can't perform the division if &lt;tt&gt;x = y&lt;/tt&gt;, so it raises a &lt;tt&gt;'DivideByZeroDiff&lt;/tt&gt; condition in that case. It also provides a code path using which you can force the result of the function to be some arbitrary value in case nothing else can be done about it. Here's a caller trying to compute something using this function &lt;a href="#exceptions-redux-appendix-efficiency"&gt;(*)&lt;/a&gt; -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(define G (fn (x1 y1 x2 y2)&lt;br /&gt;             (try (/ (H x1 y1) (H x2 y2))&lt;br /&gt;               (fn (ex 'DivideByZeroDiff x y)&lt;br /&gt;                  (if (= (- x1 y1) (- x2 y2))&lt;br /&gt;                      (ex 1)&lt;br /&gt;                      (retry 'ForceResult 2000))))))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;tt&gt;G&lt;/tt&gt; is trying to compute &lt;tt&gt;H(x1,y1)/H(x2,y2)&lt;/tt&gt;.  If one of the differences &lt;tt&gt;(x1-y1)&lt;/tt&gt; and &lt;tt&gt;(x2-y2)&lt;/tt&gt; becomes small, &lt;tt&gt;H&lt;/tt&gt; will raise the &lt;tt&gt;'DivideByZeroDiff&lt;/tt&gt; exception. Now, &lt;tt&gt;G&lt;/tt&gt; knows that if the two differences are equal, the actual value of the difference doesn't matter to the end result. The &lt;tt&gt;H&lt;/tt&gt; function cannot possibly know this. So in this case, &lt;tt&gt;G&lt;/tt&gt; simply asks &lt;tt&gt;H&lt;/tt&gt; to assume a value of &lt;tt&gt;1&lt;/tt&gt; instead of the &lt;tt&gt;(raise ...)&lt;/tt&gt; expression and continue to compute the result. If this is not the case, &lt;tt&gt;G&lt;/tt&gt; decides to cap the value of &lt;tt&gt;H&lt;/tt&gt; to &lt;tt&gt;2000&lt;/tt&gt; using the &lt;tt&gt;'ForceResult&lt;/tt&gt; code path.&lt;br /&gt;&lt;br /&gt;Note that &lt;tt&gt;H&lt;/tt&gt; embodies no knowledge about the domain that &lt;tt&gt;G&lt;/tt&gt; knows about. This makes it possible to use &lt;tt&gt;H&lt;/tt&gt; in situations where the original author cannot possibly know how to handle the divide by zero case. The computations performed by this example are trivial, but when they are substantial, the facility to interact with the execution flow of a function definitely renders it more useful in a broader set of contexts and therefore useful as a design tool. Peter Seibel's more substantial log file parsing example can be expressed using the &lt;tt&gt;try-raise-retry&lt;/tt&gt; constructs too.&lt;br /&gt;&lt;br /&gt;We've used pattern matching throughout to catch raised conditions and to pass on control to restart points. The Common Lisp approach has equivalent functionality, but to me appears more verbose than really needs to be. In muSE, a function's interface consists of a hierarchical set of patterns -&lt;br /&gt;&lt;ol&gt;&lt;li&gt;The argument pattern which must match in order for the function's computation to even start,&lt;/li&gt;&lt;br /&gt;&lt;li&gt;a tree of exception patterns, handlers and restart patterns,&lt;/li&gt;&lt;br /&gt;&lt;li&gt;the result value and&lt;/li&gt;&lt;br /&gt;&lt;li&gt;side effects if any.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;All of them are available as design tools for a function creator so that she can create code that can be used in a variety of contexts not all of which can be known at design time.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;An analogy&lt;/h3&gt;&lt;br /&gt;It is interesting to compare the hierarchy of function dependencies to a company's employee hierarchy. It is often the case that at every designation, an employee has access to some information that employees at lower designations don't. This information lets them make decisions in situations where those working under them don't know enough to make the decision themselves.&lt;br /&gt;&lt;br /&gt;Imagine a company &lt;tt&gt;P&lt;/tt&gt; that works like this - a task is handed down to the top-level employee who further describes it and hands subtasks down to those working under her. The company philosophy is that whenever an employee reaches a point at which she can't take a decision, she promptly destroys all the work she's done starting from the time her task was handed to her. &lt;b&gt;Then&lt;/b&gt; she informs her boss that such a situation has happened. Her boss is very happy with her capacity to cleanup her work without leaving a trace, destroys all the work she has done since her task was handed down, files a report in the company activity database and talks to &lt;b&gt;her&lt;/b&gt; boss about what happened, in her own language.&lt;br /&gt;&lt;br /&gt;I'm sure you don't work in a company like that! Now bump up the scale and imagine if Boeing worked like that! &lt;br /&gt;&lt;br /&gt;What usually happens is that the lower level employee &lt;em&gt;suspends&lt;/em&gt; her work and immediately talks to her boss, presenting her with a few options. Her boss, based on what she understands, instructs her to proceed in a particular direction. The result is that the task gets done. All the way up the hierarchy.&lt;br /&gt;&lt;br /&gt;We'll not want to work in the pathological company &lt;tt&gt;P&lt;/tt&gt;, but we all choose to live with and even praise programming languages that work exactly like that.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Appendix&lt;/h3&gt;&lt;br /&gt;&lt;div id="exceptions-redux-appendix-efficiency"&gt;(*) In muSE, it is slightly more efficient to write the G and H functions as -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(define H (fn (x y)&lt;br /&gt;             (try (/ (+ x y)&lt;br /&gt;                     (if (= x y)&lt;br /&gt;                         (raise 'DivideByZeroDiff x y)&lt;br /&gt;                         (- x y)))&lt;br /&gt;               {fn: ('ForceResult r) r})))&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(define G (fn (x1 y1 x2 y2)&lt;br /&gt;             (try (/ (H x1 y1) (H x2 y2))&lt;br /&gt;               {fn: (ex 'DivideByZeroDiff x y)&lt;br /&gt;                  (if (= (- x1 y1) (- x2 y2))&lt;br /&gt;                      (ex 1)&lt;br /&gt;                      (retry 'ForceResult 2000))})))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-5473896992206010383?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/5473896992206010383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=5473896992206010383' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5473896992206010383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5473896992206010383'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/03/exceptions-redux.html' title='Exceptions redux'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-3201921382200269518</id><published>2007-03-13T02:01:00.000+08:00</published><updated>2007-04-12T13:39:48.981+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Objective-C bridge'/><title type='text'>An Objective Scheme</title><content type='html'>Here's a first cut at an Objective-C bridge for muSE on MacOSX. There cannot be an easier way to run native code from muSE!&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Code is on the &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/branches/objc/"&gt;objc branch&lt;/a&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Here's &lt;a href="http://code.google.com/p/muvee-symbolic-expressions/downloads/list"&gt;a prebuilt universal binary&lt;/a&gt; for MacOSX.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The wiki page - &lt;a href="http://code.google.com/p/muvee-symbolic-expressions/wiki/AnObjectiveScheme"&gt;AnObjectiveScheme&lt;/a&gt; describes it a bit.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-3201921382200269518?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/3201921382200269518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=3201921382200269518' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/3201921382200269518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/3201921382200269518'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/03/objective-scheme.html' title='An Objective Scheme'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-7800030386750597518</id><published>2007-02-14T11:26:00.000+08:00</published><updated>2007-02-14T11:30:31.169+08:00</updated><title type='text'>Performance</title><content type='html'>When you know your code is correct and you don't get any of the diagnostics boxes popping up under Windows or stderr dumps on unices, you may be able to get up to twice the performance of your existing code by turning off the internal diagnostic checks.&lt;br /&gt;&lt;br /&gt;To turn of diagnostics, edit the &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/trunk/src/muse_config.h"&gt; src/muse_config.h&lt;/a&gt; file, set the &lt;tt&gt;MUSE_DIAGNOSTICS_LEVEL&lt;/tt&gt; to &lt;tt&gt;0&lt;/tt&gt; and recompile muSE.&lt;br /&gt;&lt;br /&gt;If performance with diagnostics on is acceptable, you should consider leaving the checks in place.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-7800030386750597518?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/7800030386750597518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=7800030386750597518' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7800030386750597518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7800030386750597518'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/02/performance.html' title='Performance'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-1977332543581267072</id><published>2007-02-02T07:09:00.000+08:00</published><updated>2007-02-02T07:44:07.549+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='API'/><title type='text'>Subversion perversion</title><content type='html'>As I'd &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/12/google-code-adds-wiki.html"&gt;mentioned earlier&lt;/a&gt;, Google code has added a Wiki feature supposed to be useful to maintain documentation. We in the programming world know that once you document stuff in a place other than the original source code, it rapidly goes out of sync. So I tried another way to present the generated muSE documentation right where the source code is available - the Subversion repo itself.&lt;br /&gt;&lt;br /&gt;I simply generated the HTML documentation using &lt;a href="http://www.stack.nl/~dimitri/doxygen/"&gt;doxygen&lt;/a&gt; and placed the output into its own Subversion module/folder - &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/api/index.html"&gt;here&lt;/a&gt;. Once all the files are tagged with the appropriate mime types, the whole site is functional .. and versioned to boot! &lt;br /&gt;&lt;br /&gt;Here are the mime-type setting commands you need to use in the doxygen generated documentation folder -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;svn propset svn:mime-type "text/html" *.html&lt;br /&gt;svn propset svn:mime-type "image/png" *.png&lt;br /&gt;svn propset svn:mime-type "text/css" *.css&lt;br /&gt;svn propset svn:mime-type "image/gif" *.gif&lt;br /&gt;svn propset svn:mime-type "text/plain" *.md5&lt;br /&gt;svn propset svn:mime-type "text/plain" *.map&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-1977332543581267072?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/1977332543581267072/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=1977332543581267072' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1977332543581267072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1977332543581267072'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/02/subversion-perversion.html' title='Subversion perversion'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-829625555621329792</id><published>2007-01-19T15:45:00.000+08:00</published><updated>2007-01-21T10:03:28.171+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='macros'/><title type='text'>A simple module system using macros</title><content type='html'>In this post, I describe how to build a simple module system. For simplicity, I assume we won't be providing support for mutually recursive functions within a module.&lt;br /&gt;&lt;br /&gt;You can think of a module as a set of symbols and the values they must be bound to. These bindings are made current whenever you "enter" a module's scope and they vanish whenever you exit the scope. Here's what we hope to achieve, with a statistics module as an example -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(define Statistics&lt;br /&gt;  (module &lt;br /&gt;    (mean &lt;br /&gt;      (fn args (/ (apply + args) (length args))))&lt;br /&gt;&lt;br /&gt;    (variance &lt;br /&gt;      (fn args (- (apply mean (map (fn (x) (* x x)) args)) &lt;br /&gt;                  (let ((mx (apply mean args)))&lt;br /&gt;                     (* mx mx)))))&lt;br /&gt;  ))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;The above module provides definitions for &lt;tt&gt;mean&lt;/tt&gt; and &lt;tt&gt;variance&lt;/tt&gt;. &lt;br /&gt;&lt;br /&gt;Notice that the body of the module definition is very similar to the bindings section of the &lt;tt&gt;let&lt;/tt&gt; construct. We can therefore use the &lt;tt&gt;let&lt;/tt&gt; construct in a &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/09/read-time-evaluation-in-muse.html"&gt;macro system&lt;/a&gt; to implement &lt;tt&gt;module&lt;/tt&gt; as a macro.&lt;br /&gt;&lt;br /&gt;It is simple to use the &lt;tt&gt;Statistics&lt;/tt&gt; module like this - &lt;blockquote&gt;&lt;span class="scm"&gt;{Statistics (mean 1 2 3)}&lt;/span&gt;&lt;/blockquote&gt;. For that to be possible, &lt;tt&gt;Statistics&lt;/tt&gt; must itself be a macro. Therefore, &lt;tt&gt;module&lt;/tt&gt; must be a macro that generates a macro. Here is a definition for &lt;tt&gt;module&lt;/tt&gt; -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(define module&lt;br /&gt;  (fn 'bindings&lt;br /&gt;    (let ((evaluated-bindings &lt;br /&gt;            (eval (list 'let bindings &lt;br /&gt;                    (list 'map &lt;br /&gt;                          (fn: ((s . _)) &lt;br /&gt;                            (list s (cons 'quote (eval s)))) &lt;br /&gt;                          (cons 'quote bindings))))))&lt;br /&gt;      (fn 'args&lt;br /&gt;        (cons 'let (cons evaluated-bindings args))))))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Now all you have to do to rope in the &lt;tt&gt;Statistics&lt;/tt&gt; definitions in a block of code is to wrap it up in a &lt;tt&gt;{Statistics ...}&lt;/tt&gt; block.&lt;br /&gt;&lt;br /&gt;Suppose we wish to use the module name to resolve the value of a single symbol. It is  potentially expensive to do &lt;tt&gt;({Statistics mean} 1 2 3)&lt;/tt&gt; because the brace expression places a (potentially huge) let block there which gets evaluated every time the whole expression is evaluated. We can make this case more efficient by defining a scope resolution operator like this -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(define :: (fn 'args (cons quote (eval (eval args)))))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Then we can resolve the meaning of &lt;tt&gt;mean&lt;/tt&gt; like this &lt;blockquote&gt;&lt;span class="scm"&gt;({:: Statistics mean} 1 2 3)&lt;/span&gt;&lt;/blockquote&gt;. The resolution will happen once at read time, after which the actual function will be used.&lt;br /&gt;&lt;br /&gt;See &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/examples/modules.scm"&gt;examples/modules.scm&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-829625555621329792?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/829625555621329792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=829625555621329792' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/829625555621329792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/829625555621329792'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/01/simple-module-system-using-macros.html' title='A simple module system using macros'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-8019913359764881230</id><published>2007-01-18T12:57:00.000+08:00</published><updated>2007-01-18T13:15:34.699+08:00</updated><title type='text'>"Processes" branch is now the "trunk".</title><content type='html'>The experimental multi-processing support that was being developed in the &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/branches/processes/"&gt;processes&lt;/a&gt; branch is now merged on to the &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/trunk/"&gt;trunk &lt;/a&gt;(v140). That is, its official! I've been waiting for this for a long time now. Apart from various bug fixes and other process related stuff already described, here's whats new -&lt;br /&gt;&lt;ol&gt;&lt;li&gt;New primitives &lt;span class="scm"&gt;post&lt;/span&gt; and &lt;span class="scm"&gt;process?&lt;/span&gt;.&lt;/li&gt;&lt;li&gt;New s-expr syntax and functions to work with raw byte data.&lt;/li&gt;&lt;li&gt;MAJOR code change to make muSE truly embeddable. This change breaks API compatibility. The new API calls all take the environment pointer as their first arguments so that multiple muSE environments can coexist in the same OS process or thread without interfering with each other.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-8019913359764881230?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/8019913359764881230/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=8019913359764881230' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8019913359764881230'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8019913359764881230'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/01/processes-branch-is-now-trunk.html' title='&quot;Processes&quot; branch is now the &quot;trunk&quot;.'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-3070265241468557319</id><published>2007-01-10T10:27:00.000+08:00</published><updated>2007-04-12T13:40:59.741+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Language'/><title type='text'>Specifying function arguments using key-value pairs</title><content type='html'>Since v129 in the &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/branches/processes/"&gt;processes branch&lt;/a&gt;, two new primitives &lt;span class="scm"&gt;call/keywords&lt;/span&gt; and &lt;span class="scm"&gt;apply/keywords&lt;/span&gt; have been added to let function argument be specified in an order that's different from the declaration order. These primitives do not change the evaluation complexity of functions at all, but simply expose a function's declared arguments as "keywords". &lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(call/keywords f 'key1 val1 'key2 val2 ...)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Evaluates the given function by explicitly binding each named argument to the given value. Can also be used on macros, in which case the value positions are used without being evaluated. This is the counterpart of the normal position based evaluation.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(apply/keywords f alist)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;If you store a set of argument bindings in an alist, you can apply a function to those bindings using &lt;tt&gt;apply/keywords&lt;/tt&gt;. This is the counterpart of the position-based &lt;span class="scm"&gt;apply&lt;/span&gt;.&lt;/dd&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;Any arguments that don't feature in the supplied key-value pairs take on their current value in the environment. This lets you specify common arguments using just a &lt;tt&gt;let&lt;/tt&gt; binding or a global &lt;tt&gt;define&lt;/tt&gt;. Such common arguments are therefore said to be implemented via a limited form of dynamic scoping.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-3070265241468557319?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/3070265241468557319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=3070265241468557319' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/3070265241468557319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/3070265241468557319'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2007/01/new-support-for-keyword-arguments.html' title='Specifying function arguments using key-value pairs'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-5553179473303028939</id><published>2006-12-27T11:37:00.000+08:00</published><updated>2006-12-27T14:11:32.032+08:00</updated><title type='text'>Creating stand-alone executables</title><content type='html'>&lt;!-- Converted from text/plain format --&gt; &lt;P&gt;&lt;FONT size=2&gt;The muSE interpreter binary can now create extensible stand-alone command  line executables. For details, check out the wiki page &lt;A  href="http://code.google.com/p/muvee-symbolic-expressions/wiki/StandAloneExecutables"&gt;StandAloneExecutables&lt;/A&gt;.&lt;/FONT&gt; &lt;/P&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-5553179473303028939?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/5553179473303028939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=5553179473303028939' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5553179473303028939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5553179473303028939'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/12/creating-stand-alone-executables.html' title='Creating stand-alone executables'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-612200511680792013</id><published>2006-12-25T08:49:00.000+08:00</published><updated>2006-12-25T23:44:28.392+08:00</updated><title type='text'>Simple run-time type checking in muSE</title><content type='html'>The &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/11/static-guarded-patterns.html"&gt;guarded patterns&lt;/a&gt; facility can be used to implement a simple type checking facility that can be turned on and off with a global setting. Some functions useful in this situation are defined in &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/examples/rtts1.scm"&gt;examples/rtts1.scm&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;muSE has some built-in functions to check types - &lt;span class="scm"&gt;int?&lt;/span&gt;, &lt;span class="scm"&gt;float?&lt;/span&gt;, &lt;span class="scm"&gt;cons?&lt;/span&gt;, &lt;span class="scm"&gt;vector?&lt;/span&gt;, &lt;span class="scm"&gt;hashtable?&lt;/span&gt;, &lt;span class="scm"&gt;text?&lt;/span&gt; and &lt;span class="scm"&gt;symbol?&lt;/span&gt;. The common characteristic of these predicates is to evaluate to their argument if it satisfies the predicate and to &lt;span class="scm"&gt;()&lt;/span&gt; if it doesn't. &lt;br /&gt;&lt;br /&gt;If you take a type to be defined by a predicate - the class of objects being all objects that satisfy the predicate - the above predicates together with the combinators &lt;span class="scm"&gt;?or&lt;/span&gt;, &lt;span class="scm"&gt;?and&lt;/span&gt;, &lt;span class="scm"&gt;?not&lt;/span&gt; and &lt;span class="scm"&gt;?list-of&lt;/span&gt; defined in &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/examples/rtts1.scm"&gt;examples/rtts1.scm&lt;/a&gt; can express a broad set of types. &lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Note:&lt;/b&gt; The type checks are all performed at function invocation time. This can be quite a drag on performance. So the definition of &lt;span class="scm"&gt;decltype&lt;/span&gt; in the rtts1.scm file is such that the checks can be turned off by setting the &lt;span class="scm"&gt;*enable-rtts*&lt;/span&gt; to &lt;span class="scm"&gt;()&lt;/span&gt; at the start of the file.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Here's an example (note the use of braces &lt;tt&gt;{}&lt;/tt&gt; around the &lt;tt&gt;decltype&lt;/tt&gt; expressions) -&lt;pre&gt;&lt;span class="scm"&gt;&lt;br /&gt;(define number? (?or int? float?)) ; From rtts1.scm&lt;br /&gt;&lt;br /&gt;(define max&lt;br /&gt;  (fn ({decltype n1 number?}&lt;br /&gt;       {decltype n2 number?})&lt;br /&gt;      (if (&gt; n1 n2) n2 n1)))&lt;br /&gt;&lt;br /&gt;(define multi-max&lt;br /&gt;  (fn ({decltype n1 number?} . {decltype ns (?list-of number?)})&lt;br /&gt;      (reduce max n1 ns)))&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;With type checking enabled, &lt;tt&gt;multi-max&lt;/tt&gt; will only be usable with numeric arguments and you have to give it at least one argument.&lt;br /&gt;&lt;br /&gt;If you disable type checking, then the above definitions become as though you'd typed -&lt;pre&gt;&lt;span class="scm"&gt;&lt;br /&gt;(define max&lt;br /&gt;  (fn (n1 n2)&lt;br /&gt;      (if (&gt; n1 n2) n2 n1)))&lt;br /&gt;&lt;br /&gt;(define multi-max&lt;br /&gt;  (fn (n1 . ns)&lt;br /&gt;      (reduce max n1 ns)))&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-612200511680792013?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/612200511680792013/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=612200511680792013' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/612200511680792013'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/612200511680792013'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/12/simple-run-time-type-checking-in-muse.html' title='Simple run-time type checking in muSE'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-2758299350992382199</id><published>2006-12-17T16:35:00.000+08:00</published><updated>2006-12-17T16:41:52.688+08:00</updated><title type='text'>Google code adds Wiki ...</title><content type='html'>I've been blogging about aspects of muSE on this site, but am feeling uncomfortable with the organization that's turning out. When I visited the google code pages a few moments ago, I saw that a new  &lt;a href="http://code.google.com/p/muvee-symbolic-expressions/w/list"&gt;Wiki&lt;/a&gt; tab has been added. That's the right tool to put in the kind of documentation I've been placing online using the blog and I'll be exploring moving the documentation that needs to be organized over to the wiki and leaving all the "latest scoop", "how to" and "things to do" kind of posts to the blog.&lt;br /&gt;&lt;br /&gt;I could've created a separate web site ... ok just call me a lazy one.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-2758299350992382199?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/2758299350992382199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=2758299350992382199' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/2758299350992382199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/2758299350992382199'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/12/google-code-adds-wiki.html' title='Google code adds Wiki ...'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-84260148805372769</id><published>2006-12-14T00:27:00.000+08:00</published><updated>2006-12-14T00:28:19.028+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Processes'/><title type='text'>Continuations and processes</title><content type='html'>The &lt;span class="scm"&gt;call/cc&lt;/span&gt; implementation has been revamped to make continuations work only within the processes in which they were captured. This is because none of the alternatives to supporting inter-process continuation invocation seemed clean enough or necessary. &lt;br /&gt;&lt;br /&gt;What should happen when a process invokes a continuation that was captured by another process? Should it terminate the current process and join with the process to which the continuation belongs? If that's the case, what about the continuations that were captured in the invoking process? Should they be rendered invalid? Would this whole spaghetti be useful or meaningful?&lt;br /&gt;&lt;br /&gt;An alternative is to have the continuation invocation finish evaluation in the invoking process and return with a value like nil or T. Doing that, however, means different behaviour when invoking a continuation in the same process it was captured in versus invoking a continuation captured in a different process. In the former case the invocation never completes evaluation whereas in the latter case it does.&lt;br /&gt;&lt;br /&gt;Due of all of that, I've disabled invocation of continuations across process boundaries. Any possible use for that can be satisfied by the message passing mechanism (I think), which is simpler and more comprehensible anyway.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-84260148805372769?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/84260148805372769/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=84260148805372769' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/84260148805372769'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/84260148805372769'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/12/continuations-and-processes.html' title='Continuations and processes'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-4363844792085847029</id><published>2006-12-13T15:36:00.000+08:00</published><updated>2006-12-15T23:48:13.462+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Processes'/><title type='text'>Erlang style processes in muSE</title><content type='html'>muSE now has an implementation of co-operative message passing processes in the same spirit as &lt;a href="http://www.erlang.org/"&gt;Erlang&lt;/a&gt;. The source code canbe obtained from the &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/branches/processes/"&gt;processes branch&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;muSE processes provide an abstraction that let you think of your program as concurrently acting entities without worrying about the actual order in which the operations are actually being performed by the processor. Evaluation of muSE expressions may be pre-empted at graph reduction boundaries to pay some attention to other processes. Switching between processes is fairly efficient (close to &lt;tt&gt;setjmp + longjmp&lt;/tt&gt; in C) and it is even possible to run 10000 processes without bringing down your machine to its knees, granted that each process will run pretty slowly on the average in that case though.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Spawning processes&lt;/h4&gt;&lt;span class="scm"&gt;(spawn thunk [attention])&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Spawns off the given thunk (a function that takes no parameters) into a separate process. The thunk is evaluated in a loop, until it returns a non-nil value. Once the thunk returns with a non-nil value, the process dies. This is thunk's way of saying "I'm done." The (optional) second argument to &lt;tt&gt;spawn&lt;/tt&gt; is an attention value that tells the muSE scheduler how much attention it should give to the created process before switching to another. The default value is 10. Play around until you find something that suits you. The processes are all scheduled in a simple round-robin manner for now.&lt;br /&gt;&lt;br /&gt;The &lt;tt&gt;spawn&lt;/tt&gt; expression itself evaluates to the process-id of the created process. The process id is not a number as is usual in most systems, but is actually a native-closure. The only two uses for the pid are to compare two pids for equality and to pass messages to the process it identifies.&lt;br /&gt;&lt;br /&gt;To pass a message, simply use the process ID like a normal function. Its entire argument list will be placed as a single message in the process's message queue.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Pausing a process&lt;/h4&gt;&lt;span class="scm"&gt;(run [timeout-microseconds])&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Pauses a process for the given timeout period, yielding time to other processes. If the timeout is omitted, the process is suspended for ever.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Receiving messages in a process&lt;/h4&gt;&lt;span class="scm"&gt;(receive ...)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Retrieves the next message in the process's mailbox. The message has the format &lt;blockquote&gt;&lt;span class="scm"&gt;(pid . values)&lt;/span&gt;&lt;/blockquote&gt;where &lt;tt&gt;pid&lt;/tt&gt; is the id of the process that sent the message and &lt;tt&gt;values&lt;/tt&gt; is the list of arguments that it supplied to the message sending operation.&lt;br /&gt;&lt;br /&gt;The result of a &lt;span class="scm"&gt;(receive...)&lt;/span&gt; expression is designed to be used with muSE's &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/09/pattern-matching-bind.html"&gt;pattern-matching &lt;tt&gt;case&lt;/tt&gt; construct&lt;/a&gt; as follows - &lt;blockquote&gt;&lt;pre&gt;&lt;span class="scm"&gt;&lt;br /&gt;(case (receive)&lt;br /&gt;   ((pid ...msg-pattern-1...) action-1)&lt;br /&gt;   ((pid ...msg-pattern-2...) action-2)&lt;br /&gt;   ...)&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;The &lt;tt&gt;receive&lt;/tt&gt; primitive has four forms -&lt;br /&gt;&lt;dl&gt;&lt;dt&gt;&lt;span class="scm"&gt;(receive)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;Pauses the process until a message is available in the process's mailbox and evaluates to the message. This will always evaluate to a valid message.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(receive timeout-microseconds)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;Pauses the process for at most &lt;tt&gt;timeout-microseconds&lt;/tt&gt;. If there is mo message in the process's mailbox for more than &lt;tt&gt;timeout-microseconds&lt;/tt&gt;, it evaluates to &lt;span class="scm"&gt;()&lt;/span&gt; which is muSE's false value.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(receive pid)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;Waits for and retrieves the next message from the process with the given &lt;tt&gt;pid&lt;/tt&gt;.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(receive pid timeout-microseconds)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;Similar to the previous one, but times out with a &lt;span class="scm"&gt;()&lt;/span&gt; value after &lt;tt&gt;timeout-microseconds&lt;/tt&gt;.&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;h4&gt;Controlling concurrency&lt;/h4&gt;&lt;span class="scm"&gt;(atomic ...expressions...)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;From the point of view of a single process, &lt;tt&gt;atomic&lt;/tt&gt; works exactly like &lt;tt&gt;do&lt;/tt&gt; - evaluating all the expression in turn and itself evaluating to the value of the last expression in the series. From the point of view of the cluster of running processes, it does not yield any time to any other process until all its expressions are evaluated.&lt;br /&gt;&lt;br /&gt;&lt;tt&gt;atomic&lt;/tt&gt; expressions may be nested to arbitrary depths. You can forcibly yield to other processes however, if you use any of the pausing functions &lt;tt&gt;receive&lt;/tt&gt; and &lt;tt&gt;run&lt;/tt&gt;.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Process identity&lt;/h4&gt;&lt;span class="scm"&gt;(this-process)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Evaluates to the pid of the process in which it is evaluated.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Embedding issues&lt;/h4&gt;For muSE, it is important to consider how these processes interact when embedded in a C/C++ based application. The application can make calls to the muSE API to evaluate expressions. These calls are always evaluated in the "main process" using the main application's C stack. Each muSE process has its own C stack and won't interfere with the main C stack. The entry and exit processes for this case will always be the main process. Other processes get a chance to execute only when within a muSE API call and therefore will not interfere with the application's execution when not running muSE code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-4363844792085847029?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/4363844792085847029/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=4363844792085847029' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4363844792085847029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4363844792085847029'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/12/erlang-style-processes-in-muse.html' title='Erlang style processes in muSE'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-5439223744629447809</id><published>2006-12-13T07:44:00.000+08:00</published><updated>2006-12-14T09:56:40.397+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exceptions'/><title type='text'>Exception mechanism</title><content type='html'>muSE had so far lacked the facility to raise exception conditions and handle them in code that's specified non-locally. One could conceivably use the &lt;tt&gt;call/cc&lt;/tt&gt; construct to implement raising exceptions, but capturing a continuation to evaluate an expression that often won't invoke the continuation turns out to be expensive in terms of memory - capturing a continuation copies the stack in muSE.&lt;br /&gt;As of &lt;b&gt;version 73&lt;/b&gt; in the &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/branches/processes/"&gt;processes branch&lt;/a&gt;, a simple exception raising and handling mechanism has been added to muSE. There are two new primitives involved -&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;&lt;span class="scm"&gt;(raise ...args...)&lt;/span&gt;&lt;/h4&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;raise&lt;/tt&gt; primitive is used to flag an exceptional condition and results in all the established handlers being tried one by one until one of them can be found to handle the condition. A handler (which is a function) is taken to accept an exception for handling if its argument pattern matches the pattern of arguments to the &lt;tt&gt;raise&lt;/tt&gt; expression that raised the exception.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;&lt;span class="scm"&gt;(try expr handler1 handler2...)&lt;/span&gt;&lt;/h4&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;try&lt;/tt&gt; block wraps the &lt;tt&gt;expr&lt;/tt&gt; with handlers that get tried when any sub-expression of &lt;tt&gt;expr&lt;/tt&gt; raises an exception.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Any muSE object can be used in the place of a handler. If the object is a function, then its arguments have to pattern match against the exception raised in order for its body to be evaluated as the result of its &lt;tt&gt;try&lt;/tt&gt; block. If the object is not a function, its value is used as the result of the &lt;tt&gt;try&lt;/tt&gt; expression as is. For example -&lt;pre&gt;&lt;span class="scm"&gt;&lt;br /&gt;(try (if (&lt; a b) &lt;br /&gt;         (- b a)&lt;br /&gt;         (raise 'NotInOrder a b))&lt;br /&gt;   0)&lt;/span&gt;&lt;/pre&gt;will evaluate too &lt;tt&gt;0&lt;/tt&gt; if &lt;tt&gt;a &gt;= b&lt;/tt&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;A function used as a handler needs to have its arguments in a special order -&lt;br /&gt;&lt;ol&gt;&lt;li&gt;The first argument to the handler is an exception object.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The remaining arguments are the same list of values passed to the &lt;tt&gt;raise&lt;/tt&gt; expression that raised the exception.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;For example -&lt;blockquote&gt;&lt;span class="scm"&gt;(fn (ex 'NotInOrder x y) ...)&lt;/span&gt;&lt;/blockquote&gt;can be the signature of a handler that handles the &lt;span class="scm"&gt;'NotInOrder&lt;/span&gt; exception raised by the previous example. The &lt;tt&gt;ex&lt;/tt&gt; argument's sole purpose is to let you resume the computation from the &lt;tt&gt;raise&lt;/tt&gt; expression with a new valid value as the result of the &lt;tt&gt;raise&lt;/tt&gt;. The &lt;tt&gt;ex&lt;/tt&gt; object is actually a (cheaper than call/cc) continuation that you can invoke with a single argument that will resume the computation in such a manner. To expand on the previous example, &lt;/p&gt;&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(try &lt;br /&gt;  (do (write "Difference = "&lt;br /&gt;             (if (&lt; a b)&lt;br /&gt;                 (- b a)&lt;br /&gt;                 (raise 'NotInOrder a b)))&lt;br /&gt;      (write "Product = " (* a b)))&lt;br /&gt;      &lt;br /&gt;  (fn (ex 'NotInOrder x y)&lt;br /&gt;      (ex (- x y))))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;In the above form, the exception condition is corrected by reversing the arguments of the subtraction operation. If the handler did not invoke the exception object to resume the computation, its result value is used as the result value of the &lt;tt&gt;try&lt;/tt&gt; block. Trivial example, yes, but serves to illustrate the point.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-5439223744629447809?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/5439223744629447809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=5439223744629447809' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5439223744629447809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5439223744629447809'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/12/exception-mechanism.html' title='Exception mechanism'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-5983030414873503539</id><published>2006-12-12T10:36:00.000+08:00</published><updated>2006-12-14T00:32:45.798+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Processes'/><title type='text'>Processes branch</title><content type='html'>The &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/branches/processes/"&gt;processes branch&lt;/a&gt; of muSE has now reached a fair degree of completeness. This post documents the facilities available as of &lt;b&gt;version 82&lt;/b&gt;, whose snapshot is available in the tag &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/tags/processes/v0.2cp/"&gt;v0.2cp&lt;/a&gt;. I intend to make the processes branch the main trunk when the functionality is a bit more tested.&lt;br /&gt;&lt;br /&gt;The processes branch implements a few significant features over and above the standard muSE engine on the trunk -&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/12/erlang-style-processes-in-muse.html"&gt;Processes&lt;/a&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;A simple implementation of &lt;a href="http://www.erlang.org/"&gt;Erlang&lt;/a&gt; style message passing processes in order to express concurrent computations. Primitives added are &lt;span class="scm"&gt;spawn&lt;/span&gt;, &lt;span class="scm"&gt;receive&lt;/span&gt;, &lt;span class="scm"&gt;atomic&lt;/span&gt; and &lt;span class="scm"&gt;run&lt;/span&gt;.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/12/continuations-and-processes.html"&gt;Process-local continuations&lt;/a&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Continuation support modified to work within a process. Continuation invocation across process boundaries is forbidden. No new primitives.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;Process-aware networking&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;muSE had some simple s-expr based communication functions all along. This branch now has these functions process aware - i.e. reading from a network port will not stall processes. A polling mechanism (which is invisble at the scheme-level) is used to handle all connections.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/12/exception-mechanism.html"&gt;Resumable exception mechanism&lt;/a&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;New primitives &lt;span class="scm"&gt;try&lt;/span&gt; and &lt;span class="scm"&gt;raise&lt;/span&gt; provide the means to raise, handle and resume exceptional conditions. This is something muSE had been lacking all along and was badly needed.&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;&lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/11/static-guarded-patterns.html"&gt;Static guarded patterns&lt;/a&gt; (minor)&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;&lt;/dd&gt;&lt;br /&gt;&lt;/dl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-5983030414873503539?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/5983030414873503539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=5983030414873503539' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5983030414873503539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5983030414873503539'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/12/processes.html' title='Processes branch'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-8775467714536641765</id><published>2006-11-26T17:26:00.000+08:00</published><updated>2007-04-12T13:43:20.199+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Language'/><title type='text'>Static guarded patterns</title><content type='html'>muSE makes use of &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/09/pattern-matching-bind.html"&gt;pattern matching binding&lt;/a&gt; in its &lt;span class="scm"&gt;let&lt;/span&gt;, &lt;span class="scm"&gt;case&lt;/span&gt; and &lt;span class="scm"&gt;fn&lt;/span&gt; constructs. These patterns can destructure lists and test for equality against numbers, symbols and any quoted constants. In several situations, it is desirable to make the binding operation succeed only if the pattern satisfies a more complex condition that can be expressed only in code. &lt;br /&gt;&lt;br /&gt;With &lt;b&gt;revision 36&lt;/b&gt; of &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/trunk/"&gt;muSE trunk&lt;/a&gt;, support for &lt;em&gt;static guarded patterns&lt;/em&gt; have been added, which allows you to specify conditions that a pattern must satisfy in order for the binding operation to succeed.&lt;br /&gt;&lt;br /&gt;In any language with pattern matching binding, a &lt;em&gt;guard&lt;/em&gt; typically has two components - 1) a pattern to match and bind and 2) a condition that the bound variables must satisfy additionally, for the binding operation to be considered to be successful. A fairly straight forward  s-expression form of a guard therefore is &lt;blockquote&gt;&lt;span class="scm"&gt;(guard PATTERN TEST-BODY)&lt;/span&gt;&lt;/blockquote&gt; where the &lt;span class="scm"&gt;PATTERN&lt;/span&gt; introduces variables and the &lt;span class="scm"&gt;TEST-BODY&lt;/span&gt; makes use of the introduced variables in an expression that evaluates to a boolean value (in muSE, &lt;span class="scm"&gt;()&lt;/span&gt; is 'false' and anything else is 'true').&lt;br /&gt;&lt;br /&gt;We can exploit the fact that the above guard form is structurally and semantically identical to a predicate expressed as a closure and reuse that mechanism to add support for guards in patterns. There is, therefore, no need to introduce another special symbol &lt;span class="scm"&gt;guard&lt;/span&gt;. &lt;br /&gt;&lt;br /&gt;Hence, you can place guards wherever a pattern is expected - in &lt;span class="scm"&gt;let&lt;/span&gt;, arguments to &lt;span class="scm"&gt;fn&lt;/span&gt; itself and, most importantly, the &lt;span class="scm"&gt;case&lt;/span&gt; expression. The current implementation of guards does not allow the guard body to refer to the lexical context. It can only refer to the global context and that's why the guard mechanism is called &lt;b&gt;static&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;If you use an &lt;span class="scm"&gt;fn&lt;/span&gt; expression directly in a pattern, like &lt;blockquote&gt;&lt;span class="scm"&gt;(a b (fn (c d) (&lt; c d)))&lt;/span&gt;&lt;/blockquote&gt; against a value &lt;span class="scm"&gt;'(1 2 (3 4))&lt;/span&gt;, it is not possible to tell whether you intended the third element of the list to be decomposed into 3 elements, binding the first to the symbol &lt;span class="scm"&gt;fn&lt;/span&gt; or you intended for the &lt;span class="scm"&gt;fn&lt;/span&gt; expression to be used as a guard. To resolve this ambiguity, we call upon muSE's &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/09/read-time-evaluation-in-muse.html"&gt;read-time expression evaluation&lt;/a&gt; to really place a predicate object at the third position - like this - &lt;blockquote&gt;&lt;span class="scm"&gt;(a b {fn (c d) (&lt; c d)})&lt;/span&gt;&lt;/blockquote&gt;. Now, the pattern matcher actually sees a function object in the third position and knows to treat it as a guarded pattern. This pattern will bind 4 variables &lt;span class="scm"&gt;a&lt;/span&gt;, &lt;span class="scm"&gt;b&lt;/span&gt;, &lt;span class="scm"&gt;c&lt;/span&gt; and &lt;span class="scm"&gt;d&lt;/span&gt; if it succeeds.&lt;br /&gt;&lt;br /&gt;There is limited support for &lt;em&gt;dynamic&lt;/em&gt; guards in patterns. You can use muSE's dynamic scoping mechanism &lt;span class="scm"&gt;fn:&lt;/span&gt; instead of &lt;span class="scm"&gt;fn&lt;/span&gt; in cases where you need the guard body to refer to variables in the immediately enclosing lexical closure.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-8775467714536641765?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/8775467714536641765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=8775467714536641765' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8775467714536641765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8775467714536641765'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/11/static-guarded-patterns.html' title='Static guarded patterns'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-7085278313542210774</id><published>2006-11-08T06:43:00.000+08:00</published><updated>2006-11-08T07:11:28.867+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='API'/><title type='text'>Multiple muSE instances</title><content type='html'>When embedding muSE into an existing C/C++ program, there are a few ground rules for creating and using &lt;em&gt;muSE environments&lt;/em&gt; a.k.a. &lt;em&gt;execution contexts&lt;/em&gt;.&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;You are allowed to create multiple muSE environments in a single process.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;You have to limit all expression evaluation to a single thread of execution.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;You can switch between different environments using the &lt;span class="scm"&gt;muse_set_current_env()&lt;/span&gt; API call. If you don't the last created environment will be the &lt;em&gt;current environment&lt;/em&gt; for evaluating expressions.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;If you statically link muSE into a shared module (.dll/.so), each shared module gets its own &lt;em&gt;current environment&lt;/em&gt; state and will not interfere with other shared libraries.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;In the future, the &lt;em&gt;current environment&lt;/em&gt; state may become thread-local, in which case you'll be able to use different environments simultaneously in different threads. Still, a single environment will be allowed to be the &lt;em&gt;current environment&lt;/em&gt; of only one thread at a time. Note that the API won't need to change to support this behaviour extension.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-7085278313542210774?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/7085278313542210774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=7085278313542210774' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7085278313542210774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7085278313542210774'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/11/multiple-muse-instances.html' title='Multiple muSE instances'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-4901607055180698036</id><published>2006-10-27T09:32:00.000+08:00</published><updated>2006-12-26T14:42:50.630+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data structures'/><title type='text'>Polymorphic higher order functions</title><content type='html'>Its been a while since my last posting. That's because a lot of changes have been happening under the hood. Objects (vectors and hashtables) now have printed representations, higher order functions are now polymorphic - they can be used on lists, vectors and hashtables, the diagnostic messages are now more extensive and several hashtable bugs have been fixed. There is a fairly serious language departure from standard Scheme which doesn't have polymorphic operators, but I chose this for ease of use. Here, I describe what's available as of revision 21 in the svn repository.&lt;br /&gt;&lt;br /&gt;The following operations are now applicable to lists, vectors and hashtables. Wherever you see &lt;span class="scm"&gt;collection&lt;/span&gt;, it means you can use any of those. -&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(map (fn (x) ...) collection)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Creates a structurally similar collection with all the values transformed using the given function. The hashtable keys are not processed.&lt;/dd&gt;&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(join list1 list2 ...)&lt;br/&gt;(join vector1 vector2 ...)&lt;br/&gt;(join hashtable1 hashtable2 ...)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Concatenates all the objects into a single collection. All objects must be of the same type. Lists get concatenated into a single list, vectors get concatenated into a single vector. For hashtables, a union hashtable is created with all the key-value pairs of all the hashtables. &lt;br /&gt;&lt;br /&gt;If two hashtables have the same key, the value for that key will be the value in the hashtable that's later in the argument sequence. You can influence this by supplying an optional reduction function as the first argument to join. The default behaviour is as though the reduction function is &lt;span class="scm"&gt;(fn&amp;nbsp;(v1&amp;nbsp;v2)&amp;nbsp;v2)&lt;/span&gt;.&lt;/dd&gt;&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(length collection)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;You can use the same &lt;span class="scm"&gt;length&lt;/span&gt; function to get the size of any data structure. A synonym &lt;span class="scm"&gt;size&lt;/span&gt; is available as well for clarity.&lt;/dd&gt;&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(find item collection)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Finds the item in the given collection and returns something that you can use to locate the item within the collection, or &lt;span class="scm"&gt;()&lt;/span&gt; if the item cannot be found. In the case of lists, it returns the remainder of the list starting from the object. In the case of vectors, it returns the index of the item. In the case of hashtables, it returns the key for which the given item is the value.&lt;/dd&gt;&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(reduce (fn (acc x) ...) initial collection)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Uses the given reduction function and reduces the given collection of values to a single value. This is the &lt;span class="scm"&gt;foldl&lt;/span&gt; operation that must be familiar to functional programming afficionados. This function only uses the values in the data structures. The keys of a hashtable, for example, are not touched.&lt;/dd&gt;&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(for-each func collection)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Invokes the function for each entry in the data structure. The result value is always &lt;span class="scm"&gt;()&lt;/span&gt;. The function is expected to have the signature -&lt;blockquote&gt;&lt;span class="scm"&gt;(fn&amp;nbsp;(obj)&amp;nbsp;...)&lt;/span&gt;&lt;/blockquote&gt;It is to be noted that the iteration always happens over the value objects. You don't have access to the keys of hashtables or the indices of vectors when using &lt;tt&gt;for-each&lt;/tt&gt;. For a more generalized iteration construct, see &lt;tt&gt;collect&lt;/tt&gt; below. This (new) behaviour is since v120.&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(andmap predicate collection)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Returns &lt;span class="scm"&gt;T&lt;/span&gt; if all elements satisfy the predicate and &lt;span class="scm"&gt;()&lt;/span&gt; if even one doesn't. The signature of the predicate has the same signature constraints as that for &lt;span class="scm"&gt;for-each&lt;/span&gt;.&lt;/dd&gt;&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(ormap predicate collection)&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;Returns &lt;span class="scm"&gt;()&lt;/span&gt; if none of the elements satisfy the predicate. If even one satisfies the predicate, returns a reference into the data structure (like &lt;span class="scm"&gt;find&lt;/span&gt;) using which you can locate the element. The predicate signature constraints are the same as for &lt;span class="scm"&gt;andmap&lt;/span&gt; and &lt;span class="scm"&gt;for-each&lt;/span&gt;. You can use &lt;span class="scm"&gt;ormap&lt;/span&gt; as a generalized version of &lt;span class="scm"&gt;find&lt;/span&gt;.&lt;/dd&gt;&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;span class="scm"&gt;(collect collection predicate mapper [reduction-fn])&lt;/span&gt;&lt;/dt&gt;&lt;br /&gt;&lt;dd&gt;This is an &lt;b&gt;experimental&lt;/b&gt; generalized construct that fuses filtering, mapping and reduction operations into a single loop. The &lt;span class="scm"&gt;predicate&lt;/span&gt; selects elements from the &lt;span class="scm"&gt;collection&lt;/span&gt;, the &lt;span class="scm"&gt;mapper&lt;/span&gt; transforms the elements and the (optional) &lt;span class="scm"&gt;reduction-fn&lt;/span&gt; combines multiple values into a single entry in the result.&lt;br /&gt;&lt;br /&gt;The &lt;span class="scm"&gt;predicate&lt;/span&gt; has to have the signature &lt;span class="scm"&gt;(fn&amp;nbsp;(x)&amp;nbsp;...)&lt;/span&gt; for lists. For vectors, it is expected to have the signature &lt;span class="scm"&gt;(fn&amp;nbsp;(index&amp;nbsp;.&amp;nbsp;value)&amp;nbsp;...)&lt;/span&gt; and for hashtables, it must be &lt;span class="scm"&gt;(fn&amp;nbsp;(key &amp;nbsp;.&amp;nbsp;value)&amp;nbsp;...)&lt;/span&gt;. If you want to run the mapper on every element, you can simply pass &lt;span class="scm"&gt;()&lt;/span&gt; as the predicate - indicating that you don't wish to do the test.&lt;br /&gt;&lt;br /&gt;Once an element passes the predicate test, it is passed to the &lt;span class="scm"&gt;mapper&lt;/span&gt; function. If no mapper function is given, the identity map is assumed and in this case &lt;span class="scm"&gt;collect&lt;/span&gt; behaves like a pure filter. &lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;For lists, the mapper function should have the usual signature &lt;span class="scm"&gt;(fn&amp;nbsp;(x)&amp;nbsp;...)&lt;/span&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;For vectors, the signature is expected to be &lt;span class="scm"&gt;(fn&amp;nbsp;(index&amp;nbsp;.&amp;nbsp;value)&amp;nbsp;...)&lt;/span&gt;. The &lt;span class="scm"&gt;index&lt;/span&gt; will be the filtered index of the value and not the original index in the vector. The mapper function is expected to return a pair of the form &lt;span class="scm"&gt;(result-index&amp;nbsp;.&amp;nbsp;result-value)&lt;/span&gt;. The result is used to determine where in the result vector the &lt;span class="scm"&gt;result-value&lt;/span&gt; should be placed. The result vector is automatically resized to fit the set of returned indices. The (optional) &lt;span class="scm"&gt;reduction-fn&lt;/span&gt; is used to determine how to combine multiple values if more than one value is mapped to the same result index.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;For hashtables, the case is similar to that of vectors, except that instead of index-value pairs, the mapper works with &lt;span class="scm"&gt;(key&amp;nbsp;.&amp;nbsp;value)&lt;/span&gt; pairs and is expected to return a &lt;span class="scm"&gt;(result-key&amp;nbsp;.&amp;nbsp;result-value)&lt;/span&gt; pair. The reduction function is also applied similar to the case of vectors.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/dl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-4901607055180698036?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/4901607055180698036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=4901607055180698036' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4901607055180698036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4901607055180698036'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/10/polymorphic-higher-order-functions.html' title='Polymorphic higher order functions'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-1795625960129071563</id><published>2006-09-19T22:10:00.000+08:00</published><updated>2006-09-19T22:27:10.804+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='macros'/><title type='text'>Object I/O</title><content type='html'>... or &lt;em&gt;Why you don't need to invent a new syntax for every object type in muSE&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;Standard Scheme (RnRS) has special read/write syntax for vectors which goes like this - &lt;span class="scm"&gt;#(1&amp;nbsp;2&amp;nbsp;3&amp;nbsp;4)&lt;/span&gt;, which will print out as &lt;span class="scm"&gt;#4(1&amp;nbsp;2&amp;nbsp;3&amp;nbsp;4)&lt;/span&gt;. muSE doesn't have such special syntax for objects because its syntax for read-time evaluation is general enough to cover vectors, hashtables and (as far as I can see) all new object types that can be added to muSE in the future.&lt;br /&gt;&lt;br /&gt;The idea is dead simple and is based on the &lt;a href="http://muvee-symbolic-expressions.blogspot.com/2006/09/read-time-evaluation-in-muse.html"&gt;read-time evaluation&lt;/a&gt; done by muSE. It is quite likely that you'll have written a function that takes a list of arguments and constructs your object. In the case of vectors, muSE has &lt;span class="scm"&gt;vector&lt;/span&gt; that's used like &lt;span class="scm"&gt;(vector 1 2 3 4)&lt;/span&gt; and in the case of hashtables, it has &lt;span class="scm"&gt;hashtable&lt;/span&gt; that's used like &lt;span class="scm"&gt;(hashtable '((key1 . value1) (key2 . value2)))&lt;/span&gt;. &lt;br /&gt;&lt;br /&gt;Whenever the writer encounters an object, it simply has to write it out in that "constructor" function notation, using &lt;span class="scm"&gt;{}&lt;/span&gt; instead of &lt;span class="scm"&gt;()&lt;/span&gt;. When such an expression is read back in by muSE, the reader will expand the braces and return the constructed object directly. For example -&lt;br /&gt;&lt;span class="scm"&gt;&gt; (define v (vector 1 2 3 4))&lt;br /&gt;&gt; (write v)&lt;br /&gt;{vector 1 2 3 4}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When the reader reads the following expression -&lt;br /&gt;&lt;span class="scm"&gt;(third item {vector 1 2 3 4} is a vector)&lt;/span&gt;&lt;br /&gt;you'll actually get a vector as the third item in the above list.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-1795625960129071563?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/1795625960129071563/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=1795625960129071563' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1795625960129071563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1795625960129071563'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/object-io.html' title='Object I/O'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-7311264463884127224</id><published>2006-09-15T03:57:00.001+08:00</published><updated>2006-09-15T03:57:40.444+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Symbols'/><category scheme='http://www.blogger.com/atom/ns#' term='Data structures'/><title type='text'>Anonymous symbols</title><content type='html'>muSE has a notion of anonymous symbols - symbols which do not have a textual representation - which are useful in situations where you need to keep a set of properties together, and in macros to introduce new variables into the generated expressions. The difference between named and anonymous symbols (apart from the textual representation) is that named symbols persist for the life time of the muSE execution environment whereas anonymous symbols and their property lists are garbage collected when there are no references to them.&lt;br /&gt;&lt;br /&gt;Anonymous symbols are created using &lt;span class="scm"&gt;(new)&lt;/span&gt; . You can use an anonymous symbol as the first argument to the &lt;span class="scm"&gt;get&lt;/span&gt; and &lt;span class="scm"&gt;put&lt;/span&gt; functions to edit its property list.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-7311264463884127224?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/7311264463884127224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=7311264463884127224' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7311264463884127224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/7311264463884127224'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/anonymous-symbols.html' title='Anonymous symbols'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-5539040679773603880</id><published>2006-09-15T03:49:00.001+08:00</published><updated>2006-09-15T03:49:20.345+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Symbols'/><title type='text'>Property lists</title><content type='html'>Every symbol in muSE has an associated property list that  you can query and edit using the &lt;span class="scm"&gt;get&lt;/span&gt; and &lt;span class="scm"&gt;put&lt;/span&gt; functions. For example -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&gt; (put 'kumar 'sister 'hamsa)&lt;br /&gt;(sister . hamsa)&lt;br /&gt;&gt; (get 'kumar 'brother)&lt;br /&gt;()&lt;br /&gt;&gt; (get 'kumar 'sister)&lt;br /&gt;(sister . hamsa)&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;A symbol's property list is globally available and is not changed by local contexts such as &lt;span class="scm"&gt;let&lt;/span&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-5539040679773603880?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/5539040679773603880/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=5539040679773603880' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5539040679773603880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/5539040679773603880'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/property-lists.html' title='Property lists'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-1294941678266836889</id><published>2006-09-15T03:37:00.001+08:00</published><updated>2006-09-15T03:37:39.239+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Symbols'/><title type='text'>Symbols and values</title><content type='html'>In muSE, as in all Schemes I guess, named symbols are entities that are uniquely specified by their textual representation - i.e. two symbols with the same name refer to the same internal object, irrespective of context. In muSE, all named symbols are "interned" forever - i.e. they are automatically kept alive for the life of the running environment.&lt;br /&gt;&lt;br /&gt;You can bind values to symbols either using the &lt;span class="scm"&gt;define&lt;/span&gt; syntax or using the &lt;span class="scm"&gt;set!&lt;/span&gt; function. There is very little difference between &lt;span class="scm"&gt;define&lt;/span&gt; and &lt;span class="scm"&gt;set!&lt;/span&gt;. They can both assign values to symbols at the lexically top-level, but only &lt;span class="scm"&gt;define&lt;/span&gt; can be used to specify recursive functions. muSE's &lt;span class="scm"&gt;define&lt;/span&gt; syntax is more restrictive than R5RS Scheme in that you can define functions only like this -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(define f (fn (...args..) ...body...))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;whereas in standard Scheme you'd define it like this -&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;(define (f ...args...) ...body...)&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It is not an error to define the value of a symbol more than once using &lt;span class="scm"&gt;define&lt;/span&gt;, but it will complain because it is a common source of programming error that indicates that an incorrect assumption is probably being made. &lt;span class="scm"&gt;set!&lt;/span&gt; will not complain, of course, as the intention is clear.&lt;br /&gt;&lt;br /&gt;You can get the string name of a symbol using &lt;span class="scm"&gt;(name sym)&lt;/span&gt; and you can intern a symbol given its string representation using &lt;span class="scm"&gt;(symbol&amp;nbsp;"name")&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Differences with standard Scheme&lt;/b&gt;&lt;br /&gt;In &lt;a href="http://www.plt-scheme.org/software/mzscheme/"&gt;MzScheme&lt;/a&gt; (for example), symbols introduced by &lt;span class="scm"&gt;define&lt;/span&gt; are not closed over when creating functions using &lt;span class="scm"&gt;lambda&lt;/span&gt;. Changing the definition of such a top-level symbol will change the behaviour of the function created using &lt;span class="scm"&gt;lambda&lt;/span&gt;. In muSE, however, &lt;span class="scm"&gt;fn&lt;/span&gt; captures the values of symbols at the time it is being created, including all top-level definitions. &lt;span class="scm"&gt;fn:&lt;/span&gt;, on the other hand, allows its behaviour to be changed after its definition ... even in a local context such as that introduced by &lt;span class="scm"&gt;let&lt;/span&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-1294941678266836889?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/1294941678266836889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=1294941678266836889' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1294941678266836889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1294941678266836889'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/symbols-and-values.html' title='Symbols and values'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-847976882967242207</id><published>2006-09-12T13:52:00.000+08:00</published><updated>2006-09-12T14:01:01.314+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data structures'/><title type='text'>Hashtables are functions</title><content type='html'>In the same spirit as vectors, hashtables can be thought of as functions that map keys to values. muSE hashtables are presented exactly like that and don't need special accessor functions.&lt;br /&gt;&lt;span class="scm"&gt;&lt;pre&gt;&lt;br /&gt;&gt; (define rgb (mk-hashtable))&lt;br /&gt;&gt; (rgb 'red 255)&lt;br /&gt;&gt; (rgb 'green 255)&lt;br /&gt;&gt; (rgb 'blue 255)&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;If you load the above definitions, you can get an alist from the hash table using -&lt;br /&gt;&lt;span class="scm"&gt;&gt; (hashtable-&gt;alist rgb)&lt;/span&gt;&lt;br /&gt;which will give&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;tt&gt;((red . 255) (green . 255) (blue . 255))&lt;/tt&gt;&lt;/span&gt;&lt;br /&gt;(The order is unspecified, though.)&lt;br /&gt;&lt;br /&gt;You can retrieve the green component using &lt;span style="color: orange"&gt;&lt;tt&gt;(rgb 'green)&lt;/tt&gt;&lt;/span&gt;. If you supply a key that is not present in the hashtable, the function will return &lt;tt&gt;()&lt;/tt&gt;. In muSE therefore, it is not possible to distinguish between a key with a value that is &lt;tt&gt;()&lt;/tt&gt; and a key that is not present in the hashtable. This fact is used to remove a key from the hashtable if you pass &lt;tt&gt;()&lt;/tt&gt; as the value argument. For example -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;&gt; (rgb 'green ())&lt;br /&gt;&gt; (hashtable-&gt;alist rgb)&lt;br /&gt;((red . 255) (blue . 255))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;This is not really a restriction and you can use a hashtable as a set by setting the value to any non-NIL value.&lt;br /&gt;&lt;br /&gt;Hashtables accept integers, strings and symbols as keys. Therefore, you can use a hashtable like a sparse vector if need be, since they both have the same invocation interface.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-847976882967242207?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/847976882967242207/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=847976882967242207' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/847976882967242207'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/847976882967242207'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/hashtables-in-muse.html' title='Hashtables are functions'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-8682727488874481547</id><published>2006-09-12T13:40:00.000+08:00</published><updated>2006-09-12T13:52:12.213+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data structures'/><title type='text'>Vectors are functions</title><content type='html'>A vector is, conceptually, a function from an index to an object and in muSE, a vector is exactly that - a normal function. Here's an example -&lt;br /&gt;&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;tt&gt;(define rgb (mk-vector 3))&lt;/tt&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now &lt;tt&gt;rgb&lt;/tt&gt; is a 3-element vector, with all the slots set to &lt;tt&gt;()&lt;/tt&gt;. Here's how to set the three color components -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;(rgb 0 255) ; Red&lt;br /&gt;(rgb 1 255) ; Green&lt;br /&gt;(rgb 2 255) ; Blue&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;To get the green component, for example, you use &lt;tt&gt;(rgb 1)&lt;/tt&gt;. If you pass an index out of range, you always get &lt;tt&gt;()&lt;/tt&gt;.&lt;br /&gt;&lt;br /&gt;You can create a vector from data using the &lt;span style="font-family:courier new;"&gt;vector &lt;/span&gt;function like this -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;tt&gt;(vector 255 255 255)&lt;/tt&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Other vector manipulation functions are more or less the same as standard Scheme - such as &lt;tt&gt;vector-length&lt;/tt&gt;, &lt;tt&gt;list-&gt;vector&lt;/tt&gt; and &lt;tt&gt;vector-&gt;list&lt;/tt&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-8682727488874481547?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/8682727488874481547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=8682727488874481547' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8682727488874481547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/8682727488874481547'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/vectors-and-hashtables-in-muse.html' title='Vectors are functions'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-4178946293727801215</id><published>2006-09-12T10:26:00.000+08:00</published><updated>2006-09-12T10:53:07.893+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='macros'/><title type='text'>"Backquote" syntax</title><content type='html'>muSE does not support the Scheme/Lisp backquote notation in its reader. This is primarily because I was lazy, but later on I realized that it is simple to implement something like it using muSE's macro facility. Here's the definition -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;(define literal &lt;br /&gt;  (fn 'args&lt;br /&gt;    (case args&lt;br /&gt;      (() &lt;br /&gt;       ())&lt;br /&gt;      ((('unlit expr) . etc) &lt;br /&gt;       (list 'cons expr (apply literal etc)))&lt;br /&gt;      ((('unlit-splice expr) . etc) &lt;br /&gt;       (list 'append! expr (apply literal etc)))&lt;br /&gt;      ((x . etc) &lt;br /&gt;       (list 'cons (cons quote x) (apply literal etc))))))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;For example -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;(literal 1 2 (+ 1 2)&lt;br /&gt;          (unlit (+ 2 2))&lt;br /&gt;          (unlit-splice (map (fn (x) (* x x)) '(5 6 7)))&lt;br /&gt;          8 9 10)&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;will get you the literal expression -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;tt&gt;(1 2 (+ 1 2) 4 25 36 49 8 9 10)&lt;/tt&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This works mostly well enough to write macros using it, except when you want to use a macro-like expression within the literal, in which case the result of the macro expansion will be used instead of the literal macro term. This is due to the tail-first expansion performed by muSE.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-4178946293727801215?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/4178946293727801215/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=4178946293727801215' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4178946293727801215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/4178946293727801215'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/backquote-syntax-and-muse-muse-does-not.html' title='&quot;Backquote&quot; syntax'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-319872713305840612</id><published>2006-09-12T07:01:00.000+08:00</published><updated>2006-09-12T07:28:41.177+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='macros'/><title type='text'>Read-time evaluation &amp; first class macros</title><content type='html'>muSE has a simple approach to evaluate certain expression at read-time - you enclose the expression in braces &lt;span style="font-family:courier new;"&gt;{}&lt;/span&gt; instead of parentheses &lt;span style="font-family:courier new;"&gt;()&lt;/span&gt;. If you have untrusted input sources, the &lt;a href="http://homepage.mac.com/srikumarks/.Public/muSE-html-doc-0.1a.zip"&gt;muSE API&lt;/a&gt; lets you turn off read-time evaluation. You can use read-time evaluation to precompute subexpressions that won't change during execution.&lt;br /&gt;&lt;br /&gt;Apart from the braces approach, muSE provides a way to specify functions which take in their syntactic arguments - i.e. their unevaluated arguments and can return code in the form of another expression that is evaluated instead. These are called &lt;span style="font-weight: bold;"&gt;macros&lt;/span&gt; - just as in Scheme. A macro is specified in muSE using the &lt;span style="font-family:courier new;"&gt;fn&lt;/span&gt; expression that's used for normal functions, but the entire argument list should be quoted. Here's an example macro that evaluates a three-term infix expression -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;(define infix3&lt;br /&gt; (fn '(x op y)&lt;br /&gt;   (list op x y)))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Macro calls may be enclosed in braces or parentheses - both are accepted. So the following uses &lt;span style="font-family:courier new;"&gt;infix3&lt;/span&gt; in the expected way -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;&gt; (infix3 2 + 3)&lt;br /&gt;5&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Macro symbols are recognized at the head of a parenthesized list, but not anywhere else. So you can get the expression that the &lt;span style="font-family:courier new;"&gt;infix3&lt;/span&gt; macro computes by using &lt;span style="font-family:courier new;"&gt;apply&lt;/span&gt;.&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;&gt; (apply infix3 '(2 + 3))&lt;br /&gt;(+ 2 3)&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;This is possible because macros in muSE are first class entities - i.e. they can be passed around by value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Evaluation order&lt;/span&gt;&lt;br /&gt;In common-lisp, I believe macros are expanded head first and they continue to expand until no more macros exist in the expression. muSE, on the contrary, performs &lt;span style="font-weight: bold;"&gt;tail-first&lt;/span&gt; expansion.&lt;br /&gt;&lt;br /&gt;For example, in the expression &lt;tt&gt;(infix3 2 + (infix3 1 + 2))&lt;/tt&gt;,&lt;br /&gt;the inner &lt;tt&gt;(infix3 1 + 2)&lt;/tt&gt; is expanded before passing on to the outer infix3, so the outer infix3 sees the expression &lt;tt&gt;(2 + (+ 1 2))&lt;/tt&gt;, which it'll transform to &lt;tt&gt;(+ 2 (+ 1 2))&lt;/tt&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Braces vs. parentheses&lt;/span&gt;&lt;br /&gt; Braces are evaluated even if they occur within quoted expressions, whereas parentheses aren't, even if they contain sub-expressions that look like macro calls. So the expression&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;tt&gt;'(1 2 {+ 3 4} 5 6)&lt;/tt&gt;&lt;/span&gt;&lt;br /&gt;is actually&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;tt&gt;'(1 2 7 5 6)&lt;/tt&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-319872713305840612?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/319872713305840612/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=319872713305840612' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/319872713305840612'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/319872713305840612'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/read-time-evaluation-in-muse.html' title='Read-time evaluation &amp; first class macros'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-1502924273768104533</id><published>2006-09-12T06:35:00.000+08:00</published><updated>2007-04-12T13:41:31.694+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Language'/><title type='text'>Pattern matching bind</title><content type='html'>muSE uniformly uses pattern matching to bind symbols to values. It is used in &lt;span style="font-family:courier new;"&gt;fn&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;case&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;let&lt;/span&gt; expressions - which therefore differ slightly from standard Scheme. Not only was it easier to use the same technique in all three expressions, it has resulted in greater expressive power for &lt;span style="font-family:courier new;"&gt;let&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;case&lt;/span&gt;, obviating the need to do &lt;span style="font-family:courier new;"&gt;first&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;rest&lt;/span&gt; and such destructuring operations on lists.&lt;br /&gt;&lt;br /&gt;muSE's pattern matching bind can deconstruct lists and match constants such as numbers, strings and symbols. Here's an example using &lt;span style="font-family:courier new;"&gt;fn&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;case&lt;/span&gt; - Suppose we need to create a function that adds up the pair-wise product of its arguments. i.e -&lt;br /&gt;&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;tt&gt;&gt; (f 1 2 3 4 5 6)&lt;/tt&gt;&lt;/span&gt;&lt;br /&gt;should yield -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;tt&gt;1 * 2 + 3 * 4 + 5 * 6&lt;/tt&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;tt&gt;= 45&lt;/tt&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We can write f like this -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;(define f&lt;br /&gt;  (fn args&lt;br /&gt;    (case args&lt;br /&gt;      (() 0)&lt;br /&gt;      ((x y . etc) (+ (* x y) (apply f etc))))))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Note that &lt;span style="font-family:courier new;"&gt;args&lt;/span&gt; is used by itself without an enclosing parentheses to get the arguments of the function as a list - this itself is a pattern match. Also note that NIL can be notated as &lt;span style="font-family:courier new;"&gt;()&lt;/span&gt; without a quote character.&lt;br /&gt;&lt;br /&gt;Similarly, &lt;span style="font-family:courier new;"&gt;let&lt;/span&gt; also allows you to deconstruct lists. Apart from that, the behaviour of &lt;span style="font-family:courier new;"&gt;let&lt;/span&gt; in muSE is similar to &lt;span style="font-family:courier new;"&gt;let*&lt;/span&gt; in Scheme. There are no other kinds of let in muSE because so far this one has been sufficient.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-1502924273768104533?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/1502924273768104533/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=1502924273768104533' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1502924273768104533'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/1502924273768104533'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/pattern-matching-bind.html' title='Pattern matching bind'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-3546312056274494088</id><published>2006-09-12T06:13:00.000+08:00</published><updated>2006-09-12T06:19:01.382+08:00</updated><title type='text'>Functions/closures</title><content type='html'>muSE doesn't use the Scheme standard &lt;span style="font-weight: bold;font-family:courier new;" &gt;lambda&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;keyword to create functions. This language deecision is because muSE is used by non-programmers who are slightly familiar with JavaScript, but will freak out if they see things like &lt;span style="font-family:courier new;"&gt;lambda&lt;/span&gt; occuring anywhere. It has &lt;span style="font-weight: bold;font-family:courier new;" &gt;fn&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;and &lt;span style="font-weight: bold;font-family:courier new;" &gt;fn:&lt;/span&gt; instead. &lt;span style="font-family:courier new;"&gt;fn&lt;/span&gt; behaves like you'd expect &lt;span style="font-family:courier new;"&gt;lambda&lt;/span&gt; to - capturing the lexical context in a closure. &lt;span style="font-family:courier new;"&gt;fn:&lt;/span&gt; creates a function which has a dynamically scoped body. Here's an example that tells you the difference between the two -&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;(define y 2.0)&lt;br /&gt;(define f (fn (x) (+ x y)))&lt;br /&gt;(define g (fn: (x) (+ x y)))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Now,&lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;&gt; (f 5.0)&lt;br /&gt;7.0&lt;br /&gt;&gt; (g 5.0)&lt;br /&gt;7.0&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Fair enough, but now lets change the definition of y ..... locally! &lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;(let ((y 4.0))&lt;br /&gt; (print (f 5.0))&lt;br /&gt; (print (g 5.0)))&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now &lt;tt&gt;f&lt;/tt&gt; continues to use the old value of &lt;tt&gt;y&lt;/tt&gt; whereas &lt;tt&gt;g&lt;/tt&gt; uses the new value of &lt;tt&gt;y&lt;/tt&gt; instead. The above expression will print - &lt;br /&gt;&lt;span style="color: orange"&gt;&lt;pre&gt;&lt;br /&gt;7.0&lt;br /&gt;9.0&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-3546312056274494088?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/3546312056274494088/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=3546312056274494088' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/3546312056274494088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/3546312056274494088'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/functions-in-muse-muse-doesnt-use.html' title='Functions/closures'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-115797332342291262</id><published>2006-09-11T19:13:00.000+08:00</published><updated>2007-02-02T07:09:29.050+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='API'/><title type='text'>API documentation</title><content type='html'>muSE API documentation in HTML format now available.&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://muvee-symbolic-expressions.googlecode.com/files/muse-processes-v109-API-doc.chm"&gt;Windows CHM help file&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/api/index.html"&gt;Online HTML docs&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;The API documentation was generated by running the &lt;a href="http://www.stack.nl/%7Edimitri/doxygen/"&gt;doxygen&lt;/a&gt; tool on the muSE source code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-115797332342291262?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/115797332342291262/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=115797332342291262' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/115797332342291262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/115797332342291262'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/muse-api-documentation-in-html-format.html' title='API documentation'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34156343.post-115789110286970827</id><published>2006-09-10T19:53:00.000+08:00</published><updated>2006-09-10T20:34:38.276+08:00</updated><title type='text'>Welcome to muSE</title><content type='html'>Hello and welcome to muSE.&lt;br /&gt;&lt;br /&gt;I wrote this Scheme dialect with the intention of having a simple small foot print engine that one can use as an expressive embedded extension language. The &lt;a href="http://www.muvee.com/"&gt;company I work for&lt;/a&gt; has allowed me to publish muSE under very liberal &lt;a href="http://muvee-symbolic-expressions.googlecode.com/svn/trunk/LICENSE.txt"&gt;open-source license terms&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Selling points -&lt;br /&gt;&lt;ul&gt;   &lt;li&gt;Easy to use and reasonably documented &lt;a href="http://homepage.mac.com/srikumarks/muSE-docs/html/"&gt;C embedding API&lt;/a&gt;.&lt;/li&gt;   &lt;li&gt;Closed execution environment - instabilities won't leak into your system unlike an environment that uses the Boehm garbage collector.&lt;/li&gt;   &lt;li&gt;Fairly small foot print - WIN32 executable is about 80KB including diagnostics.&lt;/li&gt;&lt;li&gt;64-bit ready - muSE integers are always 64-bit and 64-bit pointers are just a recompile away.&lt;/li&gt;   &lt;li&gt;Unicode throughout - Exclusively uses 16-bit characters internally, supports (only) UTF-8 for I/O.&lt;br /&gt; &lt;/li&gt;    &lt;li&gt;Fast enough as a glue language (at least for us). Startup/shutdown times are also quite fast due to the minimal language.&lt;br /&gt;&lt;/li&gt;   &lt;li&gt;Suitable for creating simple DSLs.&lt;br /&gt;&lt;/li&gt;   &lt;li&gt;Some novel/experimental features -&lt;/li&gt;   &lt;ul&gt;     &lt;li&gt;Simple notation for read-time code evaluation.&lt;br /&gt;&lt;/li&gt;   &lt;/ul&gt;   &lt;ul&gt;     &lt;li&gt;First class reader macros that expand tail-first.&lt;/li&gt;     &lt;li&gt;Dynamic or lexical scoping - you choose according to your need.&lt;/li&gt;     &lt;li&gt;Diagnostics that make spell-check-like suggestions.&lt;/li&gt;&lt;li&gt;Experimental support for &lt;a href="http://code.google.com/p/ez2scm"&gt;ez2scm&lt;/a&gt; syntax.&lt;/li&gt;    &lt;/ul&gt; &lt;/ul&gt; What muSE is not -&lt;br /&gt;&lt;ul&gt;   &lt;li&gt;A full R5RS compliant Scheme. We don't need full support because the runtime is expected to be aggresively extended using C/C++ depending on the usage context. Basics are however covered - map, for-each, list manipulations, closures, call/cc, vectors, hashtables, ports, etc. are in there. If you're looking for a full R5RS Scheme, try &lt;a href="http://www.plt-scheme.org/software/mzscheme/"&gt;MzScheme&lt;/a&gt; which is supported by the wonderful     &lt;a href="http://www.drscheme.org/"&gt;DrScheme&lt;/a&gt; IDE.&lt;/li&gt;&lt;li&gt;A coffee maker that toasts bagels to boot.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34156343-115789110286970827?l=muvee-symbolic-expressions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muvee-symbolic-expressions.blogspot.com/feeds/115789110286970827/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34156343&amp;postID=115789110286970827' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/115789110286970827'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34156343/posts/default/115789110286970827'/><link rel='alternate' type='text/html' href='http://muvee-symbolic-expressions.blogspot.com/2006/09/hello-and-welcome-to-muse.html' title='Welcome to muSE'/><author><name>Kumar</name><uri>http://www.blogger.com/profile/13618832348086828111</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
