<?xml version="1.0" encoding="UTF-8"?> <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/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>Foognostic blogs &#187; gnu</title> <atom:link href="http://blogs.foognostic.net/topics/gnu/feed/" rel="self" type="application/rss+xml" /><link>http://blogs.foognostic.net</link> <description>Seeking knowledge of foo</description> <lastBuildDate>Thu, 24 Feb 2011 23:17:24 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Configuring projects in org mode, or defining variables in Lisp is strange</title><link>http://blogs.foognostic.net/2009/04/configuring-projects-in-org-mode-or-defining-variables-in-lisp-is-strange/</link> <comments>http://blogs.foognostic.net/2009/04/configuring-projects-in-org-mode-or-defining-variables-in-lisp-is-strange/#comments</comments> <pubDate>Fri, 10 Apr 2009 23:06:54 +0000</pubDate> <dc:creator>Seth Schroeder</dc:creator> <category><![CDATA[gnu]]></category> <category><![CDATA[lisp]]></category> <category><![CDATA[org-mode]]></category> <guid
isPermaLink="false">http://blogs.foognostic.net/?p=92</guid> <description><![CDATA[Org mode in GNU Emacs makes it somewhat easy to publish its files as a small static website. You define the files to publish, how to convert them, where to publish them, and so on. The bad news is that you need to manually write a big data structure in Emacs Lisp. Not what a Lisp newbie really wanted to hear (no customize page?) but I decided org mode was worth the pain. Speaking of pain, here's the data structure:]]></description> <content:encoded><![CDATA[<p><a
href="http://orgmode.org">Org mode</a> in <a
href="http://directory.fsf.org/project/emacs/">GNU Emacs</a> makes it somewhat easy to publish its files as a small static website. You define the files to publish, how to convert them, where to publish them, and so on. The bad news is that you need to manually write a big data structure in Emacs Lisp. Not what a Lisp newbie really wanted to hear (no customize page?) but I decided org mode was worth the pain. Speaking of pain, here's the data structure:</p><p><pre class="">
<a name="cfg_loc_0"> 0:</a>  (set
<a name="cfg_loc_1"> 1:</a>    (quote org-publish-project-alist)
<a name="cfg_loc_2"> 2:</a>    '
<a name="cfg_loc_3"> 3:</a>    (
<a name="cfg_loc_4"> 4:</a>      (
<a name="cfg_loc_5"> 5:</a>        &quot;tsn&quot;
<a name="cfg_loc_6"> 6:</a>        :base-directory &quot;~/Documents/foog/tsn&quot;
<a name="cfg_loc_7"> 7:</a>        :base-extension &quot;org&quot;
<a name="cfg_loc_8"> 8:</a>         :publishing-directory &quot;/dev/null&quot;
<a name="cfg_loc_9"> 9:</a>         :publishing-function org-publish-org-to-html
<a name="cfg_loc_10">10:</a>      )
<a name="cfg_loc_11">11:</a>    )
<a name="cfg_loc_12">12:</a>  )
</pre></p><p>All that work just to define a list of lists? I could just write it in Ruby as:</p><p><pre>
 # pretend this function exists in Ruby
 # def org_publish_to_html() end
