<?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>Lojic Technologies Blog &#187; logo</title>
	<atom:link href="http://lojic.com/blog/tag/logo/feed/" rel="self" type="application/rss+xml" />
	<link>http://lojic.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 25 Nov 2011 20:12:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Learning Logo &#8211; Part 4</title>
		<link>http://lojic.com/blog/2009/07/26/learning-logo-part-4/</link>
		<comments>http://lojic.com/blog/2009/07/26/learning-logo-part-4/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 19:51:33 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[logo]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/?p=644</guid>
		<description><![CDATA[Table of Contents
Chapter Four &#8211; Predicates
Key Ideas
A predicate is an operation whose output is always either the word true or the word false.
For example:

? print listp [ hello ]
true
? print listp "hello
false
? print listp [ hello ]
true
? print listp [ ]
true
? print wordp "hello
true

By convention, predicates often end in &#8216;p&#8217; or &#8216;?&#8217;. Here&#8217;s an example [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://lojic.com/blog/2008/01/05/learning-logo-part-one/">Table of Contents</a></p>
<h2>Chapter Four &#8211; Predicates</h2>
<h3>Key Ideas</h3>
<p>A <em>predicate</em> is an operation whose output is always either the word <code>true</code> or the word <code>false</code>.<br />
For example:</p>
<pre class="code">
? print listp [ hello ]
true
? print listp "hello
false
? print listp [ hello ]
true
? print listp [ ]
true
? print wordp "hello
true
</pre>
<p>By convention, predicates often end in &#8216;p&#8217; or &#8216;?&#8217;. Here&#8217;s an example of defining your own predicate using a built-in predicate:</p>
<pre class="code">
to vowel? :letter
  output memberp :letter [a e i o u]
end

? print vowel? "i
true
? print vowel? "y
false
</pre>
<p><code>if</code> is a command with two inputs. The first input must be either the word <code>true</code> or the word <code>false</code>. The second input must be a list containing Logo instructions. If the first input is <code>true</code>, the instructions are evaluated.</p>
<p><code>ifelse</code> is a procedure that requires three inputs. The first input must be either the word <code>true</code> or the word <code>false</code>. The second and third inputs must be lists of Logo instructions. If the first input is <code>true</code>, the list in the second input is evaluated; otherwise, the list in the third input is evaluated. <code>ifelse</code> is unusual in that it can be used as a command or operation.</p>
<p><code>test</code> is a command that takes one input that is either <code>true</code> or <code>false</code>. <code>test</code> stores its input in special variable that is local to the procedure from which <code>test</code> is invoked. <code>iftrue</code> (abbreviated ift) is a command with one input &#8211; a list of Logo instructions which are evaluated if the most recent <code>test</code> command stored <code>true</code>. <code>iffalse</code> (abbreviated iff) is similar except that the list of instructions are evaluated if the recent <code>test</code> was <code>false</code>.</p>
<p><code>and</code> is a predicate with two inputs each of which must be <code>true</code> or <code>false</code>. The ouput is <code>true</code> if both inputs are <code>true</code>; otherwise, it is <code>false</code>.</p>
<p><code>or</code> is a similar predicate whose output is <code>true</code> if <em>either</em> input is true.</p>
<p><code>not</code> is a predicate with one input (true or false) whose output is the opposite of the input.</p>
<p>When <code>ifelse</code> is used as an operation, the output is the result of evaluating the list of instructions in either the second or third inputs depending on whether the first input was <code>true</code> or <code>false</code> respectively. For example:</p>
<pre class="code">
? print sentence "It's ifelse 2=3 ["correct] ["incorrect]
It's incorrect

to abs :number
  output ifelse :number < 0 [-:number] [:number]
end

? print abs -7
7
? print abs 7
7
</pre>
<p><code>stop</code> is a command that takes no inputs that finishes the evaluation of the procedure in which it is used. An <code>output</code> command also finishes the evaluation of the procedure in which it occurs. If you're writing an operation, which should have an output, you use <code>output</code>; if you're writing a command, which doesn't have an output, you use <code>stop</code>.</p>
<p><code>repeat</code> is a command with two inputs. The first input is a non-negative whole number. The second input is a list of Logo instructions which will be evaluated the number of times given as the first input.</p>
<h3>Questions</h3>
<pre class="code">
1) What type of operation always outputs either the word true or the word
   false?

2) Do names of predicates have to end in the letter p? Is it a good idea
   to name your predicates with names ending in the letter p? What would
   be another good way to name a predicate?

3) List eleven primitive predicates that are named in this chapter:

4) What is another way to say the same thing as the following?
   equalp "hello last [goodbye hello]

5) Fill in the blank so the command prints true:
   print memberp ______ [barnes noble]

6) Fill in the blank so the command prints true:
   print memberp _____ "chitty

7) Create a predicate, even?, that returns true if the input is even.

8) Write a procedure that will print the specified output when given
   the specified input:
   input: Brian
   output: [Hello Brian]

   input: [Brian Adkins]
   output: [Hello Mr. Adkins]

   input: [Brian Xavier Adkins]
   output: [Xavier is a nice middle name.]

9) Write integerp, as described on p. 66

10) Write the procedure converse that's described on the bottom of p. 67.

11) Read the section entitled "About Those Brackets" on the top of p. 69 again to
    make sure you understand it.

12) Which primitive predicates takes only one input?

13) Use the operation form of ifelse to output the input word backwards if it has
    an odd number of characters or output it normally if it has an even number of
    characters.

    to evenword? :value
      output equal? 0 (remainder count :value 2)
    end

    to condreverse :value
      output ifelse ______________________________________________
    end

    print condreverse "hello   -> olleh
    print condreverse "hi      -> hi
    print condreverse "daddy   -> yddad

14) How are output and stop similar? How are they different?

