<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Blog-O! (Posts about scheme)</title><link>https://bwinton.github.io/weblog.latte.ca/</link><description></description><atom:link rel="self" href="https://bwinton.github.io/weblog.latte.ca/tags/scheme.xml" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 13 Apr 2019 21:03:25 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Some notes on cross-compiling GambitC</title><link>https://bwinton.github.io/weblog.latte.ca/blake/tech/iTouch/gambit/</link><dc:creator>Blake Winton</dc:creator><description>&lt;div&gt;&lt;p&gt;The command to use is:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;$ env &lt;span class="nv"&gt;CC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/local/bin/arm-apple-darwin-gcc &lt;span class="nv"&gt;CC_FOR_BUILD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;gcc ./configure --host&lt;span class="o"&gt;=&lt;/span&gt;mac&lt;span class="p"&gt;;&lt;/span&gt; make
&lt;/pre&gt;


&lt;p&gt;Well, kind of.  First you do that, then you copy gsc/gsc to gsc/gsc.onboard,
then you go to a new directory, and type:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;$ ./configure&lt;span class="p"&gt;;&lt;/span&gt;make
&lt;/pre&gt;


&lt;p&gt;and copy the gsc/gsc from that directory into the first directory.&lt;/p&gt;
&lt;p&gt;To compile a script into an exe:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;$ gsc/gsc -:&lt;span class="o"&gt;=&lt;/span&gt;. -c euler.scm
$ gsc/gsc -:&lt;span class="o"&gt;=&lt;/span&gt;. -link euler.c
$ /usr/local/bin/arm-apple-darwin-gcc euler.c euler_.c -Iinclude -Llib -lgambc -o euler
&lt;/pre&gt;


&lt;p&gt;It's freaking huge!&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;$ ls -alh euler
-rwxr-xr-x   &lt;span class="m"&gt;1&lt;/span&gt; bwinton  bwinton  4M Jan &lt;span class="m"&gt;23&lt;/span&gt; &lt;span class="m"&gt;14&lt;/span&gt;:22 euler
$ ls -alh /WifiToggle
-rwxr-xr-x   &lt;span class="m"&gt;1&lt;/span&gt; bwinton  bwinton  17K Jan &lt;span class="m"&gt;16&lt;/span&gt; &lt;span class="m"&gt;14&lt;/span&gt;:07 /WifiToggle
&lt;/pre&gt;


