<?xml version='1.0' encoding='utf-8' ?>
<!--  If you are running a bot please visit this policy page outlining rules you must respect. http://www.livejournal.com/bots/  -->
<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:media='http://search.yahoo.com/mrss/'>
<channel>
  <title>Kevin Reid&apos;s blog</title>
  <link>http://kpreid.livejournal.com/</link>
  <description>Kevin Reid&apos;s blog - LiveJournal.com</description>
  <managingEditor>kpreid@mac.com</managingEditor>
  <lastBuildDate>Mon, 13 Jul 2009 13:33:56 GMT</lastBuildDate>
  <generator>LiveJournal / LiveJournal.com</generator>
  <lj:journal>kpreid</lj:journal>
  <lj:journalid>3537103</lj:journalid>
  <lj:journaltype>personal</lj:journaltype>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/14890.html</guid>
  <pubDate>Mon, 13 Jul 2009 13:33:56 GMT</pubDate>
  <title>GSoC update: Hurry up and procrastinate.</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/14890.html</link>
  <description>&lt;p&gt;I&apos;m having severe getting-around-to-actually-doing-the-work problems; I am far behind schedule. I think the problem is framing this as “work” rather than just another of the projects that I&apos;ve found interesting and tinkered with. (I also blame &lt;a href=&quot;http://store.steampowered.com/app/440/&quot;&gt;Team Fortress 2&lt;/a&gt; and &lt;a href=&quot;http://rosettacode.org/&quot;&gt;Rosetta Code&lt;/a&gt; for providing attractive distractions...)&lt;/p&gt;

&lt;p&gt;I&apos;ve ported the “&lt;a href=&quot;http://wiki.erights.org/wiki/Ref&quot;&gt;Ref&lt;/a&gt;” facility from E; this is necessary as CapTP is built on Ref semantics (promises, proxies, broken refs). I hope to very soon get the actual CapTP connection module up, then (as I wrote before) “define, document and implement a CapTP-over-HTTP protocol”.&lt;/p&gt;

&lt;p&gt;(I previously mentioned implementing the Surgeon (serialization tool) but I then remembered that that&apos;s actually irrelevant to CapTP.)&lt;/p&gt;

&lt;p&gt;Also: working without Internet access removes a whole lot of potential distractions — and one’s access to online documentation. Luckily I had some source code around which provided examples.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/14890.html</comments>
  <category>captp</category>
  <category>e</category>
  <category>javascript</category>
  <category>gsoc</category>
  <category>gsoc2009</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/14713.html</guid>
  <pubDate>Mon, 13 Jul 2009 13:09:44 GMT</pubDate>
  <title>Common Lisp hackery: writing fasls from non-file input</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/14713.html</link>
  <description>

&lt;p&gt;Common Lisp provides &lt;a href=&quot;http://www.lispworks.com/documentation/HyperSpec/Body/f_cmp_fi.htm&quot; title=&quot;CLHS: Function COMPILE-FILE&quot;&gt;compile-file&lt;/a&gt; whose purposes is to convert a CL source file into an (implementation-defined) format which usually has precompiled code and is designed for faster loading into a lisp system.&lt;/p&gt;

&lt;p&gt;compile-file takes the pathname of a textual lisp source file. But what if you want to compile some Lisp code that&apos;s not in a file already, perhaps because you translated/compiled it from some not-amenable-to-the-Lisp-reader input syntax, or because it contains un&lt;a href=&quot;http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_rd.htm&quot; title=&quot;CLHS: Function READ, READ-PRESERVING-WHITESPACE&quot;&gt;READ&lt;/a&gt;able literals? You can use a &quot;universal Lisp file&quot;, which I know two ways to create (use whichever you find cleaner):&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;(cl:in-package :mypackage)
#.mypackage::*program*&lt;/pre&gt;&lt;/blockquote&gt;

or

&lt;blockquote&gt;&lt;pre&gt;(cl:in-package :mypackage)
(macrolet ((it () *program*))
  (it))&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Suppose this is in &quot;universal.lisp&quot;. Then to use it:&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;(defvar *program*)

(defun compile-to-file (form output-file)
  (let ((*program* form))
    (compile-file #p&quot;universal.lisp&quot;
                  :output-file output-file)))&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;This is just a minimal example; you&apos;ll also want to appropriately handle the return value from compile-file, provide an appropriate pathname to the universal file, etc. For example, here&apos;s an excerpt of the relevant code from &lt;a href=&quot;http://wiki.erights.org/wiki/E-on-CL&quot; title=&quot;E on Common Lisp&quot;&gt;E-on-CL&lt;/a&gt;, where I have used this technique to compile non-CL sources (emakers) into fasls:&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;
(defparameter +the-asdf-system+ (asdf:find-system :e-on-cl))
(defvar *efasl-program*)
(defvar *efasl-result*)
...
(defun compile-e-to-file (expr output-file fqn-prefix opt-scope)
  ...
  (let* (...
         (*efasl-program*
           `(setf *efasl-result*
                  (lambda (...) ...))))
    (multiple-value-bind (truename warnings-p failure-p)
        (compile-file (merge-pathnames
                        #p&quot;lisp/universal.lisp&quot;
                        (asdf:component-pathname +the-asdf-system+))
                      :output-file output-file
                      :verbose nil
                      :print nil)
      (declare (ignore truename warnings-p))
      (assert (not failure-p) () &quot;Compilation for ~A failed.&quot; output-file))))

(defun load-compiled-e (file env)
  (let ((*efasl-result* nil)
        ...)
    (load file :verbose nil :print nil)
    (funcall *efasl-result* env)))
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Note that the pathname is computed relative to the &lt;a href=&quot;http://www.cliki.net/asdf&quot; title=&quot;CLiki : asdf&quot;&gt;ASDF&lt;/a&gt; system containing the universal file; also note the use of a variable *efasl-result* to simulate a &quot;return value&quot; from the compiled file, and the use of a lambda to provide a nonempty lexical environment, both of which are features not directly provided by the CL compiled file facility.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/14713.html</comments>
  <category>e</category>
  <category>programming</category>
  <category>lisp</category>
  <category>e-on-cl</category>
  <lj:security>public</lj:security>
  <lj:reply-count>2</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/14573.html</guid>
  <pubDate>Sun, 14 Jun 2009 04:37:10 GMT</pubDate>
  <title>Web site moved; feedback wanted</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/14573.html</link>
  <description>&lt;p&gt;I have moved my web site to a new location: &lt;a href=&quot;http://switchb.org/kpreid/&quot;&gt;http://switchb.org/kpreid/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I have done this because Apple has announced they are shutting down homepage.mac.com. While they offer a replacement, I do not want to have to change my URLs ever again, so I bought a domain name.&lt;/p&gt;

&lt;p&gt;As well as moving the files I have updated my picture, changed some of the URL layout, updated some miscellaneous information, added an “About me” section for the front page, and fixed broken external links. Please let me know if I missed anything...&lt;/p&gt;

&lt;p&gt;or even just critique it without respect to what&apos;s new.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/14573.html</comments>
  <category>life</category>
  <category>web site</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/14259.html</guid>
  <pubDate>Tue, 02 Jun 2009 18:52:11 GMT</pubDate>
  <title>GSoC update: Going both ways.</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/14259.html</link>
  <description>&lt;p&gt;I&apos;m not making progress as fast as I would like; mostly due to assorted distractions rather than Doing The Work.&lt;/p&gt;

&lt;p&gt;That said, I&apos;ve gotten both ends of serialization implemented, at least for non-circular cases: the deJSONTreeKit and deSubgraphKit have both builder and recognizer implementations. (For a terminology introduction, see &lt;a href=&quot;http://www.erights.org/data/serial/jhu-paper/deconstructing.html&quot;&gt;the serialization paper&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;Next up is the surgeon (high-level serialization interface), and designing uncallers suitable for JavaScript. I definitely need to increase my rate of progress to get this done on schedule.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/14259.html</comments>
  <category>captp</category>
  <category>e</category>
  <category>javascript</category>
  <category>gsoc</category>
  <category>gsoc2009</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/13956.html</guid>
  <pubDate>Sat, 30 May 2009 03:58:06 GMT</pubDate>
  <title>GSoC update: It runs!</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/13956.html</link>
  <description>&lt;p&gt;I completed enough of &lt;a href=&quot;http://kpreid.livejournal.com/13814.html&quot;&gt;the E-on-JavaScript improvements&lt;/a&gt;, and wrote the beginnings of one Data-E kit in Cajita, together with the Updoc tests for it, and a Makefile to &lt;a href=&quot;http://code.google.com/p/google-caja/wiki/CajaCajole&quot;&gt;cajole&lt;/a&gt; the JavaScript and &quot;animate&quot; the Updoc - convert it into a HTML page that actually runs the tests.&lt;/p&gt;

&lt;p&gt;I also improved various readme files and pages, hopefully such that someone else can get it all installed on their own system starting from &lt;a href=&quot;http://code.google.com/p/caja-captp/&quot;&gt;my project page&lt;/a&gt; without too much prior knowledge.&lt;/p&gt;

&lt;p&gt;Near-term plan: Put aside the EoJS, and get the Data-E kits working; then the surgeon; then the CapTPConnection; then define, document and implement a CapTP-over-HTTP protocol.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/13956.html</comments>
  <category>captp</category>
  <category>e</category>
  <category>javascript</category>
  <category>gsoc</category>
  <category>gsoc2009</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/13814.html</guid>
  <pubDate>Thu, 28 May 2009 14:39:43 GMT</pubDate>
  <title>GSoC project update</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/13814.html</link>
  <description>&lt;p&gt;I have begun the work on my GSoC project, &lt;a href=&quot;http://code.google.com/p/caja-captp/&quot;&gt;Caja-CapTP&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I am currently working on improving &lt;a href=&quot;http://www.eros-os.org/pipermail/e-lang/2009-January/012946.html&quot;&gt;E-on-JavaScript&lt;/a&gt; in order to be able to use its Updoc facility as the test framework for the Caja-CapTP code.&lt;/p&gt;

&lt;p&gt;(If you don&apos;t know, &lt;a href=&quot;http://wiki.erights.org/wiki/Updoc&quot;&gt;Updoc&lt;/a&gt; is a test system which works by rerunning a recorded or made-up interactive session and confirming that the output is the same as before. The advantage of this system is that you can write test cases very simply as sequential code without gobs of assertFoo() for every particular attribute you think of testing.)&lt;/p&gt;

&lt;p&gt;You can see &lt;a href=&quot;http://cia.vc/stats/project/erights.org&quot;&gt;my commits to EoJS at CIA.vc&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I am also learning more about exactly how Cajita works in areas such as library loading; the documentation in this area needs improvement, which I am going to work on myself and/or ask the Caja developers to clarify.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/13814.html</comments>
  <category>captp</category>
  <category>e</category>
  <category>javascript</category>
  <category>gsoc</category>
  <category>gsoc2009</category>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/13341.html</guid>
  <pubDate>Wed, 13 May 2009 17:54:36 GMT</pubDate>
  <title>The overstuffed ballot box</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/13341.html</link>
  <description>&lt;p&gt;I get the feeling the textbook writers had a list of everyday objects which they randomly picked from to avoid saying “an object” in each exercise. The results are &lt;em&gt;mostly&lt;/em&gt; just distracting or mildly amusing, but sometimes they&apos;re a bit too much:&lt;/p&gt;

&lt;blockquote&gt;&lt;img style=&quot;-webkit-box-shadow: 0px 1px 3px #888; -moz-box-shadow: 0px 1px 3px #888;&quot; src=&quot;http://switchb.org/kpreid/2009/phys-ballot-box.jpg&quot; alt=&quot;Sample Problem 9-6One-dimensional explosion: A ballot box with mass m = 6.0 kg slides with speed v = 4.0 m/s across a frictionless floor in the positive direction of an x axis. The box explodes into two pieces. One piece, with mass m_1 = 2.0 kg, moves in the positive direction of the x axis at v_1 = 8.0 m/s. What is the velocity of the second piece, with mass m_2?&quot;&gt;&lt;/blockquote&gt;
&lt;p&gt;— Halliday, Resnick, Walker, &lt;i&gt;Fundamentals of Physics&lt;/i&gt;, 8th ed., page 215&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/13341.html</comments>
  <category>college</category>
  <category>irrelevant</category>
  <category>physics</category>
  <lj:security>public</lj:security>
  <lj:reply-count>9</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/13234.html</guid>
  <pubDate>Tue, 12 May 2009 12:06:42 GMT</pubDate>
  <title>Spot the bogus proof [updated]</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/13234.html</link>
  <description>&lt;p&gt;(This is (finally, now that the semester is over and I have some free time, heh) one of those posts-related-to-schoolwork I &lt;a href=&quot;http://kpreid.livejournal.com/12194.html&quot; title=&quot;kpreid: Decloaking, part 1: stage of life&quot;&gt;mentioned before&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;
Does the &lt;a href=&quot;http://en.wikipedia.org/wiki/Series_(mathematics)&quot; title=&quot;Series (mathematics) - Wikipedia, the free encyclopedia&quot;&gt;infinite series&lt;/a&gt; 
&lt;img align=&quot;MIDDLE&quot; border=&quot;0&quot; src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/theseries.png&quot; alt=&quot;$ \displaystyle\sum_{n=2}^{∞} \dfrac{n^2}{n^3 + 1}$&quot;&gt;
 converge?&lt;/p&gt;

&lt;p style=&quot;margin-bottom: 0&quot;&gt;
First, rewrite it to have &lt;var&gt;n&lt;/var&gt; = 1 as 
&lt;img align=&quot;MIDDLE&quot; border=&quot;0&quot; src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/startat1.png&quot; alt=&quot;$ \displaystyle -\frac{1}{2} + \sum_{n=1}^{∞} \dfrac{n^2}{n^3 + 1}$&quot;&gt;
, and discard the constant term since it does not affect convergence. The terms of this series are &lt;i&gt;strictly&lt;/i&gt; less than those of 
&lt;img align=&quot;MIDDLE&quot; border=&quot;0&quot; src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/eqharmonic.png&quot; alt=&quot;$ \displaystyle \sum_{n=1}^{∞} \dfrac{n^2}{n^3} = \sum_{n=1}^{∞} \dfrac{1}{n}$&quot;&gt;
; therefore, there is some &lt;var&gt;x&lt;/var&gt; such that&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 0;&quot;&gt;&lt;img align=&quot;MIDDLE&quot; border=&quot;0&quot; src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/ineqinf.png&quot; alt=&quot;$\displaystyle \sum_{n=1}^{∞} \dfrac{n^2}{n^3 + 1} &amp;lt; x &amp;lt; \sum_{n=1}^{∞} \dfrac{1}{n}$&quot;&gt;&lt;/div&gt;

&lt;p&gt;Let &lt;var&gt;k&lt;/var&gt; be the upper bound of the sum as we take the limit: 
&lt;img style=&quot;vertical-align: middle&quot; border=&quot;0&quot; src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/eqlimk.png&quot; alt=&quot;$ \displaystyle \sum_{n=1}^{∞} \dfrac{n^2}{n^3 + 1} = \lim_{k\to ∞}\sum_{n=1}^{k} \dfrac{n^2}{n^3 + 1}$&quot;&gt;
. 

&lt;p style=&quot;margin-bottom: 0;&quot;&gt;
Since 
&lt;img align=&quot;MIDDLE&quot; border=&quot;0&quot; src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/pseriesk.png&quot; alt=&quot;$ \displaystyle \sum_{n=1}^k \dfrac{1}{n^p}$&quot;&gt;
 is a &lt;a href=&quot;http://en.wikipedia.org/wiki/Continuous_function&quot; title=&quot;Continuous function - Wikipedia, the free encyclopedia&quot;&gt;continuous function&lt;/a&gt; of &lt;var&gt;p&lt;/var&gt;, for any &lt;var&gt;k&lt;/var&gt; &lt;a href=&quot;http://en.wikipedia.org/wiki/Intermediate_value_theorem&quot; title=&quot;Intermediate value theorem - Wikipedia, the free encyclopedia&quot;&gt;there is some &lt;var&gt;p&lt;/var&gt;&lt;/a&gt; greater than 1 such that&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 0;&quot;&gt;
&lt;img align=&quot;MIDDLE&quot; border=&quot;0&quot; src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/ineqK.png&quot; alt=&quot;$\displaystyle \sum_{n=1}^k \dfrac{n^2}{n^3 + 1} &amp;lt; x = \sum_{n=1}^k \dfrac{1}{n^p} &amp;lt; \sum_{n=1}^k \dfrac{1}{n}$&quot;&gt;&lt;/div&gt;
&lt;p&gt;Since 
&lt;img align=&quot;MIDDLE&quot; border=&quot;0&quot; src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/pseries.png&quot; alt=&quot;$ \displaystyle \sum_{n=1}^{∞} \dfrac{1}{n^p}$&quot;&gt;
 is a &lt;a href=&quot;http://en.wikipedia.org/wiki/Harmonic_series_(mathematics)#P-series&quot; title=&quot;Harmonic series (mathematics) - Wikipedia, the free encyclopedia&quot;&gt;&lt;var&gt;p&lt;/var&gt;-series&lt;/a&gt; which converges, i.e. has a finite sum, and the series under consideration has a lesser sum by the above inequality, it converges.&lt;/p&gt;

&lt;p&gt;Furthermore, the above may be generalized to a proof that any series whose terms are eventually less than those of the harmonic series converges.&lt;/p&gt;

&lt;hr width=&quot;10%&quot; noshade=&quot;noshade&quot;&gt;

&lt;p&gt;However, it is invalid, and in fact &lt;img src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/theseries.png&quot; align=&quot;middle&quot; alt=&quot;$ \displaystyle\sum_{n=2}^{∞} \dfrac{n^2}{n^3 + 1}$&quot;&gt; diverges.&lt;/p&gt;

&lt;p&gt;I managed to convince myself and my calculus teacher with it, but we realized it must be invalid after he presented a counterexample to the general case. I then realized which step was invalid.&lt;/p&gt;

&lt;hr width=&quot;10%&quot; noshade=&quot;noshade&quot;&gt;

&lt;p&gt;You can&apos;t use the &lt;em&gt;same&lt;/em&gt; &lt;var&gt;k&lt;/var&gt; for all three series in the second inequality; each infinite sum has its own independent limit, and what this proof is doing is along the lines of &amp;#8734; - &amp;#8734; = 0 &amp;mdash; assuming that &amp;ldquo;two infinities are the same size&amp;rdquo;. Or rather, the inequality itself (among partial sums) is true, but that fact has nothing to do with the properties of the true infinite series.&lt;/p&gt;

&lt;p&gt;I would be mildly interested in a more formal description of this sort of failure: how the &lt;var&gt;k&lt;/var&gt; inequality is true yet the independent series do not have the same relation.&lt;/p&gt;

&lt;hr width=&quot;10%&quot; noshade=&quot;noshade&quot;&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: I have received many informative comments and replied to some; one pointed out an earlier mistake: &lt;img align=&quot;MIDDLE&quot; border=&quot;0&quot; src=&quot;http://switchb.org/kpreid/2009/bogus-series-proof/ineqinf.png&quot; alt=&quot;$\displaystyle \sum_{n=1}^{∞} \dfrac{n^2}{n^3 + 1} &amp;lt; x &amp;lt; \sum_{n=1}^{∞} \dfrac{1}{n}$&quot;&gt; is bogus because we can&apos;t compare the &lt;em&gt;series&lt;/em&gt; until we know they converge.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/13234.html</comments>
  <category>college</category>
  <category>math</category>
  <lj:security>public</lj:security>
  <lj:reply-count>13</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/12872.html</guid>
  <pubDate>Tue, 21 Apr 2009 11:09:25 GMT</pubDate>
  <title>Whee, G-S-o-C</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/12872.html</link>
  <description>&lt;p&gt;I have been &lt;a href=&quot;http://socghop.appspot.com/student_project/show/google/gsoc2009/google/t124022446464&quot;&gt;accepted&lt;/a&gt; to &lt;a href=&quot;http://code.google.com/soc/&quot;&gt;Google Summer of Code 2009&lt;/a&gt;!&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/12872.html</comments>
  <category>captp</category>
  <category>e</category>
  <category>programming</category>
  <category>life</category>
  <category>gsoc</category>
  <category>gsoc2009</category>
  <category>caps</category>
  <lj:security>public</lj:security>
  <lj:reply-count>3</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/12730.html</guid>
  <pubDate>Thu, 26 Mar 2009 04:05:41 GMT</pubDate>
  <title>Ads</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/12730.html</link>
  <description>I just recently found out that LJ is displaying ads on my journal-or-blog-whichever — I hadn&apos;t previously noticed as it doesn&apos;t when I&apos;m logged in (which seems a bit deceptive). I had previously understood that with a basic account there would be no ads.&lt;br /&gt;&lt;br /&gt;Your opinion on the matter? Have the ads bothered you? Is there actually a way to turn them off that I haven&apos;t noticed? Should I find other hosting for my blog? &lt;br /&gt;&lt;br /&gt;(I expect most of my readers are actually via feeds and don&apos;t see them...)</description>
  <comments>http://kpreid.livejournal.com/12730.html</comments>
  <category>meta</category>
  <category>web site</category>
  <lj:security>public</lj:security>
  <lj:reply-count>3</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/12466.html</guid>
  <pubDate>Sat, 21 Mar 2009 15:46:39 GMT</pubDate>
  <title>Confused yet?</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/12466.html</link>
  <description>&lt;p&gt;While setting up my new laptop, I found this situation:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://switchb.org/kpreid/2009/kpreids.png&quot;&gt;&lt;img src=&quot;http://switchb.org/kpreid/2009/kpreids.png&quot; alt=&quot;I had three mounted volumes all named kpreid. Luckily, they were of different types so they could be distinguished by icon.&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/12466.html</comments>
  <category>irrelevant</category>
  <category>mac os x</category>
  <lj:security>public</lj:security>
  <lj:reply-count>2</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/12194.html</guid>
  <pubDate>Tue, 10 Mar 2009 10:49:19 GMT</pubDate>
  <title>Decloaking, part 1: stage of life</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/12194.html</link>
  <description>&lt;p&gt;Up until now, I&apos;ve pretty much had an Online Life and an Offline Life (not much of one), and not made any connections between them. It&apos;s time to change that.&lt;/p&gt;

&lt;p&gt;I&apos;m 25, and my current phase of the Standard Life Plan, in which I am running a bit late, is “college”. I am currently attending &lt;a href=&quot;http://www.mvcc.edu/&quot;&gt;Mohawk Valley Community College&lt;/a&gt; in New York, and planning to transfer to a four-year school, with the goal of a bachelor&apos;s degree in computer science.&lt;/p&gt;

&lt;p&gt;It&apos;s taken me far too long to get around to posting this. A short todo list of further items:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Update my web site.&lt;/li&gt;
  &lt;li&gt;Post about transfer.&lt;/li&gt;
  &lt;li&gt;Post about employment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(One of the reasons for this post is to provide context for if I later post something related to schoolwork; another is getting around to the third item on this list.)&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/12194.html</comments>
  <category>college</category>
  <category>life</category>
  <category>web site</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/11808.html</guid>
  <pubDate>Sat, 03 Jan 2009 19:40:21 GMT</pubDate>
  <title>A note on JavaScript method call semantics</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/11808.html</link>
  <description>&lt;p&gt;So. In JavaScript, an “object” is a set of “properties”: associations from strings to values. A method is just a property whose value is a function. Functions are called like “&lt;code&gt;foo()&lt;/code&gt;”, properties are accessed like “&lt;code&gt;bar.foo&lt;/code&gt;”, and methods are called like “&lt;code&gt;bar.foo()&lt;/code&gt;”. Looks straightforward enough, right?&lt;/p&gt;

&lt;p&gt;Now, how does a method access the state of its object? Without inheritance, you could just have the method functions of a given object all close over some variables; but JavaScript does have prototype inheritance, so the necessary access is provided by binding the variable “&lt;code&gt;this&lt;/code&gt;”, in the method body, to the object the method was invoked on.&lt;/p&gt;

&lt;p&gt;And when does &lt;code&gt;this&lt;/code&gt; happen? &lt;em&gt;When you use the method call syntax.&lt;/em&gt; &lt;code&gt;bar.foo()&lt;/code&gt; is not the same as&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;var m = bar.foo;
m();&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;(It is the same as &lt;code&gt;m.call(bar)&lt;/code&gt; — &lt;code&gt;call&lt;/code&gt; is a method on function objects which invokes them with &lt;code&gt;this&lt;/code&gt; bound — but that&apos;s beside the point.)&lt;/p&gt;

&lt;p&gt;So, the syntax is non-compositional.&lt;/p&gt;

&lt;p&gt;Not only that, but it is enthusiastically so: &lt;code&gt;bar.foo()&lt;/code&gt; is the same as &lt;code&gt;(bar.foo)()&lt;/code&gt; — the parentheses do not break up the method call construct!&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/11808.html</comments>
  <category>programming</category>
  <category>javascript</category>
  <lj:security>public</lj:security>
  <lj:reply-count>6</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/11554.html</guid>
  <pubDate>Thu, 30 Oct 2008 20:44:46 GMT</pubDate>
  <title>Database document software?</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/11554.html</link>
  <description>Something I&apos;ve wished for several times recently is a database-document program.&lt;br /&gt;&lt;br /&gt;By &quot;document&quot; I mean that the database is a single file, which I can move, copy, etc., as opposed to living in a database server which has to stay up, uses accounts and ACLs, needs special backup procedures, and so on. It doesn&apos;t need to support humongous data sets — fits-in-memory and even linear searches are fine.&lt;br /&gt;&lt;br /&gt;I am aware that people use spreadsheets for such purposes, but I would like to have named, typed, and homogeneous columns, easy sorting/filtering/querying, etc. which I assume I&apos;m not going to find there. Relational would be nice too.&lt;br /&gt;&lt;br /&gt;It must be GUI, and run on Mac OS X, but it doesn&apos;t have to be thoroughly native — I can stand the better sort of Java or perhaps even X11 app.&lt;br /&gt;&lt;br /&gt;And finally, it should have a file format that either is obvious how to parse, or has a specification, or is supported by many other programs.&lt;br /&gt;&lt;br /&gt;Does such a thing exist?&lt;br /&gt;&lt;br /&gt;(If not, I might write it.)</description>
  <comments>http://kpreid.livejournal.com/11554.html</comments>
  <category>programming</category>
  <category>programs</category>
  <category>mac os x</category>
  <category>data formats</category>
  <lj:security>public</lj:security>
  <lj:reply-count>13</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/11404.html</guid>
  <pubDate>Sat, 04 Oct 2008 14:36:57 GMT</pubDate>
  <title>A dreadful thing</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/11404.html</link>
  <description>&lt;pre&gt;&lt;var&gt;some type&lt;/var&gt; *foo;
size_t count = &lt;var&gt;...&lt;/var&gt;;

&lt;var&gt;...&lt;/var&gt;

foo = malloc(count * sizeof * foo);&lt;/pre&gt;</description>
  <comments>http://kpreid.livejournal.com/11404.html</comments>
  <category>c</category>
  <category>thoughts</category>
  <category>programming</category>
  <lj:security>public</lj:security>
  <lj:reply-count>15</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/11257.html</guid>
  <pubDate>Wed, 01 Oct 2008 21:28:41 GMT</pubDate>
  <title>Getting started with AVR microcontrollers (using C, free tools and no IDE)</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/11257.html</link>
  <description>&lt;p&gt;This is not a complete tutorial; it is intended to collect the information that I needed to get started and didn&apos;t find obvious, particularly explaining the operations needed to compile a program, and the most basic of syntax, operators, and IO operations to use microcontroller-specific operations from C/avr-gcc/avr-libc. It does not cover designing circuits or choosing a &lt;a href=&quot;http://en.wikipedia.org/wiki/Programmer_(hardware)&quot;&gt;programmer&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Needed software&lt;/h3&gt;

&lt;p&gt;Get avr-gcc, avr-binutils, &lt;a href=&quot;http://www.nongnu.org/avr-libc/&quot;&gt;avr-libc&lt;/a&gt;, and &lt;a href=&quot;http://www.nongnu.org/avrdude/&quot;&gt;avrdude&lt;/a&gt;. If you&apos;re on Mac OS X, all three are available through &lt;a href=&quot;http://www.macports.org/&quot;&gt;MacPorts&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Setup&lt;/h3&gt;

&lt;p&gt;Create &lt;tt&gt;&lt;a href=&quot;http://www.nongnu.org/avrdude/user-manual/avrdude_9.html#SEC9&quot;&gt;~/.avrduderc&lt;/a&gt;&lt;/tt&gt; to specify what kind of programmer you have and where it&apos;s connected. Mine looks like this:&lt;/p&gt;
&lt;pre&gt;  default_serial = &quot;/dev/cu.KeySerial1&quot;;
  default_programmer = &quot;stk500v1&quot;;&lt;/pre&gt;
  
&lt;p&gt;default_serial is the device for the serial port the programmer is attached to; default_programmer is the type of programmer; see &lt;a href=&quot;http://www.nongnu.org/avrdude/user-manual/avrdude_4.html#SEC4&quot;&gt;the manual section on command line options&lt;/a&gt; for programmer type names. You can also specify these on the command line, but I figure since these are specific to your computer it&apos;s better to leave them unspecified in makefiles.&lt;/p&gt;

&lt;h3&gt;Writing code&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;char&lt;/code&gt; is 8 bits and &lt;code&gt;int&lt;/code&gt; is 16.&lt;/li&gt;
&lt;li&gt;The entry point is the normal int main(void); you don&apos;t have to do any special initialization.&lt;/li&gt;
&lt;li&gt;Special registers are exposed as variables — e.g. &lt;code&gt;PORTD = 0&lt;/code&gt; to do output.&lt;/li&gt;
&lt;li&gt;All normal variables take up scarce RAM — for constant data, use the facilities in &amp;lt;avr/pgmspace.h&amp;gt; to store it in program space.&lt;/li&gt;
&lt;li&gt;Basic IO: Each port has three registers. For some port &lt;var&gt;x&lt;/var&gt;, DDR&lt;var&gt;x&lt;/var&gt; specifies direction: a 1 bit makes the corresponding pin an output, whereas 0 makes it an input. Reading PIN&lt;var&gt;x&lt;/var&gt; takes input from the pins; writing PORT&lt;var&gt;x&lt;/var&gt; sets output. If DDR&lt;var&gt;x&lt;/var&gt; has a 1 bit, then PORT&lt;var&gt;x&lt;/var&gt; controls internal pullups on those pins.&lt;/li&gt;
&lt;li&gt;For further info on the functions of the chip, read the datasheet for it; the translation into C is mostly straightforward.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;http://www.nongnu.org/avr-libc/user-manual/index.html&quot;&gt;avr-libc manual&lt;/a&gt; contains info on its avr-specific features.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;http://www.nongnu.org/avr-libc/user-manual/group__demos.html&quot;&gt;avr-libc demo projects&lt;/a&gt; are informative and well-explained.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Compiling&lt;/h3&gt;
&lt;pre&gt;  avr-gcc -mmcu=at90s8515 -Werror foo.c bar.c -o foo.elf&lt;/pre&gt;
&lt;p&gt;Substitute the part number of your target chip for &lt;tt&gt;at90s8515&lt;/tt&gt;. I use -Werror to reduce the chances I&apos;ll run broken code on real hardware.&lt;/p&gt;

&lt;pre&gt;  avr-objcopy -O ihex foo.elf foo.hex&lt;/pre&gt;
&lt;p&gt;This step discards the metadata the &lt;code&gt;.elf&lt;/code&gt; file contains, leaving just the code, suitable for programming.&lt;/p&gt;
  
&lt;h3&gt;Programming (downloading)&lt;/h3&gt;
  &lt;pre&gt;avrdude -p 8515 -U flash:w:foo.hex&lt;/pre&gt;
  &lt;p&gt;Substitute the part number of your target chip for &lt;tt&gt;8515&lt;/tt&gt;.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/11257.html</comments>
  <category>avr</category>
  <category>electronics</category>
  <category>timer project</category>
  <lj:security>public</lj:security>
  <lj:reply-count>2</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/10902.html</guid>
  <pubDate>Mon, 22 Sep 2008 23:34:31 GMT</pubDate>
  <title>Why you should idly browse Wikipedia</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/10902.html</link>
  <description>&lt;p&gt;I&apos;ve seen it said that one should not use &lt;a href=&quot;http://en.wikipedia.org/&quot;&gt;Wikipedia&lt;/a&gt; because at any given moment, a page might be wrong. But what&apos;s that error rate, versus the error rate of your own memory of miscellaneous not-significant-to-you-at-the-time information?&lt;/p&gt;

&lt;p&gt;If the latter is ≥ the former, then &lt;em&gt;even if&lt;/em&gt; Wikipedia is worthless for reliable information, it is still then useful to browse it &lt;a href=&quot;http://xkcd.com/214/&quot;&gt;randomly&lt;/a&gt;, or in a topic area of slight interest, because afterward you have increased your total knowledge while not increasing your error rate per fact.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/10902.html</comments>
  <category>thoughts</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/10678.html</guid>
  <pubDate>Sun, 31 Aug 2008 17:14:00 GMT</pubDate>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/10678.html</link>
  <description>&lt;p&gt;“Language-independent” just means they invented a new language.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/10678.html</comments>
  <category>thoughts</category>
  <category>programming</category>
  <category>data formats</category>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/10476.html</guid>
  <pubDate>Thu, 19 Jun 2008 14:09:03 GMT</pubDate>
  <title>Apple&apos;s Sampler file format, and SBCL SB-SPROF report generation</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/10476.html</link>
  <description>&lt;p&gt;Apple&apos;s Sampler is a profiler based on the principle of periodically collecting the entire call stack of the executing threads, then summarizing these stacks to show what occurs frequently; primarily, as a tree, rooted at the bottom of the stack, where each node shows the number of times that call sequence was found on the stack.

&lt;p&gt;&lt;a href=&quot;http://www.sbcl.org/&quot;&gt;SBCL&lt;/a&gt;&apos;s &lt;code&gt;&lt;a href=&quot;http://www.sbcl.org/manual/Statistical-Profiler.html&quot;&gt;sb-sprof&lt;/a&gt;&lt;/code&gt; is a profiler which also collects call stacks, but its summary report is much less useful to me as it does not provide the per-branch counting; just top-of-stack frequencies and a caller/callee graph.

&lt;p&gt;Therefore, I examined Sampler&apos;s file format and wrote code to generate it from &lt;code&gt;sb-sprof&lt;/code&gt;&apos;s record.

&lt;p&gt;&lt;a href=&quot;http://switchb.org/kpreid/2008/sb-sprof-in-sampler-window.png&quot;&gt;&lt;img src=&quot;http://switchb.org/kpreid/2008/sb-sprof-in-sampler-window.png&quot; alt=&quot;Screenshot of Sampler with SB-SPROF data&quot; style=&quot;max-width: 100%;&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The file is mixed text/binary, LF line endings. The grammar, as far as I&apos;ve determined it, is:

&lt;pre&gt;  &quot;@supersamplerV1.0&quot; LF
  &quot;@symboltableV1.1&quot; LF
  (TAB int32&amp;lt;id&amp;gt; TAB int32&amp;lt;unknown&amp;gt; 
   TAB text&amp;lt;symbol&amp;gt; 
   TAB text&amp;lt;library-path&amp;gt; TAB text&amp;lt;library-path&amp;gt; LF)*
  &amp;quot;@end&amp;quot; LF
  (
    &amp;quot;@threadV1.0&amp;quot; TAB int16Hex&amp;lt;thread-id&amp;gt; LF
    (
      TAB int32&amp;lt;1&amp;gt; int32&amp;lt;0&amp;gt; int32&amp;lt;1&amp;gt; int32&amp;lt;count of stack-frame&amp;gt; (int32&amp;lt;stack-frame&amp;gt;)* LF
    )*
  )*
  &quot;@end&quot; LF&lt;/pre&gt;
  
&lt;p&gt;where by &quot;int32&quot; I mean a big-endian 32-bit (unsigned?) integer (i.e. four not-necessarily-ASCII bytes), and by &quot;int16Hex&quot; I mean a 16-bit integer in hexadecimal (i.e. four ASCII bytes).

&lt;p&gt;&quot;id&quot; is an arbitrary identifier for this symbol. &quot;unknown&quot; is occasionally nonzero, but I don&apos;t know what it means. &quot;symbol&quot; is the name of a function/method found on the stack. &quot;library-path&quot; is the pathname to the object file it was loaded from (relative in the case of a standard framework, e.g. &quot;Carbon.framework/HIToolbox.framework/HIToolbox&quot;).

&lt;p&gt;&quot;thread-id&quot; is an identifier for the thread, which should occur as an &quot;id&quot; in the symbol table; the upper 16 bits evidently must be 0. Thread symbol table entries have a name and library path which is the string (&quot;Thread_&quot; int16&amp;lt;thread-id&amp;gt;); I have not confirmed whether this is necessary.

&lt;p&gt;Each entry in a @thread block is one sampling of the whole stack of that thread. I do not know what the 1, 0, and 1 mean, but the fourth integer is the number of frames on the stack; immediately after are that many integers, each of which is an id from the symbol table.

&lt;p&gt;Files generated from this structure are accepted by Sampler, but not always by &lt;a href=&quot;http://developer.apple.com/tools/performance/&quot;&gt;Shark&lt;/a&gt;; I don&apos;t know why, and my attempt at tracking it down made it seem to depend on the &lt;em&gt;size&lt;/em&gt; of the trace file.&lt;/p&gt;

&lt;p&gt;Here is code to generate such a file from sb-sprof data; it should be loaded in the &lt;code&gt;SB-SPROF&lt;/code&gt; package:

&lt;a name=&quot;cutid1&quot;&gt;&lt;/a&gt;
&lt;pre&gt;  (defun write-32 (index stream)
    (write-byte (ldb (byte 8 24) index) stream)
    (write-byte (ldb (byte 8 16) index) stream)
    (write-byte (ldb (byte 8 8) index) stream)
    (write-byte (ldb (byte 8 0) index) stream))

  (defun write-sampler-data (stream)
    (format stream &amp;quot;~&amp;amp;@supersamplerV1.0~%&amp;quot;)
    (format stream &amp;quot;~&amp;amp;@symboltableV1.1~%&amp;quot;)
    (let ((symbols (make-hash-table :test &amp;apos;equal))
          (buffer))
      (loop with gen = #x00002121
            for i below (- (samples-index *samples*) 2) by 2
            for debug-info = (aref (samples-vector *samples*) i)
            do (unless (or (member debug-info &amp;apos;(trace-start))
                           (gethash debug-info symbols))
                 (let ((index (incf gen)))
                   (setf (gethash debug-info symbols) index)
                   (write-char #\Tab stream)
                   (write-32 index stream)
                   (write-char #\Tab stream)
                   (write-32 0 stream)
                   (let* ((*print-right-margin* nil)
                          (*print-miser-width* nil)
                          (name (princ-to-string 
                                  (if debug-info
                                    (node-name (make-node debug-info))
                                    (format nil &amp;quot;Thread&amp;quot;))))
                          (real-info
                           (when (typep debug-info &amp;apos;sb-di::compiled-debug-fun)
                             (sb-di::compiled-debug-fun-debug-info debug-info)))
                          (source
                           (when real-info
                             (sb-c::debug-info-source real-info)))
                          (pathname
                            (when (and source
                                       (eql (sb-c::debug-source-from source) :file))
                              (sb-c::debug-source-name source))))
                     (nsubstitute #\/ #\Newline name)
                     (format stream &amp;quot;~C~A~C~A~C~A~%&amp;quot;
                             #\Tab name
                             #\Tab pathname
                             #\Tab pathname)))))
      (format stream &amp;quot;~&amp;amp;@threadV1.0~C~4,&amp;apos;0X~%&amp;quot; #\Tab (gethash nil symbols))
      (flet ((out ()
               (when buffer
                 (write-char #\Tab stream)
                 (write-32 1 stream)
                 (write-32 0 stream)
                 (write-32 1 stream)
                 (write-32 (length buffer) stream)
                 (dolist (sym buffer)
                   (write-32 sym stream))
                 (terpri stream)
                 (setf buffer nil))))
        (loop for i downfrom (- (samples-index *samples*) 2) to 0 by 2
              for debug-info = (aref (samples-vector *samples*) i)
              do (cond
                   ((eql debug-info &amp;apos;trace-start)
                    (out))
                   (t
                    (push (or (gethash debug-info symbols)
                              (error &amp;quot;No symbol assigned to ~S&amp;quot; debug-info))
                          buffer))))
        (out)))
    (format stream &amp;quot;~&amp;amp;@end~%&amp;quot;))&lt;/pre&gt;

&lt;p&gt;Usage:
&lt;pre&gt;(with-open-file (s &quot;sampler.trace&quot; :direction :output 
                                   :element-type :default
                                   :if-exists :supersede)
  (sb-sprof::write-sampler-data s))&lt;/pre&gt;



&lt;p&gt;This code generates a noninteractive Sampler-style tree report from SB-SPROF data.

&lt;a name=&quot;cutid2&quot;&gt;&lt;/a&gt;
&lt;pre&gt;  (defun make-bucket ()
    (list 0 (make-hash-table :test &apos;equal)))

  (defun put (bucket name)
    (let ((h (second bucket)))
      (or (gethash name h)
          (setf (gethash name h) (make-bucket)))))

  (defun build-tree ()
    (loop with root = (make-bucket)
          with current = (list root)
          for i downfrom (- (samples-index *samples*) 2) to 0 by 2
          for debug-info = (aref (samples-vector *samples*) i)
          do (cond
               ((eql debug-info &apos;trace-start)
                (dolist (bucket current)
                  (incf (first bucket)))
                (setf current (list root)))
               (t
                (let ((name (node-name (make-node debug-info)) #|kludge|#))
                  (push (put (first current) name) current))))
          finally (return root)))

  (defun twiddle-tree (bucket)
    (let (entries)
      (maphash (lambda (k v) (push (list* :i k (twiddle-tree v)) entries))
               (second bucket))
      (list (first bucket) entries)))&lt;/pre&gt;

&lt;p&gt;(Usage for printing a report: &lt;code&gt;(twiddle-tree (build-tree))&lt;/code&gt;.)&lt;/p&gt;
</description>
  <comments>http://kpreid.livejournal.com/10476.html</comments>
  <category>shark</category>
  <category>programming</category>
  <category>sbcl</category>
  <category>lisp</category>
  <category>mac os x</category>
  <category>programs</category>
  <category>optimization</category>
  <category>sampler</category>
  <category>sb-sprof</category>
  <category>data formats</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/10037.html</guid>
  <pubDate>Fri, 30 May 2008 03:05:13 GMT</pubDate>
  <title>Re: Zippers</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/10037.html</link>
  <description>&lt;p&gt;For those wondering about &lt;a href=&quot;http://kpreid.livejournal.com/9816.html&quot;&gt;the problem I was trying to solve with a zipper&lt;/a&gt;: After all the advice and some consideration, I decided to go with “option #2”: a whole-tree processing step which adds equal labels to corresponding variable uses and bindings. I’ve implemented all of the analysis I described in the original post using this system.&lt;/p&gt;

&lt;p&gt;(However, the code isn&apos;t quite finished (as I discovered some problems with a different aspect of it) so it&apos;s not in any public repository yet.)&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/10037.html</comments>
  <category>auditors</category>
  <category>e</category>
  <category>programming</category>
  <category>zippers</category>
  <category>haskell</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/9816.html</guid>
  <pubDate>Sun, 04 May 2008 14:02:52 GMT</pubDate>
  <title>Zippers for evaluation and program analysis</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/9816.html</link>
  <description>&lt;p&gt;It occurs to me that there is a similarity between a &lt;a href=&quot;http://www.haskell.org/haskellwiki/Zipper&quot;&gt;zipper&lt;/a&gt; and the combination of an expression and an environment, as for evaluation. I&apos;ve got a problem that seems almost solvable by use of this, and I would especially like to hear Planet Haskell readers&apos; thoughts on the matter.

&lt;p&gt;(The expressions given here are in &lt;a href=&quot;http://www.erights.org/&quot;&gt;E&lt;/a&gt; syntax.)

&lt;p&gt;For example, let&apos;s start with the expression

&lt;pre&gt;  def x := 74
  x + 1&lt;/pre&gt;

&lt;p&gt;For those unfamiliar with &lt;a href=&quot;http://www.erights.org/&quot;&gt;E&lt;/a&gt;, the tree this expression parses into has structure like this (ignoring some extra features and names):
  
&lt;pre&gt;  sequence(define(var(&quot;x&quot;), literal(74)),
           call(var(&quot;x&quot;), &quot;add&quot;, literal(1)))&lt;/pre&gt;

&lt;p&gt;If we move “down” zipperwise into the second subexpression of the sequence, then  we get the &lt;em&gt;expression&lt;/em&gt; “&lt;code&gt;x + 1&lt;/code&gt;” with the &lt;em&gt;context&lt;/em&gt; “&lt;code&gt;def x := 74&lt;/code&gt; before this in a &lt;code&gt;sequence&lt;/code&gt;”. Similarly, an interpreter uses an intermediate result of “&lt;code&gt;x + 1&lt;/code&gt;”, “&lt;code&gt;x&lt;/code&gt; is bound to &lt;code&gt;74&lt;/code&gt;”.
  
&lt;hr&gt;

&lt;p&gt;With a slightly extended context, I&apos;m trying to use this to express program analysis in an &lt;a href=&quot;http://www.erights.org/elang/kernel/auditors/&quot;&gt;auditor&lt;/a&gt;. The zipper context now tracks a small amount of information about variables, as well as the enclosing expressions.

&lt;p&gt;The first problem is to determine that all occurrences of a given variable are used in a particular fashion: e.g. for &lt;var&gt;f&lt;/var&gt;, permitting “&lt;code&gt;f(1)&lt;/code&gt;” but not “&lt;code&gt;f(&quot;foo&quot;)&lt;/code&gt;” or “&lt;code&gt;somethingElse(f)&lt;/code&gt;” (where the third case would permit &lt;var&gt;f&lt;/var&gt; to be used arbitrarily since the auditor doesn&apos;t get to see somethingElse’s code). This is easily accomplished by walking the entire expression looking for occurrences of &lt;code&gt;var(&quot;f&quot;)&lt;/code&gt;, and walking “up” from each of those occurrences to check that the enclosing expressions form a permitted usage.

&lt;p&gt;The second problem is to determine that the variable in a particular position is a free variable, and that its &lt;a href=&quot;http://wiki.erights.org/wiki/Guard-based_auditing&quot;&gt;guard&lt;/a&gt; is of a particular form. This can be done by extending the context objects to record what variable names are bound by any expression &lt;em&gt;preceding&lt;/em&gt; the current location (that is not inside its own block); thus walking up the contexts to the top-level determines whether the variable is free.

&lt;p&gt;The third problem, I&apos;m not sure what to do about. I have a situation roughly like this:

&lt;pre&gt;  def foo {
    method a() {
      def bar {
        method b() { foo }
      }
    }
  }&lt;/pre&gt;
  
&lt;pre&gt;  object(var(&quot;foo&quot;),
         method(&quot;a&quot;, object(var(&quot;bar&quot;), 
                            method(&quot;b&quot;, var(&quot;foo&quot;)))))&lt;/pre&gt;

&lt;p&gt;As part of the first problem, I have found the object “bar”; I then walk upward to determine that it is generated by a method of the object “foo”. (There are additional constraints on the structure that I haven&apos;t mentioned.) I need to determine that the reference to “foo” in “b” is in fact to the outer object, and not to some other intervening lexical binding.

&lt;p&gt;I&apos;ve thought of two possible solutions so far:
&lt;ol&gt;
  &lt;li&gt;Starting from &lt;code&gt;method(&quot;a&quot;, ...)&lt;/code&gt;, scan its children for occurrences of &lt;code&gt;var(&quot;foo&quot;)&lt;/code&gt; and reject any which bind it. This would reject more than it needs to.&lt;/li&gt;
  &lt;li&gt;Switch to a pre-processing stage (instead of the incremental operation of a zipper) to assign an identity (or a mutable analysis-information field, equivalently) to each variable binding &lt;em&gt;and all of its uses&lt;/em&gt;, and add upward references (like in the zipper) to each node; this would make the is-this-foo-that-foo test a simple comparison.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At the moment, the second option seems attractive; tying uses to definitions of variables in a generic fashion should be useful for other types of analysis. And since this is strictly analysis, not transformation, I don&apos;t need the modify-without-mutation function of a zipper. The only reason I haven&apos;t done that yet is I think zippers are neat (and there might be other uses for an established zipper over E ASTs).

&lt;p&gt;What do you think I should do?</description>
  <comments>http://kpreid.livejournal.com/9816.html</comments>
  <category>auditors</category>
  <category>e</category>
  <category>programming</category>
  <category>zippers</category>
  <category>haskell</category>
  <lj:security>public</lj:security>
  <lj:reply-count>8</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/9604.html</guid>
  <pubDate>Tue, 05 Feb 2008 15:19:11 GMT</pubDate>
  <title>Portal (on a Mac)</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/9604.html</link>
  <description>&lt;p&gt;I found out that you can play &lt;a href=&quot;http://en.wikipedia.org/wiki/Portal_(video_game)&quot;&gt;Portal&lt;/a&gt; on a Mac without installing Windows using &lt;a href=&quot;http://www.codeweavers.com/products/cxmac/&quot;&gt;CrossOver Mac&lt;/a&gt;. Yay.&lt;/p&gt;

&lt;a name=&quot;cutid1&quot;&gt;&lt;/a&gt;
&lt;p&gt;It works fine with minor glitches, except that on the MacBook I have access to, level 19 (the last main-sequence level) appears nearly completely obscured by blue fog. I have not found any solution for this yet, though I&apos;ve seen &lt;a href=&quot;http://forums.macrumors.com/showthread.php?t=418295&quot;&gt;a report of success&lt;/a&gt;. (The launch option &lt;code&gt;-dxlevel 70&lt;/code&gt; works for Half-Life 2 (which uses the same engine), but is incompatible with Portal.) Level 19 works fine on an iMac.&lt;/p&gt;

&lt;p&gt;The worst of the minor glitches was that the first time, it started up in full-screen with the image shifted down and right by half the screen size.&lt;/p&gt;

&lt;p&gt;Changing the display options to some other resolution will straighten it out, but the glitch put the Options menu item off-screen. I found that the menu could be accessed by keyboard, and guessed correctly that Options would be the second-from-last option. So, highlight the first option, up arrow twice, return. Then drag the options subwindow by its edge to get to the controls.&lt;/p&gt;

&lt;p&gt;Oh, and the game?&lt;/p&gt;



&lt;p&gt;Portal is great.&lt;/p&gt;

&lt;p&gt;I especially liked the moments of &lt;i&gt;stare at layout baffled ... OH! ... portal-portal-portal-ding!&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;A bit of advice: Don&apos;t go on YouTube and watch a bunch of videos. There are only 19 levels (25 if you count the advanced maps, which are modifications of 6 of the regular ones), and having several of them spoiled was a bit disappointing.&lt;/p&gt;

&lt;p&gt;I haven&apos;t tried any third-party maps. (Got recommendations?)&lt;/p&gt;

&lt;p&gt;Oh, and one tip: when bouncing through a pair of floor portals and trying to aim at something, be looking straight up or down when you pass through the portal — that way, the game won&apos;t reorient you while you&apos;re trying to aim.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/9604.html</comments>
  <category>windows</category>
  <category>portal</category>
  <category>games</category>
  <category>mac os x</category>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/9431.html</guid>
  <pubDate>Sat, 08 Dec 2007 21:40:46 GMT</pubDate>
  <title>The Electronic Goldmine</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/9431.html</link>
  <description>&lt;p&gt;I recently purchased some items from &lt;a href=&quot;http://www.goldmine-elec-products.com/&quot;&gt;The Electronic Goldmine&lt;/a&gt;. I placed the order on December 2 (Sunday); it arrived at my post office box December 7 (Friday). The box was large and the contents were well-padded; I think it could safely have been smaller.&lt;/p&gt;

&lt;a name=&quot;cutid1&quot;&gt;&lt;/a&gt;
&lt;p&gt;On the quality and details of the contents:&lt;/p&gt;

&lt;dl&gt;
  &lt;dt&gt;&lt;a href=&quot;http://www.goldmine-elec-products.com/prodinfo.asp?number=G15698&quot;&gt;G15698 “5.5&quot; x 12&quot; Scissor Cut SS Copper Clad”&lt;/a&gt; $1.75&lt;/dt&gt;
  &lt;dd&gt;Looks like it got kicked around a bit: scratches, scuffs, grunge, and dark spots that might be dirt or pits; I haven&apos;t unbagged it yet.&lt;/dd&gt;
  &lt;dt&gt;&lt;a href=&quot;http://www.goldmine-elec-products.com/prodinfo.asp?number=GP59&quot;&gt;GP59 “Small Mono Capacitors”&lt;/a&gt; $2.49&lt;/dt&gt;
  &lt;dd&gt;Not quite as described and depicted. The leads are 1&quot; rather than 1⁄2&quot; long. All have leads exiting with .1&quot; spacing, but most of them are bent into .2&quot; spacing.&lt;/dd&gt;
  &lt;dt&gt;&lt;a href=&quot;http://www.goldmine-elec-products.com/prodinfo.asp?number=G16567&quot;&gt;G16567 “EIC-801 Solderless Breadboard 400 Contact”&lt;/a&gt; $4.49&lt;/dt&gt;
  &lt;dd&gt;No surprises, but note that the &quot;distribution strip&quot; is at a half-step offset from the &quot;terminal strip&quot; grid. The spacing between the distribution strip and the terminal strip sockets is an even .3&quot; (two empty rows), however. The strips appear to be separable and interlocked, and are joined on the bottom with a pad of what appears to be double-sided foam tape.&lt;/dd&gt;
  &lt;dt&gt;&lt;a href=&quot;http://www.goldmine-elec-products.com/prodinfo.asp?number=G8534&quot;&gt;G8534 “Large Universal Breadboard”&lt;/a&gt; $6.75&lt;/dt&gt;
  &lt;dd&gt;The design is almost identical to the G16567, and they came in similar packaging (EIC branded); however, the attachment pegs/notches on the sides are not compatible. Unlike the photo, the distribution strips are marked in red and blue.&lt;/dd&gt;
  &lt;dt&gt;&lt;a href=&quot;http://www.goldmine-elec-products.com/prodinfo.asp?number=G16562&quot;&gt;G16562 “Microtips Technology MTC-S16204A LCD Display w/Backlight”&lt;/a&gt; $3.95&lt;/dt&gt;
  &lt;dd&gt;Looks new; haven&apos;t tested it yet. The pins fit into a breadboard as expected.&lt;/dd&gt;
  &lt;dt&gt;&lt;a href=&quot;http://www.goldmine-elec-products.com/prodinfo.asp?number=G2200&quot;&gt;G2200 “Electronic Surprise Box”&lt;/a&gt; $3.25&lt;/dt&gt;
  &lt;dd&gt;I haven&apos;t unpacked this, as I do not yet have containers to sort it into. The box is about a 4&quot; cube (inside), and reasonably well filled. The items I&apos;ve spotted on top are:&lt;ul&gt;
    &lt;li&gt;3 &amp;times; 6.5V 8800µF electrolytic capacitors
    &lt;li&gt;1 &amp;times; large non-electrolytic capacitor
    &lt;li&gt;2 &amp;times; rectangular-ceramic-cased power resistors

    &lt;li&gt;many resistors, on tapes
    &lt;li&gt;many small glass diodes, loose
    &lt;li&gt;3 &amp;times; not-yet-identified TO-92-package device
    &lt;li&gt;1 &amp;times; not-yet-identified IC (bent leads)
    &lt;li&gt;1 &amp;times; LED

    &lt;li&gt;3 &amp;times; paired &quot;N/R&quot; 14V indicator lamps, incandescent, panel-mount
    &lt;li&gt;4 &amp;times; 125V indicator lights
    &lt;li&gt;3 &amp;times; thermal cutout fuses

    &lt;li&gt;3 &amp;times; headers, 2&amp;times;?? pins

    &lt;li&gt;4 &amp;times; stick-on rubber feet
    &lt;li&gt;2 &amp;times; stick-on cable clips
    &lt;/ul&gt;&lt;/dd&gt;
  &lt;dt&gt;&lt;a href=&quot;http://www.goldmine-elec-products.com/prodinfo.asp?number=GP27&quot;&gt;GP27 “LED Mixture 1”&lt;/a&gt; $2.49&lt;/dt&gt;
  &lt;dd&gt;All the non-surface-mount ones are working and in good condition. 5 were surface mount, packed in a plastic strip; I did not open it to test them. 3 are in plastic right-angle frames like in the photo of &lt;a href=&quot;http://www.goldmine-elec-products.com/prodinfo.asp?number=GP43&quot;&gt;GP43&lt;/a&gt;; 10 are in frames which have the leads folded back underneath as if for surface mount or plug-in use. These frames could probably be removed by straightening the leads. 9 are rectangular, and 23 are round (various sizes, mostly 5mm).&lt;/dd&gt;
  &lt;dt&gt;&lt;a href=&quot;http://www.goldmine-elec-products.com/prodinfo.asp?number=G1498&quot;&gt;G1498 “Test Clips With Wire”&lt;/a&gt; $1.99&lt;/dt&gt;
  &lt;dd&gt;All tested and working; however, removing one of the insulating sleeves shows that the wires are attached merely by folding the conductor back over the insulation and crimping the clip on. No idea whether this is adequate in the long term. Some of the sleeves are quite slippery (fresh plastic), such that squeezing the clip fully open tends to result in it slipping out of the sleeve; shouldn&apos;t be a problem for normal use. The wires are quite flexible; nearly limp. Package branding is &quot;SE&quot;.&lt;/dd&gt;
&lt;/dl&gt;
</description>
  <comments>http://kpreid.livejournal.com/9431.html</comments>
  <category>electronics</category>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/9066.html</guid>
  <pubDate>Thu, 29 Nov 2007 04:57:15 GMT</pubDate>
  <title>If your MacBook&apos;s nonexistent Num Lock is stuck, check Mouse Keys</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/9066.html</link>
  <description>&lt;p&gt;Bought a new MacBook with Leopard installed and used Migration Assistant (transferring from an iBook G3). Upon logging in to the primary account, the letter and number keys, Return, and some others stopped working. Returning to the login window, they continued to not work (as tested in the password-entry field) except for the Num-lock number pad region (which seemed strange, since this keyboard doesn&apos;t have a num-lock key or keypad markings). An external full USB keyboard worked normally.&lt;/p&gt;

&lt;p&gt;The fix that worked (found in a web search) was to disable Mouse Keys (in Universal Access preferences).&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/9066.html</comments>
  <category>mac os x</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://kpreid.livejournal.com/8775.html</guid>
  <pubDate>Sun, 07 Oct 2007 16:34:26 GMT</pubDate>
  <title>Timer project: sound generation</title>
  <author>kpreid@mac.com</author>  <link>http://kpreid.livejournal.com/8775.html</link>
  <description>&lt;p&gt;One of the requirements for &lt;a href=&quot;http://switchb.org/kpreid/2007/timer/&quot;&gt;the timer project&lt;/a&gt; is that the alarm sound be not too unpleasant.&lt;/p&gt;

&lt;p&gt;So: What can I do with the current prototype hardware, a piezo element taken from a watch connected directly to a (digital) output pin on the PIC?&lt;/p&gt;

&lt;p&gt;Trivially, fixed-volume square waves, by either toggling the output pin in software or setting up the PIC&apos;s PWM feature to drive it automatically. (Note that the PWM produces a minimum frequency of 1/16384 of the main oscillator.)&lt;/p&gt;

&lt;p&gt;(I&apos;ve moved the piezo output on the prototype to the RC2/CCP1 pin. This change is not yet reflected in the published circuit and program.)&lt;/p&gt;

&lt;p&gt;However, I want software volume control, so I tried something more elaborate. I set the PWM to a very high frequency, and produce the audio-frequency signal by varying the PWM&apos;s duty cycle parameter. The characteristics of the piezo crystal filter out the high frequency, producing an effectively analog output.&lt;/p&gt;

&lt;p&gt;After much twiddling getting this to work (CCPR1L is &lt;em&gt;not&lt;/em&gt; the least-significant bits of the duty cycle), I found that square waves work well, sine waves are very quiet, and changing the amplitude has the expected effect. So while it won&apos;t sound great, I can at least program it to increase the volume gradually.&lt;/p&gt;

&lt;p&gt;I haven&apos;t yet integrated this into the main timer program, so I don&apos;t know whether I&apos;ll be able to produce decent tones despite (or making use of) the timer program&apos;s counting interrupt.&lt;/p&gt;</description>
  <comments>http://kpreid.livejournal.com/8775.html</comments>
  <category>audio</category>
  <category>electronics</category>
  <category>timer project</category>
  <lj:security>public</lj:security>
  <lj:reply-count>2</lj:reply-count>
</item>
</channel>
</rss>