15) Write a predicate, palindrome?, that outputs true if a word is a
    palindrome. A word is a palindrome if it is the same forward and backward.

    print palindrome? "hello  -> false
    print palindrome? "mom    -> true
    print palindrome? "wow    -> true

16) Write a procedure that uses the palindrome? predicate you wrote in #15 to
    accept a list and output a list containing only the words that are
    palindromes.

    print palindromes [hello mom daddy wow doogood] -> mom wow doogood
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2009/07/26/learning-logo-part-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TriFunc.org</title>
		<link>http://lojic.com/blog/2009/07/22/trifuncorg/</link>
		<comments>http://lojic.com/blog/2009/07/22/trifuncorg/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 14:15:42 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[arc]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[logo]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[sml]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/?p=635</guid>
		<description><![CDATA[I first became interested in functional programming when I was exposed to Python, Ruby &#038; JavaScript a number of years ago. Since then I&#8217;ve looked into Arc, Clojure, Common Lisp, Haskell, Logo, ML &#038; Scheme. I haven&#8217;t yet determined whether I&#8217;ll be more productive in any of them than I am with Ruby for developing [...]]]></description>
			<content:encoded><![CDATA[<p>I first became interested in functional programming when I was exposed to Python, Ruby &#038; JavaScript a number of years ago. Since then I&#8217;ve looked into Arc, Clojure, Common Lisp, Haskell, Logo, ML &#038; Scheme. I haven&#8217;t yet determined whether I&#8217;ll be more productive in any of them than I am with Ruby for developing web applications, but I do find them quite interesting.</p>
<p>After bumping into a number of local programmers who expressed an interest in functional programming, I thought it might be a good time to start a local group that focused on functional programming languages, so I did a couple days ago.</p>
<p><a rel="nofollow" href="http://TriFunc.org">TriFunc.org</a> is a group for programmers who are interested in functional programming languages and live near the Research Triangle area of North Carolina.</p>
<p>If you live in the area and have an interest in functional programming languages, feel free to dive in and start participating in the Google Group discussions. Once we reach a critical mass, I expect we&#8217;ll produce a meeting schedule, etc., but that will depend on where the group wants to take this.</p>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2009/07/22/trifuncorg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Logo &#8211; Part 3</title>
		<link>http://lojic.com/blog/2009/06/28/learning-logo-part-3/</link>
		<comments>http://lojic.com/blog/2009/06/28/learning-logo-part-3/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 00:49:26 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[logo]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/?p=616</guid>
		<description><![CDATA[Table of Contents
Part 3 was written with the help of my daughter.
Chapter Three &#8211; Variables
Key Ideas
To have a procedure accept input parameters, provide the names of the input parameters preceded by a colon. The colon provides a distinction between the procedure name and input parameters. Some versions of Logo don&#8217;t require the colon.

to greet :person

Thing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://lojic.com/blog/2008/01/05/learning-logo-part-one/">Table of Contents</a></p>
<p>Part 3 was written with the help of my daughter.</p>
<h2>Chapter Three &#8211; Variables</h2>
<h3>Key Ideas</h3>
<p>To have a procedure accept input parameters, provide the names of the input parameters preceded by a colon. The colon provides a distinction between the procedure name and input parameters. Some versions of Logo don&#8217;t require the colon.</p>
<pre class="code">
to greet :person
</pre>
<p><em>Thing</em> is an operation that takes an input which is the name of a container and outputs the contents of the container.</p>
<pre class="code">
? to greet :person
> print sentence "Hello, thing "person
> end
greet defined
? greet "Brian
Hello, Brian
</pre>
<p>An abbreviation for <em>thing &#8220;person</em> is to simply use a colon.</p>
<pre class="code">
:person
</pre>
<p>Sometimes you can even leave the colon off, but you shouldn&#8217;t depend on that.</p>
<p><em>Readlist</em> is an operation that waits for you to type a line, then outputs what you type.</p>
<p><em>output</em> is a command that has the effect of making its input available as the output of the procedure it&#8217;s within.</p>
<p>Logo uses <em>dynamic scope</em> for its variables; however, it&#8217;s good style to minimize referencing variables in calling procedures.</p>
<p><em>make</em> is a command that accepts two inputs. The first input is a word that is the name of a variable; the second input is a value to assign to the variable.</p>
<pre class="code">
? make "name [Brian Adkins]
? print :name
Brian Adkins
</pre>
<p>The following two lines are equivalent:</p>
<pre class="code">
make "new :old
make first [new old] thing last [new old]
</pre>
<p>If the first input to <em>make</em> refers to a non-existent variable, a new globabl variable is created. To create a variable local to the procedure, use the <em>local</em> command.</p>
<p><em>make</em> can use computed names in addition to quoted names. For example, the increment procedure below:</p>
<pre class="code">
? to increment :variable
> make :variable (thing :variable)+1
> end
increment defined
? make "foo 7
? increment "foo
? print :foo
8
</pre>
<p>A procedure is <em>functional</em> if it always gives the same output when invoked with the same input(s).</p>
<h3>Questions</h3>
<pre class="code">
1) Work through all the examples in the chapter to make sure you
   understand them.

2) Every variable has a ____ and a _____.

3) Define "formal parameter" and "actual argument"

4) What is another way to say the following?
    thing "name

5) Take problem #8 from chapter 1 and solve it without using make to
   store a temporary variable. Do you like this solution better or
   worse than your solution in chapter 1?

6) A complete instruction begins with which of the following?
  operation
  command

7) Write the procedure you're asked to write on p. 46 to conjugate
   French verbs.

8) Consider the following command:

  to thang :thing
    print thing :thing
  end

   How would you invoke this procedure to get it print the following?

   thing

9) Write the procedure you're asked to on p. 49:

10) Write the helper procedure you're asked to write on p.54

11) What will the following print?

  make "foo 7
  make last [foo oof] sum thing first [foo oof] 7
  print oof

12) How do you prevent a global variable from being created when using
    make with a name that is not the name of an input?

