<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.11" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Omnigia: Scheme, web applications, tech</title>
	<link>http://www.omnigia.com/news</link>
	<description>Scheme, web applications, tech</description>
	<pubDate>Thu, 12 Jun 2008 10:49:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.11</generator>
	<language>en</language>
			<item>
		<title>CPSCM: interfacing Javascript and Scheme</title>
		<link>http://www.omnigia.com/news/2007/09/10/cpscm-native-calls/</link>
		<comments>http://www.omnigia.com/news/2007/09/10/cpscm-native-calls/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 00:52:52 +0000</pubDate>
		<dc:creator>Dan Muresan</dc:creator>
		
		<category>scheme</category>

		<category>cpscm</category>

		<guid isPermaLink="false">http://www.omnigia.com/news/2007/09/10/cpscm-native-calls/</guid>
		<description><![CDATA[Calling Javascript from Scheme just got easier in CPSCM:
(define v 10)
(define (f x) (+ x v))
(%cpscm:native "alert (" v ")")
;; Can pass Scheme variables and computations
(%cpscm:native "alert (" (f 5) ")")
All string arguments to %cpscm:native are copied verbatim to the output. Inner computations are still compiled as any normal Scheme code, and their results are [...]]]></description>
			<content:encoded><![CDATA[<p>Calling Javascript from Scheme just got easier in <a href="http://www.omnigia.com/scheme/cpscm/home/">CPSCM</a>:</p>
<pre>(define v 10)
(define (f x) (+ x v))
(%cpscm:native "alert (" v ")")
;; Can pass Scheme variables and computations
(%cpscm:native "alert (" (f 5) ")")</pre>
<p>All string arguments to <kbd>%cpscm:native</kbd> are copied verbatim to the output. Inner computations are still compiled as any normal Scheme code, and their results are passed to the native call via temporary variables. Each native call must correspond to a single JS statement.</p>
<p>The old method was to provide a CPS wrapper with the correct mangled name, e.g. to create a function callable as <kbd>(fun 1 2)</kbd> from Scheme:</p>
<pre>var cpscmjsfun = cpscm__cpswrap (
  function fun (x, y) { return x + y; }
);</pre>
<p>This still works, of course (as demonstrated in the <a href="http://www.omnigia.com/scheme/cpscm/bs-demo/">DHTML bubble-sort</a> example), but the new method adds convenience.</p>
<p>The main reason for <kbd>native</kbd> is the anticipated Emacs Lisp backend: users will surely want to call a myriad of elisp functions from Scheme, and writing a CPS stub for each of them would be impractical.</p>
<p><strong>Note</strong>: the new code is in <a href="http://code.google.com/p/cpscm/source">SVN</a>, but the I haven&#8217;t updated the <a href="http://www.omnigia.com/scheme/cpscm/">online compiler</a> demo webapp yet.
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.omnigia.com/news/2007/09/10/cpscm-native-calls/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Emacs Lisp vs. Scheme: scoping and globals</title>
		<link>http://www.omnigia.com/news/2007/08/07/emacs-lisp-scoping-globals/</link>
		<comments>http://www.omnigia.com/news/2007/08/07/emacs-lisp-scoping-globals/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 09:46:52 +0000</pubDate>
		<dc:creator>Dan Muresan</dc:creator>
		
		<category>scheme</category>

		<category>cpscm</category>

		<category>emacs</category>

		<guid isPermaLink="false">http://www.omnigia.com/news/2007/08/07/emacs-lisp-scoping-globals/</guid>
		<description><![CDATA[I&#8217;ve been considering an elisp back-end for CPSCM (so that we can program Emacs in R5RS Scheme). I thought the lack of lexical scoping would prove a major stumbling block, but in the end it turns out that Elisp will be somewhat easier to support than Common Lisp. Here are the twists and turns (to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been considering an elisp back-end for <a href="http://www.omnigia.com/scheme/cpscm/home/">CPSCM</a> (so that we can program Emacs in R5RS Scheme). I thought the lack of lexical scoping would prove a major stumbling block, but in the end it turns out that Elisp will be somewhat easier to support than Common Lisp. Here are the twists and turns (to evaluate Elisp code, go to the *scratch* buffer, paste the code and type <kbd>C-x C-e</kbd>):</p>
<ul>
<li>Elisp has dynamic scope by default:
<pre>(defun f () y)
(let ((y 10)) (f))  ;; 10
;; lambda arguments are also dynamic
(funcall (lambda (y) (f)) 11)  ;; 11
</pre>
</li>
<li>However, with <kbd>(require &apos;cl)</kbd> you get access to the (lexical-let &#8230;) macro, which does exactly what the name says (there is also a <kbd>lexical-let*</kbd>)</li>
<li>Using <kbd>lexical-let</kbd>, one can easily define <kbd>lexical-lambda</kbd> &mdash; here&#8217;s a simple version (optimized for minimal line lengths, not Lisp-ness)
<pre>(defmacro lexical-lambda (args &#038;rest body)
  (lexical-let* ((r '&amp;rest) (g (lambda (x) (if (eq x r) x (gensym))))
                 (gvars (mapcar g args))
                 (bnd (mapcar* #'list args gvars)))
    `(lambda ,gvars
       (lexical-let ,(delete-if (lambda (b) (eq (car b) r)) bnd)
         ,@body))))</pre>
</li>
</ul>
<p>OK, so we&#8217;ve played catch up with Common Lisp and managed to work around dynamic scoping; here&#8217;s the beautiful part:</p>
<ul>
<li>Elisp has sane(r) globals (from a Schemer&#8217;s POV, at least)</li>
</ul>
<p>To those who haven&#8217;t bashed their heads against this problem, Common Lisp&#8217;s &#8220;normal&#8221; way of declaring globals (<kbd>defvar</kbd> / <kbd>defparameter</kbd>) makes variables &#8220;pervasively special&#8221; (i.e. dynamic) &mdash; meaning that</p>
<pre>(defvar myvar 10)
(defun (f) myvar)
(defun g () (let ((myvar 1)) (f)))
(g)  ;; => 1, not 10</pre>
<p>This is not such a problem for Lisp, but what with Scheme being a Lisp-1, translation of global functions is problematic:</p>
<pre>(define (f x) x)  ;; Scheme
;; Lisp translation -- broken
(defvar f (lambda (x) x))</pre>
<p>There&#8217;s another standard-compliant way to simulate globals in Lisp (using symbol macros &mdash; search comp.lang.lisp for <kbd>deflex</kbd>); however this method requires you to define each global before referencing it, which would preclude mutually-recursive global functions:</p>
<pre>(deflex f (lambda (x) (funcall g (- x 1))))  ;; broken: g undefined
(deflex g (lambda (x) (if (> x 0) (funcall f x) 0)))</pre>
<p>There are other, more convoluted ways to implement &#8220;non-special&#8221; globals that have elicited endless (and inconclusive, as far as I could tell) threads on comp.lang.lisp, e.g. using <kbd>(locally (declare (special myvar)))</kbd>.  Finally, in many Lisp&apos;s one can simply use <kbd>(setq myvar &#8230;)</kbd> and at most get a warning, but this is not standards-compliant.</p>
<p>As luck would have it, <kbd>setq</kbd> globals work in Elisp too, and the manual seems to indicate that this is intended semantics, not accident. So this will save me the pain of working around Common Lisp&#8217;s &#8220;special&#8221; variable rules (I&#8217;ve never found a satisfactory solution), which is why I&#8217;m happy about Elisp.</p>
<p>Of course there are areas that need work, e.g. an easier &#8220;FFI&#8221; to access Elisp functions from Scheme (currently, one has to define a CPS-style wrapper in the back-end with the proper mangled name to make a function callable from CPSCM). But I find the prospect of programming Emacs in Scheme a pretty good motivation&#8230;
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.omnigia.com/news/2007/08/07/emacs-lisp-scoping-globals/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CPSCM passes R5RS pitfalls</title>
		<link>http://www.omnigia.com/news/2006/12/23/cpscm-r5rs-pitfalls/</link>
		<comments>http://www.omnigia.com/news/2006/12/23/cpscm-r5rs-pitfalls/#comments</comments>
		<pubDate>Sat, 23 Dec 2006 08:53:08 +0000</pubDate>
		<dc:creator>Dan Muresan</dc:creator>
		
		<category>scheme</category>

		<category>cpscm</category>

		<guid isPermaLink="false">http://www.omnigia.com/news/2006/12/23/cpscm-r5rs-pitfalls/</guid>
		<description><![CDATA[After several fixes and tweaks, the CPSCM Javascript backend passes the R5RS Pitfalls test with a full score. The Lisp backend almost does, but since I decided to stick with Lisp&#8217;s convention of representing both false booleans and empty lists with NIL, it fails cases 5.1 - 5.3.
Additionally, I have tested the bubble sort example [...]]]></description>
			<content:encoded><![CDATA[<p>After several fixes and tweaks, the <a href="http://www.omnigia.com/scheme/cpscm/">CPSCM</a> Javascript backend passes the <a href="http://sisc.sourceforge.net/r5rs_pitfall.php">R5RS Pitfalls</a> test with a full score. The Lisp backend almost does, but since I decided to stick with Lisp&#8217;s convention of representing both false booleans and empty lists with <code>NIL</code>, it fails cases 5.1 - 5.3.</p>
<p>Additionally, I have tested the <a href="http://www.omnigia.com/scheme/cpscm/bs-demo/">bubble sort example</a> and the JS backend in general under IE 6, Firefox and Opera (the browsers I can access easily). I haven&#8217;t encountered any issues. If you are using IE 7 or Safari  and run into problems, please report. The <a href="http://www.omnigia.com/scheme/cpscm/">online compiler</a> now lets you execute compiled code directly in your browser, so it&#8217;s much easier to test than before.</p>
<p>On the negative side, some of you have noticed that the CPS code is more bloated than before. This is because I had to back out η-reduction for some cases, in the interest of correctness: <code>(lambda (x) (f x))</code> does not reduce to <code>f</code> automaticaly if <code>f</code> is mutable (and, of course, Scheme is not Erlang). The analysis module will catch up eventually&#8230;
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.omnigia.com/news/2006/12/23/cpscm-r5rs-pitfalls/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CPSCM translates Scheme to Javascript</title>
		<link>http://www.omnigia.com/news/2006/12/14/cpscm-scheme-to-javascript/</link>
		<comments>http://www.omnigia.com/news/2006/12/14/cpscm-scheme-to-javascript/#comments</comments>
		<pubDate>Thu, 14 Dec 2006 13:21:27 +0000</pubDate>
		<dc:creator>Dan Muresan</dc:creator>
		
		<category>scheme</category>

		<category>cpscm</category>

		<guid isPermaLink="false">http://www.omnigia.com/news/2006/12/14/cpscm-scheme-to-javascript/</guid>
		<description><![CDATA[I have added a Javascript backend for CPSCM. The compiled code  runs either inside a browser or in Rhino. The Bubble sort example  demonstrates compiled Scheme code running &#8220;in a web page&#8221; and  interfacing with native Javascript code (the latter provides DHTML  functionality). You can call Scheme functions from Javascript and [...]]]></description>
			<content:encoded><![CDATA[<p>I have added a Javascript backend for <a href="http://www.omnigia.com/scheme/cpscm/">CPSCM</a>. The compiled code  runs either inside a browser or in <a href="http://www.mozilla.org/rhino/">Rhino</a>. The <a href="http://www.omnigia.com/scheme/cpscm/bs-demo/">Bubble sort example</a>  demonstrates compiled Scheme code running &#8220;in a web page&#8221; and  interfacing with native Javascript code (the latter provides DHTML  functionality). You can call Scheme functions from Javascript and  Javascript functions from Scheme with no restrictions (even  continuations will work correctly). The explanations on the bubblesort page  should get you started, in case you want to roll your own Scheme  programs.</p>
<p>I have made updates and fixes to all backends. There are still  missing pieces, but at least now they are summarized on the <a href="http://www.omnigia.com/scheme/cpscm/conformance/">conformance  page</a>, so you know what to expect. Among the improvements, there is an <code>error</code> function which interacts correctly with <code>dynamic-wind</code>. I have borrowed the concept of <a href="http://sisc.sourceforge.net/manual/html/ch03.html#FailureContinuations">failure continuations</a> from SISC; you can access them via <code>with-failure-continuation</code>.</p>
<p>Finally, since Javascript console I/O is not standardized, I have implemented SRFI-6 output strings. By default, <code>(display)</code> and its family assume you are using Rhino and try to print to standard output. You can switch to a string using <code>(current-output-port (open-output-string))</code>, and at any point retrieve the accumulated output using <code>(get-output-string (current-output-port))</code>.
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.omnigia.com/news/2006/12/14/cpscm-scheme-to-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CPSCM improvements</title>
		<link>http://www.omnigia.com/news/2006/12/03/cpscm-improvements/</link>
		<comments>http://www.omnigia.com/news/2006/12/03/cpscm-improvements/#comments</comments>
		<pubDate>Sun, 03 Dec 2006 16:44:08 +0000</pubDate>
		<dc:creator>Dan Muresan</dc:creator>
		
		<category>scheme</category>

		<category>cpscm</category>

		<guid isPermaLink="false">http://www.omnigia.com/news/2006/12/03/cpscm-improvements/</guid>
		<description><![CDATA[Alessandro Colomba (of SISCweb fame) played with CPSCM and  noted that he had trouble compiling the SRFI-1 reference  implementation (you need a self-contained  SRFI-1 to check). After investigating the problem, I  found out that the culprit was the η-reduction code in  simplify-sexp, which wasn&#8217;t designed carefully and  exhibited exponential [...]]]></description>
			<content:encoded><![CDATA[<p>Alessandro Colomba (of <a href="http://siscweb.sourceforge.net">SISCweb</a> fame) played with <a href="http://www.omnigia.com/scheme/cpscm/">CPSCM</a> and  noted that he had trouble compiling the SRFI-1 reference  implementation (you need a <a href="http://cpscm.googlecode.com/svn/tags/rel-0.9.2/tests/srfi-1.scm">self-contained  SRFI-1</a> to check). After investigating the problem, I  found out that the culprit was the η-reduction code in  <code>simplify-sexp</code>, which wasn&#8217;t designed carefully and  exhibited exponential behavior on certain inputs (in practice, I&#8217;ve  only seen that happen on CPS-ed code). After refactoring  <code>simplify-sexp</code>, SRFI-1 compiles in just a few  seconds.</p>
<p>The fixes are up in SVN (I&#8217;ve tagged the current  version as <kbd>rel-0.9.2</kbd>). Other improvements:</p>
<ul>
<li>Most of the code can be compiled under Chicken, with remarkable  speed gains. Just type <kbd>make</kbd> in the <kbd>scm</kbd>  directory. <kbd>csi</kbd> (which is still needed for the REPL) uses  the compiled libraries automatically.</li>
<li>By popular demand I have added a <code>file->lisp</code>  procedure for compiling a Scheme source file.</li>
<li>Programs are no longer wrapped in a giant <code>letrec</code>,  but generate a sequence of top-level definitions and evaluation  calls. This means you can compile libraries (such as SRFI-1 above)  to separate files, and then load those compiled files independently  in the back-end.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.omnigia.com/news/2006/12/03/cpscm-improvements/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Announcing CPSCM, a new Scheme</title>
		<link>http://www.omnigia.com/news/2006/11/25/cpscm-scheme/</link>
		<comments>http://www.omnigia.com/news/2006/11/25/cpscm-scheme/#comments</comments>
		<pubDate>Sat, 25 Nov 2006 13:25:23 +0000</pubDate>
		<dc:creator>Dan Muresan</dc:creator>
		
		<category>scheme</category>

		<category>cpscm</category>

		<guid isPermaLink="false">http://www.omnigia.com/news/2006/11/25/cpscm-scheme/</guid>
		<description><![CDATA[I am releasing CPSCM, a new Scheme compiler based on classic CPS conversion and trampolines. It will eventually support multiple backends (Javascript and Java are in the works), but currently it supports Scheme to Common Lisp translation. You can see it work right from your browser on the online demo page (no large jobs, please), [...]]]></description>
			<content:encoded><![CDATA[<p>I am releasing <a href="http://www.omnigia.com/scheme/cpscm/home/">CPSCM</a>, a new Scheme compiler based on classic CPS conversion and trampolines. It will eventually support multiple backends (Javascript and Java are in the works), but currently it supports Scheme to Common Lisp translation. You can see it work right from your browser on the <a href="http://www.omnigia.com/scheme/cpscm/">online demo</a> page (no large jobs, please), or you can download and run it by following the instructions on the CPSCM homepage.</p>
<p>Macro-expansion is delegated to Al Petrofsky&#8217;s <a href="http://petrofsky.org/src/alexpander.scm">alexpander</a>, which means that CPSCM has full <code>syntax-rules</code> support from the start. I&#8217;ll probably add <code>define-macro</code> support at some point. I don&#8217;t feel up to integrating <code>syntax-case</code>, but if anyone wants to contribute, it would be greatly appreciated.</p>
<p>Other than this, CPSCM supports full continuations, including correct <code>call/cc</code> + <code>dynamic-wind</code> interaction, and SRFI-0. It still lacks <code>eval</code>, <code>error</code> protection in <code>dynamic-wind</code>, streams, <code>load</code>, and multiple-file source facilities. An interesting point is that as soon as CPSCM is able to compile itself, <code>eval</code> can be added in (though the <kbd>environment</kbd> functions other than <code>interaction-environment</code> will be problematic.)</p>
<p>As with <a href="http://www.omnigia.com/scheme/scsh-regexp/">scsh-regexp</a>, I will use <a href="http://code.google.com/p/cpscm/">Google Code Project Hosting</a>. Some people have questioned this choice (and Google Code has earned mixed reviews); compared to Sourceforge, Google Code has a big advantage: they don&#8217;t make you fill out multi-page forms (and wait for approval!) for the &#8220;privillege&#8221; of uploading an open-source project.
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.omnigia.com/news/2006/11/25/cpscm-scheme/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