&lt;p&gt;And it's not a lot faster.
0.1643 seconds for the compiled version, as opposed to 0.1803 seconds for the interpreter. &lt;/p&gt;
&lt;p&gt;But on my Mac:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;$ more m1.c
power_of_2 &lt;span class="o"&gt;(&lt;/span&gt;int x&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;lt&lt;span class="p"&gt;;&amp;amp;&lt;/span&gt;lt&lt;span class="p"&gt;;&lt;/span&gt;x&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
$ more m2.scm
&lt;span class="o"&gt;(&lt;/span&gt;c-declare &lt;span class="s2"&gt;"extern int power_of_2 ();"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;(&lt;/span&gt;define pow2 &lt;span class="o"&gt;(&lt;/span&gt;c-lambda &lt;span class="o"&gt;(&lt;/span&gt;int&lt;span class="o"&gt;)&lt;/span&gt; int &lt;span class="s2"&gt;"power_of_2"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="o"&gt;(&lt;/span&gt;define &lt;span class="o"&gt;(&lt;/span&gt;twice x&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;cons x x&lt;span class="o"&gt;))&lt;/span&gt;
$ more m3.scm
&lt;span class="o"&gt;(&lt;/span&gt;write &lt;span class="o"&gt;(&lt;/span&gt;map twice &lt;span class="o"&gt;(&lt;/span&gt;map pow2 &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="o"&gt;))))&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;newline&lt;span class="o"&gt;)&lt;/span&gt;
$ gsc/gsc -:&lt;span class="o"&gt;=&lt;/span&gt;. -link -flat -o foo.o1.c m2 m3
$ /usr/local/bin/arm-apple-darwin-gcc -Iinclude -bundle -D___DYNAMIC m1.c m2.c m3.c foo.o1.c -o foo.o1
$ ls -alh foo.o1
-rwxr-xr-x   &lt;span class="m"&gt;1&lt;/span&gt; bwinton  bwinton    13K Jan &lt;span class="m"&gt;23&lt;/span&gt; &lt;span class="m"&gt;14&lt;/span&gt;:45 foo.o1
&lt;/pre&gt;


&lt;p&gt;then on the iTouch,&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;# scp bwinton@latte.ca:/Users/bwinton/Programming/Bazaar/iTouch/gambc-v4_1_2/foo.o1 .
# gsi foo.o1
((2 . 2) (4 . 4) (8 . 8) (16 . 16))
# gsi
Gambit v4.1.2

&amp;amp;gt; (load "foo")
((2 . 2) (4 . 4) (8 . 8) (16 . 16))
"/private/var/root/foo.o1"
&amp;amp;gt; (twice 5)
(5 . 5)
&amp;amp;gt; (pow2 10)
1024
&lt;/pre&gt;&lt;/div&gt;</description><category>gambit</category><category>itouch</category><category>scheme</category><guid>https://bwinton.github.io/weblog.latte.ca/blake/tech/iTouch/gambit/</guid><pubDate>Fri, 12 Dec 2008 22:09:47 GMT</pubDate></item><item><title>An odd restriction</title><link>https://bwinton.github.io/weblog.latte.ca/blake/tech/scheme/backtick/</link><dc:creator>Blake Winton</dc:creator><description>&lt;div&gt;&lt;p&gt;As &lt;a href="http://weblog.latte.ca/blake/tech/iTouch/languages.html"&gt;I mentioned&lt;/a&gt; before, I’ve
ported Gambit Scheme to my iTouch, and have been playing around with
it a little.  It’s pretty nice all in all, but I recently ran into a
small problem while I was trying to play around with macros.  The
problem?  There’s no way to enter a backtick (`) on the iTouch!  That
means that I don’t really have a way to write code like&lt;/p&gt;
&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;`&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;which makes writing macros a lot more painful.  Fortunately, I got a
lot of help from the people on &lt;a href="irc://irc.freenode.net/gambit"&gt;IRC&lt;/a&gt;
and on the &lt;a href="https://webmail.iro.umontreal.ca/pipermail/gambit-list/"&gt;Gambit mailing list&lt;/a&gt;.
Specifically, Marc Feeley, the author of Gambit, &lt;a href="https://webmail.iro.umontreal.ca/pipermail/gambit-list/2008-February/002011.html"&gt;posted&lt;/a&gt;
a snippet of code that I could put into my .gambcini file that would
add $ as a synonym for `.  The code looked like this:&lt;/p&gt;
&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6
7&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;begin&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;##&lt;/span&gt;&lt;span class="nv"&gt;readtable-char-class-set!&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;current-readtable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="sc"&gt;#\$&lt;/span&gt;  &lt;span class="c1"&gt;;; the character to dispatch on&lt;/span&gt;
    &lt;span class="no"&gt;#t&lt;/span&gt;   &lt;span class="c1"&gt;;; this character is a delimiter&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;re&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;##&lt;/span&gt;&lt;span class="nv"&gt;read-quotation&lt;/span&gt; &lt;span class="nv"&gt;re&lt;/span&gt; &lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;  &lt;span class="c1"&gt;;; handler&lt;/span&gt;
  &lt;span class="no"&gt;#f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;and the example, which works, is:&lt;/p&gt;
&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;output:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;If you’re trying to write that code on your iTouch, you might notice that it
includes the forbidden `, and so you’re once again out of luck.  Except that
in this case, you can replace #\` with #\u0060, which you can type in on the
iTouch, and then it’ll all work.&lt;/p&gt;&lt;/div&gt;</description><category>gambit</category><category>itouch</category><category>macros</category><category>scheme</category><guid>https://bwinton.github.io/weblog.latte.ca/blake/tech/scheme/backtick/</guid><pubDate>Wed, 09 Apr 2008 14:20:43 GMT</pubDate></item><item><title>More stuff on the iTouch.</title><link>https://bwinton.github.io/weblog.latte.ca/blake/tech/iTouch/languages/</link><dc:creator>Blake Winton</dc:creator><description>&lt;p&gt;Yeah, like I was done messing with my iTouch.  Whatever.&lt;/p&gt;

&lt;p&gt;I've been playing around a lot with the iTouch, and developing
quite a few programs for it.  The first one was by request, although
I’m also finding it very useful.  (And apparently a &lt;a href="http://forums.macrumors.com/showthread.php?p=4754458"&gt;few other
people&lt;/a&gt; are as well!  Cool!)  It’s called &lt;a href="http://www.csse.uwa.edu.au/~chris/iphone/WifiToggle/"&gt;WifiToggle&lt;/a&gt;, and it’s a small app that simply toggles on and off
your Wifi connection, so as to save batteries.  The next thing I did
was &lt;a href="http://iphone.latte.ca/info/Javascript.html"&gt;a port&lt;/a&gt;
of the &lt;a href="http://www.mozilla.org/js/spidermonkey/"&gt;SpiderMonkey
Javascript&lt;/a&gt; interpreter.  It works, and it wasn’t that hard to get
compiled and installed, which is really pretty cool when you stop to
think about it.&lt;/p&gt;

&lt;p&gt;The final thing I got working just tonight (which I was playing
around with mostly to take my mind off of stuff.  See tomorrow’s post
for details), was &lt;a href="http://iphone.latte.ca/info/GambitScheme.html"&gt;a port&lt;/a&gt; of the
&lt;a href="http://www.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page"&gt;Gambit Scheme&lt;/a&gt; interpreter.  I know, Scheme is just like
Javascript, only with an uglier syntax, but I still like it, and
hopefully the lack of punctuation will make it easier to use on the
iTouch.  Heh.&lt;/p&gt;

&lt;p&gt;Anyways, if you own an iPhone or iTouch, and have jailbroken it, be
sure to add &lt;a href="http://iphone.latte.ca/"&gt;http://iphone.latte.ca/&lt;/a&gt; to your list of Installer sources, and
geek out!&lt;/p&gt;</description><category>itouch</category><category>javascript</category><category>languages</category><category>scheme</category><guid>https://bwinton.github.io/weblog.latte.ca/blake/tech/iTouch/languages/</guid><pubDate>Sat, 19 Jan 2008 02:06:51 GMT</pubDate></item><item><title>Isn't that just the way of it...</title><link>https://bwinton.github.io/weblog.latte.ca/blake/tech/scheme/zip/</link><dc:creator>Blake Winton</dc:creator><description>&lt;div&gt;&lt;p&gt;I mentioned in the previous entry that I was missing Python's List
Comprehensions.  Well, I've gotten a little closer to having them.
For some reason, LispMe doesn't come with a &lt;tt&gt;zip&lt;/tt&gt; method,
and you can only get &lt;tt&gt;map&lt;/tt&gt; by importing a "&lt;tt&gt;Standard
Library&lt;/tt&gt;" memo.  So, I had to write my own version of zip, and
here it is, for anyone else who might find it useful.&lt;/p&gt;
&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;zip&lt;/span&gt; &lt;span class="nv"&gt;s1&lt;/span&gt; &lt;span class="nv"&gt;s2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;or &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;null? &lt;/span&gt;&lt;span class="nv"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;null? &lt;/span&gt;&lt;span class="nv"&gt;s2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cons &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;car &lt;/span&gt;&lt;span class="nv"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;car &lt;/span&gt;&lt;span class="nv"&gt;s2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;z&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cdr &lt;/span&gt;&lt;span class="nv"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cdr &lt;/span&gt;&lt;span class="nv"&gt;s2&lt;/span&gt;&lt;span class="p"&gt;)))))&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;Along with my halfway function, redefined to be &lt;tt&gt;(define
(halfway x) (/ (+ (car x) (cadr x)) 2))&lt;/tt&gt;, I can now write
&lt;tt&gt;(map halfway (zip current-point next-point))&lt;/tt&gt; to get the
point halfway between where I am, and where I am going to.&lt;/p&gt;
&lt;p&gt;I also came to another realization.  I was planning on defining a
&lt;tt&gt;current-point&lt;/tt&gt;, and using &lt;tt&gt;set!&lt;/tt&gt; to update it
to the new halfway point, but when I think about it, I don't really
care what the current point is at any time other than processing, so
there's no particular need to set it, and instead I should just pass
it around as a parameter, making my iter function (and I just made up
the name "iter function", based on the &amp;lt;a href=
"http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1.7"&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;tt&gt;sqrt-iter&lt;/tt&gt; function in "Structure and Interpretation
of Computer Programs") look something like this:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;triangle-iter&lt;/span&gt; &lt;span class="nv"&gt;start&lt;/span&gt; &lt;span class="nv"&gt;num-iters&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;positive? &lt;/span&gt;&lt;span class="nv"&gt;num-iters&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;begin &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;draw-point&lt;/span&gt; &lt;span class="nv"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;triangle-iter&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;map &lt;/span&gt;&lt;span class="nv"&gt;halfway&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;zip&lt;/span&gt; &lt;span class="nv"&gt;current-point&lt;/span&gt; &lt;span class="nv"&gt;next-point&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;- &lt;/span&gt;&lt;span class="nv"&gt;num-iters&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)))))&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;Does that look appropriately Scheme-ish, do you think?&lt;/p&gt;&lt;/div&gt;</description><category>scheme</category><guid>https://bwinton.github.io/weblog.latte.ca/blake/tech/scheme/zip/</guid><pubDate>Wed, 09 May 2007 21:29:00 GMT</pubDate></item><item><title>Starting Scheme.</title><link>https://bwinton.github.io/weblog.latte.ca/blake/tech/scheme/intro/</link><dc:creator>Blake Winton</dc:creator><description>&lt;div&gt;&lt;p&gt;(Posted to the LispMe@YahooGroups.com list)
Hello.&lt;/p&gt;
&lt;p&gt;Let me start with a brief introduction.  My name is Blake Winton,
and I’ve owned a PalmPilot since back when they were called PalmPilots
and made by USRobotics.  I’ve been programming for them for years,
mostly in C and C++, with brief excursions into Lua, Python, and
Forth.  My day job consists mainly of Java (J2EE), with some Python
when I get the chance, and some JavaScript when I shouldn’t be using
Python.  On my off hours, I read a lot about other languages (recently
Objective C, OCaml, and Ruby).  Now I want to learn Scheme, and
thought that LispMe would be a good way to do it.  I’m finding some
things are tripping me up, mainly due to my attempts to transfer my
knowledge from other areas into LispMe.  (One piece I miss in
particular are something like Python’s List Comprehensions, which I
believe they sole from Haskell.)&lt;/p&gt;
&lt;p&gt;So, I’m going through SICP, but while I’m doing that, I thought I
would try to do a "Real World" (tm) task, and write a program that
drew the Serpinsky Triangle, using an iterative, random, approach,
(Details available upon request,) and I’ve run into some small
questions about best practices, or basically how to do some simple
things.  In return for this help, I’ll create a sort of Tutorial
document for LispMe that will be able to help other people get up to
speed.  (If such a document already exists, please, someone, point me
to it!)&lt;/p&gt;
&lt;p&gt;So, here’s what I’ve got so far.  It doesn’t work at all, but it’s
starting to take shape.&lt;/p&gt;
&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;; Triangle&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="nv"&gt;points&lt;/span&gt;
  &lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;next-point&lt;/span&gt; &lt;span class="nv"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;vector-ref &lt;/span&gt;&lt;span class="nv"&gt;points&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;vector-length &lt;/span&gt;&lt;span class="nv"&gt;points&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
  &lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="nv"&gt;current-point&lt;/span&gt; &lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;halfway&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;/ &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;And we’re done.  Any comments on it, from spacing to indentation to
whether I should use a vector or a list for the points themselves,
would be greatly appreciated.  If it matters, I plan on extending the
point to include red, green, and blue data as well, possibly with
accessors, looking something like this:&lt;/p&gt;
&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="nv"&gt;current-point&lt;/span&gt; &lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;car &lt;/span&gt;&lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;y&lt;/span&gt; &lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cadr &lt;/span&gt;&lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;r&lt;/span&gt; &lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;caddr &lt;/span&gt;&lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;g&lt;/span&gt; &lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cadddr &lt;/span&gt;&lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;b&lt;/span&gt; &lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;caddddr&lt;/span&gt; &lt;span class="nv"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;Oh, and I suspect I’ll be blogging my progress at &lt;a href="http://weblog.latte.ca/blake/tech/scheme/"&gt;http://weblog.latte.ca/blake/tech/scheme/&lt;/a&gt;
(Nothing exists there at the moment, though.  Give it time.)&lt;/p&gt;
&lt;p&gt;Thanks,&lt;br&gt;
Blake.&lt;/p&gt;&lt;/div&gt;</description><category>scheme</category><guid>https://bwinton.github.io/weblog.latte.ca/blake/tech/scheme/intro/</guid><pubDate>Wed, 09 May 2007 21:28:58 GMT</pubDate></item></channel></rss>