13) What will the following print?
  make "a "b
  make "b "c
  make "c "d
  make "d 7
  print thing thing thing "a
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2009/06/28/learning-logo-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Learning Logo &#8211; Part 2</title>
		<link>http://lojic.com/blog/2009/05/06/learning-logo-part-2/</link>
		<comments>http://lojic.com/blog/2009/05/06/learning-logo-part-2/#comments</comments>
		<pubDate>Thu, 07 May 2009 00:44:38 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[logo]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/?p=494</guid>
		<description><![CDATA[Table of Contents
Background
It&#8217;s been a while since I posted Learning Logo &#8211; Part One. I&#8217;ve resumed Logo lessons with my kids, so I thought I&#8217;d post the chapter questions I&#8217;ve created for each chapter to accompany Brian Harvey&#8217;s excellent texts (see link above for free PDF files for the textbooks).
Chapter One &#8211; Exploration
Key Ideas
Chapter one [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://lojic.com/blog/2008/01/05/learning-logo-part-one/">Table of Contents</a></p>
<h2>Background</h2>
<p>It&#8217;s been a while since I posted <a href="http://lojic.com/blog/2008/01/05/learning-logo-part-one/">Learning Logo &#8211; Part One</a>. I&#8217;ve resumed Logo lessons with my kids, so I thought I&#8217;d post the chapter questions I&#8217;ve created for each chapter to accompany Brian Harvey&#8217;s excellent texts (see link above for free PDF files for the textbooks).</p>
<h2>Chapter One &#8211; Exploration</h2>
<h3>Key Ideas</h3>
<p>Chapter one introduces Logo and some of the vocabulary. Simple procedures are written and you learn how to save and load files.</p>
<h3>Questions</h3>
<pre class="code">1) Write a program to print the following:
   Hello, world!

2) What version of Logo are you using?

3) How many times will hello be printed with the following program?
   repeat 2 [repeat 2 [repeat 2 [print "hello]]]

4) What is the word to clear the screen? What is its abbreviation?

5) Write a program to print your name 10 times.

6) What does the name Logo come from?

7) Name some Logo procedures.

8) How do you save the workspace to a file named my.logo?

9) How do you load a file named my.logo into the workspace?</pre>
<h2>Chapter Two &#8211; Procedures</h2>
<h3>Key Ideas</h3>
<p><em>Everything</em> in Logo is done with procedures. Initially, Logo knows about 200 procedures. These are called <em>primitive</em> procedures.</p>
<p>Using the output from one procedure as an input to another procedure is called <em>composition of functions</em>.</p>
<p>In Logo there are two kinds of procedures: <em>commands</em> and <em>operations</em>. An <strong>operation</strong> is a procedure that computes a value and outputs it. A <strong>command</strong> is a procedure that does not output a value, but instead has some effect such as printing something on the screen, moving a turtle, or making a sound.</p>
<p>To have Logo treat a word as itself instead of evaluating it, you must <em>quote</em> the word by typing a quotation mark (&#8221;) in front of it.</p>
<p>You can combine several <em>words</em> to form a <em>list</em> by using square brackets. For example, [Hello world]. The members of a list can also be lists. For example:</p>
<pre class="code">[ [North Carolina] Ohio [South Dakota] ]</pre>
<p>The brackets in Logo serve two purposes &#8211; they <em>delimit</em> a list and they also <em>quote</em> the list so the members are not evaluated as procedures.</p>
<p>Logo provides several operations for taking data apart and putting data together. Words come apart into <em>characters</em> and lists come apart into whatever data are the <em>members</em> of the list. A <em>sentence</em>, which is a list of words, comes apart into <em>words</em>. For example:</p>
<pre class="code">? print first "Hello
H
? print first [How are you?]
How</pre>
<p>Logo provides infix arithmetic as well as prefix arithmetic. For example:</p>
<pre class="code">print 2+3
vs.
print sum 2 3</pre>
<p>Certain primitive procedures can be given extra inputs, or fewer inputs than usual, by using parentheses around the procedure name and all its inputs. For example:</p>
<pre class="code">? print sum 2 3 4
5
You don't say what to do with 4
? print (sum 2 3 4)
9
? show (list "one)
[one]
? show (list)
[ ]</pre>
<p>Sum, product, word, list, sentence, and print can be used with any number of inputs.</p>
<p>Logo allows creating your own procedures. For example:</p>
<pre class="code">to hello
  print "Hello
end</pre>
<h3>Questions</h3>
<pre class="code">1) What is the word that describes the special punctuation and organization of
   a programming language?

2) About how many procedures does Logo know without you teaching it any? What
   type of procedures are these (e.g. what is a word that describes them)?

3) What is the word that refers to a value that one procedure computes and
   hands on to another procedure?

4) Using the examples of tanks with inputs and outputs as described on p. 15,
   draw a picture of the following, then use the picture to determine what will
   be printed before trying it in Logo:

  print product sum 1 sum 2 3 sum 4 5

5) What are the two kinds of procedures in Logo? What is the difference between
   them?

6) Why doesn't the following code work?
  print Hello

7) Fill in the blanks, "In computer science, to _____ something means to
   prevent it from being ________."

8) What are four ingredients of a proper description of a procedure?

9) What will the following print?
  print first first [Hello world]

10) How many inputs does the sentence operation take?

11) What will each of the following instructions print? Think about why.
  print sentence [one two] [three four]
  print list [one two] [three four]
  print item 2 list [one two] [three four]
  print item 2 sentence [one two] [three four]

12) Use only the following procedures and data (you can use them more than
    once) to print Logo

  first butfirst butlast word print [I Love Pogo]

13) How would you write an instruction to print the sum of 1, 2 and 3?