org_publish_project_alist = [
    [ &quot;tsn&quot;,
      :base_directory, &quot;~/Documents/foog/tsn&quot;,
      :base_extension, &quot;org&quot;,
      :publishing_directory, &quot;~/Documents/foog/tsn_export&quot;,
      :publishing_function, org_publish_to_html ]
];
</pre></p><p>The major difference is all this set and quote nonsense. How many function calls does it take to initialize a variable in Lisp?? It turned out that answering that question well required some spelunking into Lisp. It kind of makes me appreciate GNU Emacs Lisp as a low-level high-level language.</p><h3>And now, we plunge through the rabbit hole!</h3><p>So, why call the (quote) function when defining a variable? I didn't realize what a good question this was. The answer means paying close attention to references and values. Let's take a quick look at a function which determines whether its argument is a value or a reference:</p><div
class="codecolorer-container lisp vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div
class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">symbolp</span> 123<span
style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #66cc66;">=&gt;</span> <span
style="color: #b1b100;">nil</span> &nbsp;<span
style="color: #808080; font-style: italic;">;; nil is false in Emacs Lisp</span><br
/> <span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">symbolp</span> <span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">quote</span> 123<span
style="color: #66cc66;">&#41;</span><span
style="color: #66cc66;">&#41;</span> &nbsp; <span
style="color: #66cc66;">=&gt;</span> <span
style="color: #b1b100;">nil</span> &nbsp;<span
style="color: #808080; font-style: italic;">;; 123 passes through...</span><br
/> <span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">symbolp</span> <span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">quote</span> <span
style="color: #ff0000;">&quot;abc&quot;</span><span
style="color: #66cc66;">&#41;</span><span
style="color: #66cc66;">&#41;</span> <span
style="color: #66cc66;">=&gt;</span> <span
style="color: #b1b100;">nil</span> &nbsp;<span
style="color: #808080; font-style: italic;">;; abc passes through</span><br
/> <span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">symbolp</span> <span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">quote</span> foo<span
style="color: #66cc66;">&#41;</span><span
style="color: #66cc66;">&#41;</span> &nbsp; <span
style="color: #66cc66;">=&gt;</span> t &nbsp; &nbsp;<span
style="color: #808080; font-style: italic;">;; but foo is a symbol.</span></div></div><p>Okay, so now we can distinguish between a value and a reference. The next step is assigning a value to a reference. This is where (quote) is essential.</p><div
class="codecolorer-container lisp vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div
class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">set</span> foo 123<span
style="color: #66cc66;">&#41;</span> <span
style="color: #66cc66;">=&gt;</span> Lisp <span
style="color: #b1b100;">error</span><span
style="color: #66cc66;">:</span> <span
style="color: #66cc66;">&#40;</span>void-variable foo<span
style="color: #66cc66;">&#41;</span></div></div><p>That silly Lisp interpreter, trying to get a value while we are in the middle of setting it. That's where (quote) comes in. The function call to quote is evaluated, and the result is passed as the first argument to (set). That makes some sense, but because variable definition happens <b>ALL THE TIME</b> in imperative programming languages Emacs Lisp has tried to make this as easy as possible:</p><div
class="codecolorer-container lisp vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div
class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">set</span> <span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">quote</span> foo<span
style="color: #66cc66;">&#41;</span> <span
style="color: #cc66cc;">123</span><span
style="color: #66cc66;">&#41;</span> &nbsp;<span
style="color: #66cc66;">=&gt;</span><span
style="color: #808080; font-style: italic;">; 123 &nbsp;;; No one does this</span><br
/> <span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">set</span> 'foo <span
style="color: #cc66cc;">456</span><span
style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #66cc66;">=&gt;</span><span
style="color: #808080; font-style: italic;">; 456 &nbsp;;; 'foo = (quote foo)</span><br
/> <span
style="color: #66cc66;">&#40;</span><span
style="color: #b1b100;">setq</span> foo <span
style="color: #cc66cc;">789</span><span
style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #66cc66;">=&gt;</span><span
style="color: #808080; font-style: italic;">; 789 &nbsp;;; People do this one.</span></div></div><hr/><h2>INTERMISSION</h2><p>Now that variable assignment has been hashed out we can pick up speed a bit and finish this off:</p><p><ul><li><a
href="#cfg_loc_1">Line 1</a> specifies the symbol we want to use.<li><a
href="#cfg_loc_2">Line 2</a> is just a macro for (quote), so the contents will be returned without being evaluated.<li><a
href="#cfg_loc_3">Line 3</a> starts a list. To me this implies that the variable org-publish-project-alist will contain an array of ... well, not sure yet.<li><a
href="#cfg_loc_4">Line 4</a> starts a list. This list will be the first item in the list defined by org-publish-project-alist.<li><a
href="#cfg_loc_5">Line 5</a> is just a string. It is the first element in the list. Calling (car) on the list started at line 4 would return &quot;tsn&quot;.<li><a
href="#cfg_loc_6">Line 6</a> contains the 2nd and 3rd items in the list. :base-directory is a keyword symbol ((symbolp :base-directory) =&gt; t). &quot;~/Documents/foog/tsn&quot; is the next element in the list.<li>Lines 7-9 define the remnant of the list started at line 4.<li>The remaining lines are the obligatory closing parens.</ul></p><p>Probably because I am very new to Lisp I don't understand why flat lists are used to store this data. Key value pairs are a great fit for hash maps or associative lists (the variable name ends with alist...). My first attempt to restructure the data would be:</p><p><pre>
(setq org-projects
  '(
     ("tsn"
       (:base-directory . "~/Documents/foog/tsn")
       (:base-extension . "org")
       (:publishing-directory . "~/Documents/foog/tsn_export")
       (:publishing-function . org-publish-org-to-html))
     ("css"
       (:base-directory . "~/Documents/foog/tsn/css")
       (:base-extension . "css"))
     ("img"
       (:base-directory . "~/Documents/foog/tsn/images")
       (:base-extension . "jpg|png"))
  ))
</pre></p><p>The difference being that key value pairs are stored in an associative list. This lets you take advantage of built in functions for getting property values.</p><p><pre>
(mapcar
  (lambda (elt)
    (let
      ((project (car elt))
       (properties (cdr elt)))
      (print (format "Project %s has base extension %s"
                      project
                      (cdr (assoc :base-extension properties))))))
  org-projects)