14) What are three reasons parentheses are used in Logo instructions?</pre>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2009/05/06/learning-logo-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2009 Programming Language Plan</title>
		<link>http://lojic.com/blog/2009/04/27/2009-programming-language-plan/</link>
		<comments>http://lojic.com/blog/2009/04/27/2009-programming-language-plan/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 17:36:42 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[common_lisp]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[logo]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[sml]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/?p=502</guid>
		<description><![CDATA[Background

The 2008 Programming Language Plan didn&#8217;t go as well as I hoped, so I&#8217;m regrouping for another go at it. I did make progress learning some Logo and teaching it to my daughters, and I worked through seven chapters of &#8220;Programming in Haskell&#8221; which was very enjoyable, but I also spent way too much time [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>
The <a href="http://lojic.com/blog/2008/01/17/2008-programming-language-plan/">2008 Programming Language Plan</a> didn&#8217;t go as well as I hoped, so I&#8217;m regrouping for another go at it. I did make progress learning some Logo and teaching it to my daughters, and I worked through seven chapters of &#8220;Programming in Haskell&#8221; which was very enjoyable, but I also spent way too much time trying to decide which language(s) to learn without actually learning them.
</p>
<p>
I have now decided which languages I want to learn this year, so I figured I&#8217;d post this blog entry. In some respects, things haven&#8217;t changed much from last years plan, but my decisions are much less tentative which is encouraging. I&#8217;m glad to switch from <em>information gathering</em> to actually learning a few languages.
</p>
<h2>Motivation</h2>
<p>
When I switched from C++ to Java in 1996 and noticed a large increase in productivity; however, it didn&#8217;t occur to me to consider whether switching from Java to another language might also give me a similar boost in productivity. The job demand for Java was high during the 10 years I used it, and I was getting paid for my time vs. what I produced, so the oversight wasn&#8217;t too costly.
</p>
<p>
When I switched from Java to Ruby in 2006 I experienced a comparable, if not greater, boost in productivity as I had with the switch from C++ to Java. This time I considered the effect of programming language choice on productivity more carefully and began to wonder about the optimal programming language for me. As a small business owner, my primary consideration is productivity, not popularity or the interchangeableness of programmers.
</p>
<p>
I don&#8217;t think a perfect programming language exists in general, but I think there is an optimal language for me given my particular circumstances, the problems I want to solve, the type of software I want to develop, my way of thinking, my aesthetic tastes, etc.
</p>
<h2>The Problem</h2>
<p>
There is a cost to research programming languages to determine the optimal one, and there is a cost to switch programming languages, so the benefit of a new programming language needs to exceed those costs.
</p>
<p>
Additionally, a significant catch-22 exists in that to truly determine if a language is optimal, one must reach a level of proficiency with the language. There isn&#8217;t enough time to learn <em>all</em> of the candidate languages, so some filtering mechanism must be used first to narrow the choices to a reasonably small set. This filtering mechanism is theoretical by nature, but I think the subtle practicalities of a language have a significant effect on productivity.
</p>
<p>
I have a long term perspective for this task, so I don&#8217;t mind investing time researching programming languages, and I also don&#8217;t mind if I need to develop/acquire supporting libraries before being ultimately more productive than I am currently with Ruby and Rails.
</p>
<h2>The Process</h2>
<p>
I briefly entertained the idea of going about this research in a more systematic, scientific way. That might be a reasonable approach, but due to the following:
</p>
<ul>
<li>My laziness</li>
<li>The high degree of subjectivity in programming language choice</li>
<li>The lack of consensus among programming language researchers</li>
</ul>
<p>
I ended up with a fairly ad-hoc approach involving examining the following areas and trying to absorb enough information to formulate a plan:
</p>
<h3>Efficiency</h3>
<p>
Programming language efficiency is becoming increasingly important to me as Moore&#8217;s law loses steam, and power &amp; cooling issues become more prominent.
</p>
<p>
On the one hand, Ruby is near the bottom of the pack with respect to efficiency, but the productivity has been outstanding, and at the volume of transactions I&#8217;ve needed to deliver thus far, performance hasn&#8217;t been a problem.
</p>
<p>
On the other hand, if programming languages exist (and I believe they do) that have similar or greater <em>power</em> than Ruby but are compiled instead of interpreted, that would be an advantage.
</p>
<p>
Benchmarks are notoriously controversial with respect to the degree in which they predict performance, but I don&#8217;t think they&#8217;re irrelevant. One popular benchmark site is: <a href="http://shootout.alioth.debian.org/">Programming Language Shootout</a>. I also created some micro-benchmarks of my own to test performance.
</p>
<p>
One negative result of Ruby being inefficient is the disparity in performance of code written in Ruby vs. library code, or extensions, written in C. This creates counter-intuitive scenarios where a piece of code that appears less efficient is actually more efficient because of the use of built-in code implemented in C. I don&#8217;t like thinking in those terms; I would much prefer that user written code in the language is much closer to the efficiency of built-in library code.
</p>
<h3>Concurrency</h3>
<p>
With the flattening of CPU MHz and proliferation of CPU cores, I think concurrency may continue to grow in importance. Although I develop mainly server side web applications which can take advantage of multiple cores by virtue of having multiple independent processes, I would prefer to have better concurrency mechanisms in the language/libraries directly.
</p>
<h3>Joy</h3>
<p>
I think I first heard <em>joy</em> used, in the context of programming languages, in the Ruby community &#8211; probably from Matz himself. I have to agree that programming in Ruby has been more joyful than previous programming languages.
</p>
<p>
I&#8217;m not sure exactly why this is, but I expect it has something to do with the effectiveness and productivity of Ruby, but it may be helped by the incredibly friendly Ruby community.
</p>
<h3>Fundamental Nature</h3>
<p>
My preference is for a programming language to minimize arbitrariness and to maximize orthogonality. In other words, I would prefer the language to have a minimal set of core concepts/axioms/operators/etc. that are built upon systematically.
</p>
<h3>Community</h3>
<p>
Whether my optimal language is <em>mainstream</em> or not is irrelevant to me, so I don&#8217;t need the programming language community to be large (and in fact, being <em>too</em> large is a detriment), but I do think it should be active enough that there are people available to help answer questions, write libraries, maintain/improve compilers, debuggers etc.
</p>
<p>
To this end, I spent time on various usenet groups, IRC channels and blogs. Occasionally asking questions, but mostly observing the dialog and interaction among the community members.
</p>
<h3>Education</h3>
<p>
What educational materials are available?
</p>
<p>
I tend to prefer learning from books, so searching Amazon to see what books are available, how well they&#8217;re received, etc. was helpful. Although I prefer books typically, in the exploratory stages, it&#8217;s cheaper to go through online materials, so searching the web for free PDFs was useful. The existence of a few good texts is also an indication of the vitality of community.
</p>
<h3>Productivity</h3>
<p>
Ultimately, I&#8217;m after the most productive language for me; however, I think productivity is the factor that requires the most proficiency with a language to judge, so it was the most difficult factor to research prior to learning a language. I was limited to anecdotal stories, case studies, personal testimonies, etc.
</p>
<h3>Licensing</h3>
<p>
I prefer open source licensing because I think programming languages with proprietary licensing are more likely to die.
</p>
<h2>The Final Candidates</h2>
<p>
I began with Ruby as the point of reference irrespective of Rails and other libraries. Even though Rails is an important factor in my current productivity, since I&#8217;m taking a long term view, I didn&#8217;t want to exclude a fantastic language simply because it&#8217;s lacking something that Ruby was also lacking N years ago.
</p>
<p>
Due to the cost of researching, learning and switching to a new programming language, I only considered languages that had the potential of offering a significant improvement in one or more areas without losing too much in other areas.
</p>
<p>
The candidates I eventually selected fell into two groups. Both groups have strong <em>functional</em> capabilities, good efficiency, and long, successful track records. I believe that even the best programming language designers make serious mistakes which can only be identified with the hindsight of years of use. It&#8217;s possible that someone is about to release a brand new language that has the potential to be the most productive for me personally; however, I&#8217;m not willing to take the risk to learn it.
</p>
<h3>The Lisp Family</h3>
<p>
Lisp has a very long track record of success and adaptability. In fact, if I was forced to program in a single programming language from now on, I would probably choose a Lisp since I think it would have the greatest likelihood of being able to adapt.
</p>
<p>
The Lisp family has dynamic typing which I&#8217;ve grown to love with Ruby, but most also allow type declarations for efficiency. Lisp also appears to have a more fundamental nature than most languages. I&#8217;ve heard it said that Lisp was more discovered than invented.
</p>
<p>
I first became interested in Lisp when I learned that Ruby was influenced by it. My interest was reinforced by some of Paul Graham&#8217;s essays &amp; books. I like the exploratory and dynamic nature of developing Lisp &#8211; this is mostly from reading comments of others, but I&#8217;ve tasted a small part of this when evaluating Lisp code in Emacs and having it be available immediately.
</p>
<p>
<strong>Logo</strong> is first on the list simply because it&#8217;s both a Lisp and a great language for teaching children how to program, so I can kill two birds with one stone.
</p>
<p>
<strong>Scheme</strong> is next because it&#8217;s a natural sequel to Logo and I <em>still</em> want to work through &#8220;The Structure and Interpretation of Computer Programs&#8221;. The fact that Paul Graham chose mzcheme to create his Arc language is a good &#8220;letter of recommendation&#8221;. Scheme <em>feels</em> the most fundamental, simple &amp; clean thus far.
</p>
<p>
<strong>Common Lisp</strong> is after Scheme due to its eminent practicality and completeness. It has plenty of warts, but also plenty of power and functionality. It&#8217;s been called a great, big, ball of mud &#8211; but in a good way ;)
</p>
<p>
Lastly, is <strong>Clojure</strong>. It&#8217;s last in the Lisp family because I want to learn Scheme &amp; Common Lisp first so I&#8217;ll be better equipped to judge Clojure. This will also allow more time for Clojure to mature. Clojure has a focus on functional programming &amp; concurrency that is <em>symbiotic</em> with the Java platform. The latter provides a quick start and access to Java libraries, the JVM infrastructure, etc., but my preference would be to not be dependent on the JVM in the long run. I&#8217;ll withhold judgment until I&#8217;ve learned it and used it for a while.
</p>
<h3>The ML Family</h3>
<p>
I&#8217;m least familiar with the ML family and with functional programming in general. I&#8217;ve spent most of my career studying and using imperative, object-oriented programming languages.
</p>
<p>
I think the ML family is worth studying because:
</p>
<ul>
<li>Functional programming may be beneficial with respect to concurrency.</li>
<li>Prog. Lang. researchers seem to be enamored with ML family.</li>
<li>There are enough anecdotal testimonies of productivity to warrant further study.</li>
</ul>
<p>
<strong>Standard ML</strong> is an important functional language that differs from Haskell in that it&#8217;s <em>impure</em>, i.e. it allows side effects, and it&#8217;s <em>strict</em>, i.e. not lazy. It shares Hindly-Milner static typing with Haskell. The community seems rather tiny, and I expect that if I go with a static typed language it will likely be Haskell, but I wanted to learn Standard ML first because of its historical importance and to be able to compare an impure/strict language with a pure/nonstrict language.
</p>
<p>
<strong>Haskell</strong> is probably the most different programming language from what I&#8217;m used to. This, in and of itself, has some advantages with respect to gaining new perspectives and ideas. In some ways, it&#8217;s a language that has taken things to extremes with respect to functional purity and laziness.
</p>
<p>
The community is <em>very</em> active. It offers a great compiler (GHC), software transactional memory, a decent base of libraries, etc.
</p>
<p>
At this early stage, I&#8217;m skeptical of static typing, functional purity and laziness, so becoming proficient in Haskell is a great opportunity to be able to determine how I feel about those.
</p>
<h2>The Plan</h2>
<p>
Rather than go through the candidates sequentially, I&#8217;m going to try and make progress on two tracks concurrently to allow me to compare concepts from both families:</p>
<table border="1" cellpadding="3">
<tr>
<th>ML Family</th>
<th>Lisp Family</th>
</tr>
<tr>
<td>Standard ML</td>
<td>Logo</td>
</tr>
<tr>
<td>Haskell</td>
<td>Scheme</td>
</tr>
<tr>
<td></td>
<td>Common Lisp</td>
</tr>
<tr>
<td></td>
<td>Clojure</td>
</tr>
</table>
<p>
<br />
I&#8217;m curious to find out how I feel about these languages after I&#8217;ve achieved some skill with them, but I think becoming proficient in the Lisp and ML families will be time well spent. At minimum, I&#8217;ll be better equipped to compare other languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2009/04/27/2009-programming-language-plan/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>2008 Programming Language Plan</title>
		<link>http://lojic.com/blog/2008/01/17/2008-programming-language-plan/</link>
		<comments>http://lojic.com/blog/2008/01/17/2008-programming-language-plan/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 22:12:17 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[logo]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/2008/01/17/2008-programming-language-plan/</guid>
		<description><![CDATA[I&#8217;ve learned a number of programming languages since I began programming 25 years ago. Earlier in my career, my choice of which programming language to learn was largely driven by external factors such as a class or job requirement, or the expectation of job demand in the future.
More recently I&#8217;ve enjoyed learning new programming languages [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve learned a number of programming languages since I began programming 25 years ago. Earlier in my career, my choice of which programming language to learn was largely driven by external factors such as a class or job requirement, or the expectation of job demand in the future.</p>
<p>More recently I&#8217;ve enjoyed learning new programming languages both for the joy of learning something new, and for an increase in productivity.</p>
<p>While it&#8217;s true that no programming language is a <em><a href="http://en.wikipedia.org/wiki/No_Silver_Bullet">silver bullet</a></em>, I&#8217;ve found that the choice of programming language can provide a dramatic increase in productivity &#8211; much more so than many have asserted. The benefit can be direct, by allowing the creation of a solution to a particular problem with less time and effort than it would take using another language, or it can be an indirect by providing new ways to think about a solution.</p>
<p>Do you think language affects how we think?</p>
<p><strong>The Past</strong></p>
<p>In 1982, I spotted a Radio Shack Color Computer in a store window and immediately applied for a Radio Shack credit card which had a credit limit ($500) sufficient to purchase the computer which had 4K of RAM (I later upgraded to 16K) and no external storage (unless you count the ability to hook up a cassette recorder). Contrast the 16K RAM of that early machine with my current 2,097,152K RAM :)</p>
<p>That was the beginning of a life long interest in programming.</p>
<p>In the language list below, bold indicates a more significant professional involvement, and the year indicates when I first learned the language. I&#8217;ve also likely forgotten a few:</p>
<ol>
<li>1982 &#8211; Radio Shack Extended Color BASIC</li>
<li>1983 &#8211; 6809e Assembler</li>
<li>1983 &#8211; Pascal</li>
<li>1984 &#8211; HP 48SX RPL</li>
<li><strong>1984 &#8211; S/360 Assembler</strong></li>
<li>1985 &#8211; COBOL</li>
<li>1985 &#8211; dBase III / Metafile</li>
<li><strong>1985 &#8211; C</strong></li>
<li><strong>1985 &#8211; 8088/8086 Assembler</strong></li>
<li><strong>1986 &#8211; C++</strong></li>
<li><strong>1996 &#8211; Java</strong></li>
<li>1997 &#8211; Perl</li>
<li><strong>2002 &#8211; C#</strong></li>
<li>2004 &#8211; Python</li>
<li><strong>2005 &#8211; JavaScript</strong></li>
<li><strong>2006 &#8211; Ruby</strong></li>
<li>2007 &#8211; PHP</li>
</ol>
<p><strong>The Present</strong></p>
<p>Currently, I program primarily in Ruby, followed by JavaScript and the occasional PHP script. Ruby is the most productive programming language I&#8217;ve used thus far. The combination of power, pragmatism &#038; pleasure in programming is hard to beat. If it also had performance, it would be a truly great language.</p>
<p>I&#8217;ve also begun <a href="http://lojic.com/blog/2008/01/05/learning-logo-part-one/">learning Logo</a> as I teach my daughter how to program. Logo is a great introduction to the Lisp family, so I hope to leverage it as I learn Scheme and Common Lisp later this year.</p>
<p><strong>The Future</strong></p>
<p>After completing the Logo course with my daughter, I plan on moving on to Scheme as I go through <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2FStructure-Interpretation-Computer-Programs-Engineering%2Fdp%2F0262510871%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1200604826%26sr%3D8-2&#038;tag=lojiccom-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325">Structure and Interpretation of Computer Programs</a> which some have called the greatest computer science text ever written.</p>
<p>After Scheme I plan on learning Common Lisp which has the <em>potential</em> to replace Ruby as my primary programming language.</p>
<p>Beyond Logo/Scheme/Common Lisp, the following languages are of interest:</p>
<ul>
<li>Haskell</li>
<li>Erlang</li>
<li>Lua</li>
<li>ML</li>
<li>OCaml</li>
</ul>
<p>If you know of candidates for a future programming language, feel free to add it in a comment.</p>
<p>You may notice that Smalltalk is lacking from the lists above. Despite its prominence in programming language history, I currently don&#8217;t feel that Smalltalk is sufficiently better/different than Ruby to warrant an investment in learning it.</p>
<p>After focusing on <em>object oriented</em> for twenty years, I have more of an interest in the <em>functional</em> world of programming languages (and multiple dispatch is cool :) ).</p>
<p><strong>Update:</strong> I was just over at <a href="http://news.ycombinator.com">Hacker News</a> and saw something I&#8217;ve seen many times before. In a nutshell, some guy was stating that Paul Graham&#8217;s success with ViaWeb had little to do with his choice of programming language (Lisp) and more to do with him just being a good hacker. In other words, he could&#8217;ve written it in any language. I&#8217;m so glad Paul responded because his response confirms my thoughts on the matter:</p>
<blockquote><p>
What a weird situation. I keep trying to tell people Lisp is great, and they say, no, no, you guys were just really good programmers. But if I&#8217;m such a good programmer, why don&#8217;t they believe me?
</p></blockquote>
<p>Paul Graham has written <strong>a lot</strong> on Lisp and is one of the main factors in me becoming interested in Lisp (along with the fact that Ruby pulled a lot of good ideas from it), but the simple quote above communicates volumes IMO.</p>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2008/01/17/2008-programming-language-plan/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Learning Logo &#8211; Part One</title>
		<link>http://lojic.com/blog/2008/01/05/learning-logo-part-one/</link>
		<comments>http://lojic.com/blog/2008/01/05/learning-logo-part-one/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 21:37:01 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[logo]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/2008/01/05/learning-logo-part-one/</guid>
		<description><![CDATA[Table of Contents

Part Two
Part Three
Part Four

I decided last spring that it was a good time to begin teaching my eldest daughter how to program. She was eleven at the time and had demonstrated both interest and aptitude. So after researching various programming languages, I chose to use the Logo programming language &#8211; specifically, Berkeley Logo.
There [...]]]></description>
			<content:encoded><![CDATA[<h2>Table of Contents</h2>
<ul>
<li><a href="http://lojic.com/blog/2009/05/06/learning-logo-part-2/">Part Two</a></li>
<li><a href="http://lojic.com/blog/2009/06/28/learning-logo-part-3/">Part Three</a></li>
<li><a href="http://lojic.com/blog/2009/07/26/learning-logo-part-4/">Part Four</a></li>
</ul>
<p>I decided last spring that it was a good time to begin teaching my eldest daughter how to program. She was eleven at the time and had demonstrated both interest and aptitude. So after researching various programming languages, I chose to use the Logo programming language &#8211; specifically, Berkeley Logo.</p>
<p>There are many good programming languages to choose from to teach children how to program depending on their abilities and interests, but I felt the benefits of Logo gave it the edge. It has much of the power of the Lisp family of languages but with a simpler syntax. The syntax is very uniform which saves children from having to learn too many inconsistent oddities of other languages (including my current favorite, Ruby). I had a preconceived idea that Logo was primarily about turtle graphics, so I was quite surprised when I dug a little deeper and found a very expressive language built on a solid foundation. Having said that, I think the availability of turtle graphics in Berkeley Logo is a big plus for allowing visual feedback for children.</p>
<p>In August, I wrote a <a href="http://lojic.com/blog/2007/08/31/logo-ruby-javascript/">blog post</a> comparing a short function (from Brian Harvey&#8217;s home page) in Logo and several other languages. Several people added other versions in the comments. It may give you a glimpse of the conciseness and expressiveness of Logo.</p>
<p>In deciding on a programming language, I purposely ignored IDEs. In fact, I&#8217;ve discovered that more powerful languages are much less dependent on the availability of good IDEs. For example, when I switched from Java to Ruby, I didn&#8217;t miss Eclipse at all, and I&#8217;m much more productive with Ruby and a good text editor than I was with Eclipse and Java. On the other hand, I&#8217;ve heard some glowing testimonial from Smalltalk and Lisp IDE users, so I expect I&#8217;ll be experimenting with Lisp IDEs in the future.</p>
<p><strong>Getting Started</strong></p>
<p>Many thanks to <a href="http://www.cs.berkeley.edu/~bh/">Brian Harvey</a> of UC Berkeley both for UCBLogo (along with other contributors) and for making excellent teaching materials freely available.</p>
<p>On Ubuntu Linux, simply install the ucblogo package. This will also install a PDF reference manual for Berkeley Logo which I recommend becoming familiar with.</p>
<p>You can also find links for other platforms on <a href="http://www.cs.berkeley.edu/~bh/">Brian Harvey&#8217;s home page</a>.</p>
<p>Here are links to the free text books:<br />
<a href="http://www.cs.berkeley.edu/~bh/v1-toc2.html">Computer Science Logo Style Volume 1: Symbolic Computing</a><br />
<a href="http://www.cs.berkeley.edu/~bh/v2-toc2.html">Computer Science Logo Style Volume 2: Advanced Techniques</a><br />
<a href="http://www.cs.berkeley.edu/~bh/v3-toc2.html">Computer Science Logo Style Volume 3: Beyond Programming</a></p>
<p>There is also a comp.lang.logo usenet group. You can access that via an nntp reader, or via Google below:<br />
http://groups.google.com/group/comp.lang.logo/topics?hl=en</p>
<p><strong>Methodology</strong></p>
<p>My teaching methodology thus far has simply been to have my daughter read a chapter, and then complete a short assignment of questions and programming exercises that I&#8217;ve designed to ensure she&#8217;s mastered the important concepts in the chapter. I&#8217;ll spend some time with her explaining the solutions to problems she may have missed.</p>
<p>If there&#8217;s interest, I can provide the complete set of chapter assignments including questions &#038; answers and programming problems &#038; solutions once we&#8217;ve completed volume 1. Feel free to leave a comment, if you&#8217;d like a copy.</p>
<p><strong>Some Quotes</strong></p>
<p>Here are some quotes from the preface of &#8220;Computer Science Logo Style vol 1&#8243; to <em>whet your appetite</em> :)</p>
<blockquote><p>
The truth is that Logo is one of the most powerful programming languages available for home computers.
</p></blockquote>
<blockquote><p>
In Logo there is only one syntax, the one that invokes a procedure.
</p></blockquote>
<blockquote><p>
More powerful languages are based on some particular mathematical model of computing and use that model in a consistent way. For example, APL is based on the idea of matrix manipulation; Proglog is based on predicate calculus, a form of mathematical logic. Logo, like Lisp, is based on the idea of composition of functions.
</p></blockquote>
<p><strong>Conclusion</strong></p>
<p>I highly recommend learning Logo whether you&#8217;re teaching your children to program or you simply want to learn another programming language. I&#8217;ve found both to be beneficial to my professional programming career. The Berkeley version of Logo is very powerful and has the following special features (from the intro to the UCBLogo reference manual):</p>
<ul>
<li>Source file compatible among Unix, Windows &#038; Mac</li>
<li>Random-access arrays</li>
<li>Variable number of inputs to user-defined procedures</li>
<li>Mutators for list structure</li>
<li>First-class instruction and expression templates</li>
<li>Macros</li>
</ul>
<p>I&#8217;ve entitled this <em>Part One</em> because I intend to follow up with some more posts as we become more familiar with the language.</p>
<p>We&#8217;ve also been dabbling in some simple robotics projects. I would love to find a robotics controller, or kit, that allows programming in Logo &#8211; if anyone knows of such a thing, please let me know.</p>
<p>Happy programming :)</p>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2008/01/05/learning-logo-part-one/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Logo, Ruby &amp; JavaScript</title>
		<link>http://lojic.com/blog/2007/08/31/logo-ruby-javascript/</link>
		<comments>http://lojic.com/blog/2007/08/31/logo-ruby-javascript/#comments</comments>
		<pubDate>Sat, 01 Sep 2007 01:02:54 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[logo]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/2007/08/31/logo-ruby-javascript/</guid>
		<description><![CDATA[I&#8217;ve been teaching my eldest daughter to program in Logo over the summer. Brian Harvey has posted PDF files for a set of excellent books on learning to program in Logo on his web site. The Berkeley version of Logo he&#8217;s produced is really excellent. It&#8217;s not just your typical turtle graphics language; it has [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been teaching my eldest daughter to program in Logo over the summer. Brian Harvey has posted PDF files for a set of excellent books on learning to program in Logo on his <a href="http://www.cs.berkeley.edu/~bh/logo.html">web site</a>. The Berkeley version of Logo he&#8217;s produced is really excellent. It&#8217;s not just your typical turtle graphics language; it has arrays, macros, file processing, graphics, etc.</p>
<p>While perusing his site, I came across a tiny Logo program that demonstrates a little of its power. I was curious what it would look like in Ruby, so I ported it, then I had to see what it looked like in JavaScript.</p>
<p>The formatting is a little messed up due to Wordpress, but each of the three choices functions is 4 lines long.</p>
<p>If anyone wants to add other languages, that would be great!</p>
<p>See the <a href="http://www.cs.berkeley.edu/~bh/logo-sample.html">sample page</a> for example output.</p>
<p><strong>Logo</strong><br />
<code><br />
to choices :menu [:sofar []]<br />
&nbsp;&nbsp;if emptyp :menu [print :sofar stop]<br />
&nbsp;&nbsp;foreach first :menu [(choices butfirst :menu<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sentence :sofar ?)]<br />
end<br />
choices [[small medium large]<br />
&nbsp;&nbsp;[vanilla [ultra chocolate] lychee [rum raisin] ginger]<br />
&nbsp;&nbsp;[cone cup]]<br />
</code></p>
<p><strong>UPDATE 9/2/07</strong>: Got an even more concise solution from Brian Harvey:</p>
<pre>
to choices :menu
   foreach crossmap "sentence :menu "print
end
</pre>
<p><strong>Ruby</strong><br />
<code><br />
def choices menu, sofar=[]<br />
&nbsp;&nbsp;if menu.empty?: puts sofar.join(' ')<br />
&nbsp;&nbsp;else menu[0].each {|item| choices(menu[1..-1],<br />
&nbsp;&nbsp;&nbsp;&nbsp;sofar + [item]) } end<br />
end<br />
choices [['small', 'medium', 'large'],<br />
&nbsp;&nbsp;['vanilla', 'ultra chocolate', 'lychee', 'rum raisin', 'ginger'],<br />
&nbsp;&nbsp;['cone', 'cup']]<br />
</code></p>
<p><strong>JavaScript</strong><br />
<code><br />
function choices(menu, sofar) {<br />
&nbsp;&nbsp;if (emptyp(menu)) print(sofar);<br />
&nbsp;&nbsp;else foreach(menu[0],<br />
&nbsp;&nbsp;&nbsp;function (x) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;choices(menu.slice(1), sofar.concat(x)); });<br />
}<br />
choices([['small', 'medium', 'large'],<br />
&nbsp;&nbsp;['vanilla', 'ultra chocolate', 'lychee', 'rum raisin','ginger'],<br />
&nbsp;&nbsp;['cone', 'cup']], []);<br />
</code></p>
<p>I had to create a few helpers for the JavaScript version:<br />
<code><br />
function emptyp(a) {<br />
&nbsp;&nbsp;return a.length === 0;<br />
}<br />
function print(list) {<br />
&nbsp;&nbsp;foreach(list, function (x) { document.write(x + ' '); });<br />
&nbsp;&nbsp;document.write('&lt;br /&gt;');<br />
}<br />
function foreach(arr, f) {<br />
&nbsp;&nbsp;for (var idx in arr) { f(arr[idx]); }<br />
}<br />
</code></p>
<p><strong>UPDATE:</strong> Use &lt;pre&gt; &lt;/pre&gt; tags to allow easier formatting of code. Bummer, I just discovered that Wordpress strips the &lt;pre&gt; tags from normal users :( I&#8217;ll go ahead and wrap code with it as they come in, so if your comment looks bad at first, it&#8217;ll be cleaned up shortly.</p>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2007/08/31/logo-ruby-javascript/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
	</channel>
</rss>