</pre></p><p>Output:
("Project tsn has base extension org" "Project css has base extension css" "Project img has base extension jpg|png")</p><p>Wow, look at all the rambling. At least now I understand how to manually configure org mode's projects.</p><p>Lisp is neat.</p> ]]></content:encoded> <wfw:commentRss>http://blogs.foognostic.net/2009/04/configuring-projects-in-org-mode-or-defining-variables-in-lisp-is-strange/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>GNU&#8217;ve got to be kidding me &#8212; Makefiles?</title><link>http://blogs.foognostic.net/2008/12/gnuve-got-to-be-kidding-me-makefiles/</link> <comments>http://blogs.foognostic.net/2008/12/gnuve-got-to-be-kidding-me-makefiles/#comments</comments> <pubDate>Sun, 21 Dec 2008 20:52:36 +0000</pubDate> <dc:creator>Seth Schroeder</dc:creator> <category><![CDATA[gnu]]></category> <category><![CDATA[make]]></category> <guid
isPermaLink="false">http://blogs.foognostic.net/?p=38</guid> <description><![CDATA[It's very nerdy but several years ago I really enjoyed getting to learn and use GNU Make. It's best known for compiling and linking C and C++, but it really is a powerful general purpose tool. I'm trying to get back into it and decided to publish that refresher process. Jibe or jive as you will!]]></description> <content:encoded><![CDATA[<p>It's very nerdy but several years ago I really enjoyed getting to learn and use <a
href="http://www.gnu.org/software/make/make.html">GNU Make</a>. It's best known for compiling and linking C and C++, but it really is a powerful general purpose tool. I'm trying to get back into it and decided to publish that refresher process. Jibe or jive as you will!</p><p>First, here is foo.cpp:<pre class="c++ code">#include &lt;iostream&gt;
int main() {
    std::cout &lt;&lt; "Hello, world" &lt;&lt; std::endl;
    return 0;
}</pre>And here is the Makefile to compile it, link it, and run it:<pre class="Makefile">run: foo.cpp
    g++ foo.cpp
    ./a.out</pre>There are three concepts here.</p><ol><li><div
class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">run</div></div> -- this is the target, the goal, what you are trying to do.</li><li><div
class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">foo.cpp</div></div> -- the dependencies of the goal.</li><li><div
class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">g++ foo.cpp</div></div> and<div
class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">./a.out</div></div> . Look ma, shell commands! Nothing more, nothing less than the CLI environment many live and breathe.</li></ol><p>Just type 'make' and</p><div
class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Hello, world</div></div><p>will follow shortly. This is a pretty bad Makefile though for lots of reasons. Only having one step to compile, link, and run means compiling and linking will happen everytime the Makefile is processed. To fix that, give each stage its own rule:<pre>run: a.out
    ./a.out</p>
<p>a.out: foo.o
    g++ foo.o</p>
<p>foo.o: foo.cpp
    g++ -c foo.cpp</pre>Running, linking, and compiling from top to bottom. Make automatically tracks modification dates of dependencies. It will only execute shell commands for objects with modified dependencies. Here is the output from the first time I ran this Makefile.<pre>g++ -c foo.cpp
g++ foo.o
./a.out
Hello, world</pre>Without changing foo.cpp I immediately ran make again. Here was the output:<pre>./a.out
Hello, world</pre>So that takes care of one glaring problem in the original Makefile. But I just created bar.cpp (it compiles, trust me) and I don't want to add a nearly duplicate rule. That would mean duplicating rules everytime I add a new source file, right?</p><p>Make solves that with a page from the Perl playbook; a little punctuation is good, and too much punctuation is awesome! This is perfectly clear, right?<pre>a.out: %.o
    g++ $^</p>
<p>%.o: %.cpp
    g++ -c $&lt;</pre>'%' is a wildcard character, similar to '+' and '*' in traditional regular expressions. The others I pulled from the documentation on <a
href="http://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html#Automatic-Variables">automatic variables</a>, but they refer to the dependencies in the rule (things following the : character).</p><p>So how'd that go? FAIL.<pre>make: *** No rule to make target <code>%.o', needed by</code>a.out'.  Stop.</pre>And this is where I remembered gmake has a healthy, happy family of different types of rules. Using '%' in the target of a rule makes it a pattern rule. But the rule for a.out is not a pattern rule, so it looked at %.o as a literal file name. What if I use</p><div
class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">a.out: *.o</div></div><p>instead?<pre>g++ -c bar.cpp
g++ <em>.o
Undefined symbols:
  "_main", referenced from:
      start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: **</em> [a.out] Error 1</pre>Crap, it did what I said, not what I meant. I said match *.o, which becomes true as soon as one is created. What I wanted was to match ALL the .o files. No getting around that, but at least we can act a little more grown up and use &lt;gasp&gt;variables&lt;/gasp&gt;.<pre>SRCS = foo.cpp bar.cpp
OBJS = foo.o bar.o</p>
<p>a.out: $(OBJS)
    g++ $^</pre>And that works. But now we have another problem! Who wants to update the Makefile everytime a new cpp file is added?? Well, of course there is a solution for this. Half is strange and half is really cool:<pre>SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)</pre>The strange half is calling a GNU Make function 'wildcard'. That just seems strangely difficult for something reasonably common. Anyways, the cool part was the syntactic sugar to create OBJS by replacing .cpp with .o from $SRCS.</p><p>That's about all the refresher I can handle for now. It should be enough to get me going... having done non-trivial cross-platform builds with gmake I know more is possible but I don't need it sitting here at home. At least I know <a
href="http://www.gnu.org/software/make/manual/html_node/index.html#Top">great documentation</a> will be ready when I need it.</p> ]]></content:encoded> <wfw:commentRss>http://blogs.foognostic.net/2008/12/gnuve-got-to-be-kidding-me-makefiles/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
