Profile cover photo
Profile photo
Benjamin Russell
576 followers -
Scholar-aspirant who majored in computer "science." Occasionally discusses algorithms; _haiku_; Scheme, Haskell, and Smalltalk (in the context of programming language theory); astronomy; and some narratology.
Scholar-aspirant who majored in computer "science." Occasionally discusses algorithms; _haiku_; Scheme, Haskell, and Smalltalk (in the context of programming language theory); astronomy; and some narratology.

576 followers
About
Benjamin's posts

Post is pinned.
Announcement:  I have just created two separate Google+ Collections:

● English Scholar/Poet Persona Posts (primarily in English) (see https://plus.google.com/collection/wRotaB)
●日本語での侍・ヲタクのペルソナによる投稿 ["Japanese Samurai/Otaku Persona Posts"] (primarily in Japanese) (see https://plus.google.com/collection/sLeuaB)

Auto-follow has been enabled for the first collection, and has been disabled for the second collection.

Posts in the first collection shall represent the views/opinions of my English-language American-culture-based Slashdot-culture-influenced scholar/poet persona.

Posts in the second collection shall represent the views/opinions of my Japanese-language Japanese-culture-based 2ch-culture-influenced otaku persona.

Please note that these collections actually represent different personae, not simply different interests of a single persona.  For example, because ijime (group bullying) is a not a significant issue in academia in the United States, but is a significant issue in otaku subculture in Japan, my English-language scholar/poet persona shall be opposed to anonymity on the Internet, but my Japanese-language samurai/otaku persona shall be in favor of it.

Generally speaking, my English-language scholar/poet persona shall think in English within the context of undergraduate academia at Yale University, whereas my Japanese-language samurai/otaku persona shall think in Japanese within the context of the otaku subculture at Akihabara.

In addition, my English-language scholar/poet persona shall aim toward eventually becoming a researcher in computer science, whereas my Japanese-language samurai/otaku persona shall aim toward eventually becoming an "OtaKing" (leader of all otaku) in Japanese digital entertainment.

Here is a haiku poem to insult poke fun at both Guido van Rossum and Python while celebrating Ruby:

Guido van Rossum, Possum

Guido van Rossum!
Nothing but a big possum!
Python: Not so slick!
Objects, functions: They don't click!
Ruby: You're the one I pick!

-- myself, 4:05 AM, Friday, June 23, 2017

Post has attachment
Upon conducting some research on the use of Ruby in academia, I managed to find the following doctoral thesis that favorably selected Ruby over Python and Perl for an AI-related project:

Adam, J. (2006). Designing Emergence: automatic extraction of stigmergic algorithms from lattice structures (doctoral thesis). Retrieved from http://assets.lazyatom.com/thesis.pdf

This thesis was listed at the site entitled "The Ruby Bibliography" at http://rubybib.org/ .

According to page 79 of the thesis (page 96 of the PDF file),

"Ruby was selected for this project over the other scripting languages available because of its consistent object model (compared with Python and Perl), dynamic typing and powerful built-in datastructures. These are important features which form the basis of the flexibility to plug in different geometry implementations without requiring changes to the application logic, simulation system and other high-level system components. Ruby can load and use extensions written in C++ and existing C++ classes can be modified and extended within the scripting language. Ruby also has a very shallow learning curve, and most programmers can become fluent within a few hours of first coming into contact with it.

"The C++ objects have been augmented with Ruby code to perform high-level operations such as loading and saving files, generate brick orderings and extracting rule structures from the architecture itself. The algorithm extraction implementation and other architecture manipulation code is written entirely in Ruby. The user interface logic is also written in Ruby, making calls to the underlying OpenGL extension bindings available on each platform."

This example is encouraging: It demonstrates that Ruby can be a viable alternative for academia.

The next step might be to gather a collection of links or references to similar papers, and to publish them on some Ruby-related site.

The next step after that might be to find some way to increase the number and quality of efficient numerical libraries for Ruby so as to break the current advantage that Python currently holds over Ruby in that respect.

There must be some way to break the current preeminence that Python holds over Ruby in academia as a result of its preponderance of numerical libraries and status as a preferred introductory programming language at MIT. Not everybody prefers Python over Ruby, and I definitely do not.

Post has attachment
What is the most efficient means to turn the Python community against me so that I can motivate myself to learn Ruby to fight them?
-
votes visible to Public
0%
Troll comp.lang.python
100%
Insult Guido van Rossum

I need to find a way to turn the Python community against me so that I can motivate myself to learn programming in some competing programming language. Perhaps I should troll their main mailing list and get them to ban me without due cause. That might get me to write libraries for Ruby so that I could put Python out of business.

In the past, the best way to motivate myself to do anything has always been to get somebody else--preferably somebody important in the computer science community--to tell me not to do it.

For example, the only reason that I majored in computer science was that Professor Drew V. McDermott had told me, "I don't think that you're cut-out for computer science." His comment enraged me sufficiently to convince me to major in computer science, despite the need to sleep for only an average of 3 hours per day during the semester for 4 years, defeat mathematics phobia, and put up with 2 severe migraine headaches as well as an enema.

Despite what anybody else says, I consider Python an ugly language. Generally speaking, I hate whitespace-sensitive languages unless they rely on equational reasoning. Haskell is an exception to this rule because Haskell code must be formatted as mathematical equations in order to take advantage of equational reasoning; however, Python does not rely on equational reasoning, and therefore, is not exempt from this rule.

Sooner or later, I shall find some way to make myself infamous as a troll in the Python community. I shall get them to ban me from their mailing list. I might even get them to issue an edict urging them to flood the IP address of any computer I use with a massive DOS attack.

Once the Python community bans me, I shall get angry. I shall get off my high chair, get my hands dirty, and start writing libraries for Ruby. I shall prove to the silly community of the ugly Python language that their libraries are not everything. I shall prove that a single Ruby programmer can turn the tide against them. Above all, I shall prove that Ruby can be useful outside of Web development.

Now to find a way to get started.

Addendum (10:34 PM):

Another, even more effective, means would be to incite Guido van Rossum, the creator of the Python programming language, to tell me (without joking),

"I don't think that you're cut-out for programming."

In order to verify that he had actually written the comment, I would need to forward any such message back to an official e-mail address of his for confirmation; however, if I could obtain such confirmation, then I could self-license myself to start a war against Python using Ruby.

Then I would publicize his comment in my circle here, on my Twitter account, and on the comp.lang.ruby USENET newsgroup. I would gather hordes of Ruby programmers to put him in his place. They might write hundreds of Ruby libraries to provide the same functionality for Ruby that currently exists for Python outside of Web development.

Then I would start a campaign to use Ruby instead of Python in college introductory computer science curricula. I would show the silly Python crowd that MIT's Python course, "6.0001 Introduction to Computer Science and Programming in Python," isn't everything. I would find a way to prove that Ruby can replace Python in introductory computer science curricula at colleges of caliber equal to MIT.

Along the way, I would learn how to program again (in Ruby this time).

最近、ある空想時計技師の物語を視て思ったのだが、情報を扱う事を生業とする人間には主に2種類の思考パターンを持つ人がいるのではないだろうか:

A)状況から答えを導く出す人
B)答えから状況をくみ上げるひと

Aは、例えばプログラマーや作家、作曲家、研究者。先ず、用意された道具を使って、どうやって答えを導く出すかを考えるタイプ。

Bは、例えば評論家や較正係、ジャーナリスト、先生。先ず、既に用意された答えを見て、そこからどういう状況なのかを正確にくみ上げるタイプ。

Aは、例えば、何もないところに自分で楽譜を作る事が得意だが、必ずしも他の人の演奏を正確に評価する事は出来ない。作るのが得意で、評価は必ずしもそうではない。

逆に、Bは、例えば、誰かの作った演奏を聞いて、それが下手のものに聞こえてきて、我慢が出来ない。どこを直せばいいのかは正確に分かる。直したくて仕方がない。だが、何もないところに自分だけで作る事は出来ない。

この2つのタイプは、お互いと組んだ時に最大の効力を発揮すると思う。

例えば、ボクは、大学では一人では中々上手く複雑なプログラムを組めなかった。

だが、そんな時にある日、事前にそれぞれの役目を決めて、他の生徒と組んで一緒に一つのプログラムを組んでみた事があった。

教授が用意してくれたグラフィックスライブラリーを使い、相手は何もないところにどういう残りのプログラムを書けばいいのかの擬似コードを説明してくれた。彼は実際のプログラムを1行も書かなかった。

逆に、ボクは彼の提供してくれた説明に従って、Scheme言語でテトリスのプログラムの残りの部分をすべて書いた。その代わり、擬似コードを1行も書かなかった。

結果は徹夜の1晩で大成功。名付けて、『Schemetris』。合作だった。

多分、ボクはタイプB。元々子供時代、「評論家」に向いていると言われた事があった。特に、竹村健一氏の語っていた色々な評論が面白かった。

実際に、1981年頃に竹村健一氏と一度だけ、日本テレビであった事もあった。実は彼は学生時代、ボクが後で卒業したのと同じイェール大学にフルブライト制度で通っていた時代があって、その事で手紙を出して、『イェール大学入学の事で少し相談をしたいが、会ってもらえないでしょうか』と尋ねてみたら、驚いた事に気持ちよく応じてくれた。当時の詳しいお話の内容までは覚えていないが、彼とボクの母と一緒にタクシーに乗って東京駅の近くまで行った事までは覚えている。

ボクは、プログラミング言語界の竹村健一氏のような存在になりたい。評論はとてもとても面白いと思う。

いつも不思議に思うのだが、何故かプログラミングについてのお話は、いい頭の運動になるらしい。

例えば、プログラミング言語のお話を書いたり、フィボナッチ数列(Fibonacci sequence)等を計算する為の小さなプログラムをScheme言語やHaskell言語書いたりすると、何故か翻訳は翻訳のチェックのスピードが一時的に飛躍的に上がる。

大学でも似た現象を確認した事があった。大学時代の学友からも似たお話を聞いた事があった。その一人曰く、

『プログラミングはあまりにも難しいので、他の事が何でも容易く感じられてしまう。』

特にこの現象が顕著なのは、Scheme言語とHaskell言語。また、他の関数型言語でもよく感じる。それから、Ruby言語でも少しは感じる。

逆に、BASIC言語だと殆ど感じないが。

この現象があるからボクは趣味としての時々のプログラミングを中々止められない。特に関数型言語によるプログラミングは。

最近、Ruby言語とPython言語について、どうしても分からない事がある。

それは、いったい何故日本ではRuby言語の方がPython言語よりも評判がいいのに、欧米ではその逆なのか。どうしてもこの点が分からない。

ボクは何回も色んな比較例を見ているが、どうしてもRuby言語の方が「流れ」が掴みやすい気がする。スラスラ読める気がする。まるで「詩」のようである。

対して、Python言語を解読しようとすると、どうしても何回も前後左右に目を動かさないと流れがつかめない。

例えば、以下の同等の機能を持つ2つのプログラム。

Ruby版:

hamming = Enumerator.new do |yielder|
next_ham = 1
queues = { 2 => [], 3 => [], 5 => [] }

loop do
yielder << next_ham # or: yielder.yield(next_ham)

[2,3,5].each {|m| queues[m]<< (next_ham * m)}
next_ham = [2,3,5].collect {|m| queues[m][0]}.min
[2,3,5].each {|m| queues[m].shift if queues[m][0]== next_ham}
end
end

idx = 1
hamming.each do |ham|
case idx
when (1..20), 1691
p [idx, ham]
when 1_000_000
p [idx, ham]
break
end
idx += 1
end

Python版:

from itertools import islice

def hamming2():
'''\
A text documenting this function (stripped)
'''
h = 1
_h=[h] # memoized
multipliers = (2, 3, 5)
multindeces = [0 for i in multipliers] # index into _h for multipliers
multvalues = [x * _h[i] for x,i in zip(multipliers, multindeces)]
yield h
while True:
h = min(multvalues)
_h.append(h)
for (n,(v,x,i)) in enumerate(zip(multvalues, multipliers, multindeces)):
if v == h:
i += 1
multindeces[n] = i
multvalues[n] = x * _h[i]
# cap the memoization
mini = min(multindeces)
if mini >= 1000:
del _h[:mini]
multindeces = [i - mini for i in multindeces]
#
yield h

特に、Ruby版の方がPython版よりも関数型言語的な感じがする。それがその読みやすさに繋がっている気がする。何回読んでもこの感じが拭えない。

このように感じるのはボクだけなのだろうか?

Post has attachment
先程投稿した、A. Castro-Castilla氏の『The Best Programming Language (or How to Stop Worrying and Love the Code)』と題したプログラミング言語比較ブログの和訳(但し、『合理的』な言語と『恐竜』言語と『非合理的』な言語の比較の部分とScheme言語の解説の部分が和訳から抜けているようです)。

元の英語版では、以下のように分類されていました:

『合理的』:

● Haskell
● Ruby
● Python
● Scheme

『恐竜』:

● Common Lisp
● Perl
● BASIC
● Smalltalk

『非合理的』:

● F#
● Oz
● Prolog
● Shen

個人的には、彼のPython言語対Ruby言語の比較の内容には納得がいきません。具体的には、以下の理由でRuby言語の方がPython言語よりもスタイル的にいいと思います:

● より関数型プログラミング的なスタイルである
● Ruby言語はホワイトスペース文字を無視してくれる。つまり、1個の2バイトのホワイトスペース文字と2個の1バイトのホワイトスペース文字とそれぞれと同じように見合えるタブ文字の違いを気にしなくていい。これが日本語のコメントを入れたPython言語の長いプログラムだと、2個に見えるホワイトスペース文字がどれなのかをジーと眺めて、『どれなのか?」と思わないといけない事がある。
● Ruby言語の方が流れが掴みやすい(より詩的)。これがPython言語だと、流れをつかむ為に上下に交互に目を移動しなければならない事があり、面倒だと感じる事がある。例えば以下の同等の機能を持つ2つのコード:

Ruby言語版:

hamming = Enumerator.new do |yielder|
next_ham = 1
queues = { 2 => [], 3 => [], 5 => [] }

loop do
yielder << next_ham # or: yielder.yield(next_ham)

[2,3,5].each {|m| queues[m]<< (next_ham * m)}
next_ham = [2,3,5].collect {|m| queues[m][0]}.min
[2,3,5].each {|m| queues[m].shift if queues[m][0]== next_ham}
end
end

idx = 1
hamming.each do |ham|
case idx
when (1..20), 1691
p [idx, ham]
when 1_000_000
p [idx, ham]
break
end
idx += 1
end

Python言語版:

from itertools import islice

def hamming2():
'''\
A text documenting this function (stripped)
'''
h = 1
_h=[h] # memoized
multipliers = (2, 3, 5)
multindeces = [0 for i in multipliers] # index into _h for multipliers
multvalues = [x * _h[i] for x,i in zip(multipliers, multindeces)]
yield h
while True:
h = min(multvalues)
_h.append(h)
for (n,(v,x,i)) in enumerate(zip(multvalues, multipliers, multindeces)):
if v == h:
i += 1
multindeces[n] = i
multvalues[n] = x * _h[i]
# cap the memoization
mini = min(multindeces)
if mini >= 1000:
del _h[:mini]
multindeces = [i - mini for i in multindeces]
#
yield h

Castro-Castilla氏のブログによると、

『Haskell

 このHaskellという言語は、今回取り上げた言語の中では最も考え抜かれた高度なツールではないかと感じています。おおよそどんなニーズにも対応できるライブラリを有しており、ハードコアなコミュニティが存在します。敷居が高く、とっつきにくい言語であることは間違いありませんが、それでも私はHaskellがあなたの思考を押し広げ、プログラミング言語コミュニティに参加しているすばらしい頭脳を持った開発者たちに引き合わせてくれるはずだと考えます。

 実際にプログラムを組まなくても、Haskellを学ぶ価値は充分にあると思います。他の言語と比べると無名ではありますが、私はHaskellを”妥当な言語”に分類しました。実際、Haskellはさまざまな分野、特に金融業界でよく採用されているのです。Haskellは逐次型というより概念的な処理を行う関数を多く必要とするので、多少抽象的ではあります。しかし、それにもかかわらずHaskellのコードはたいていは非常にコンパクトで分かりやすいのです。個人的には、Haskellのシンタックスはあまり気に入っていません(構文が多すぎます)が、少なくともそれぞれの目的は明確なので、混乱しているようには見えません(Perlとは大違いですね)。美しく、一貫性のある言語です。実際に下のコードで確認してみてください。

binarySearch :: Integral a => (a -> Ordering) -> (a, a) -> Maybe a
binarySearch p (low,high)
| high < low = Nothing
| otherwise =
let mid = (low + high) `div` 2 in
case p mid of
LT -> binarySearch p (low, mid-1)
GT -> binarySearch p (mid+1, high)
EQ -> Just mid

...

 Python

 美しい言語です。私は特にブロック構造をインデントで示すところが気に入っています。いちいち面倒くさいセミコロンをつけなくてすみますからね。あまり気に入っているので、JavaScriptを書く時もこの方法で書いてしまうほどです。しかしこれは完全に好みの問題で、実際そのせいでPythonが嫌いだという人は大勢います。コードが読みやすく、シンタックスという負担から開発者をできる限り解放すべく設計されています。それが成功しているかどうかは議論の余地がありますが、この言語がすばらしいコミュニティに支えられているのは確かで、そのおかげで仲間のRubyよりも確固たる地位を築いています。この2つの言語のどちらを選択するかは常に難しい決断です。ただPythonの方が広く普及していているので、分野やアプリケーションの種類を選ばないという意味では、より理にかなった選択と言えるかもしれません。私がPythonを使うのは次のような場合です。

■ Web開発
■ 科学的計算やデータ分析
■ システム管理とツール
■ ゲーム/3Dアプリケーションのスクリプティング
■ クロスプラットフォーム対応

 洗練されたPythonのコードです。

from itertools import islice

def hamming2():
'''\
A text documenting this function (stripped)
'''
h = 1
_h=[h] # memoized
multipliers = (2, 3, 5)
multindeces = [0 for i in multipliers] # index into _h for multipliers
multvalues = [x * _h[i] for x,i in zip(multipliers, multindeces)]
yield h
while True:
h = min(multvalues)
_h.append(h)
for (n,(v,x,i)) in enumerate(zip(multvalues, multipliers, multindeces)):
if v == h:
i += 1
multindeces[n] = i
multvalues[n] = x * _h[i]
# cap the memoization
mini = min(multindeces)
if mini >= 1000:
del _h[:mini]
multindeces = [i - mini for i in multindeces]
#
yield h

...

 Ruby

 Ruby on Rails。Rubyがこのリストに名を連ねた理由は、これがすべてです。もちろん今では多くのプロジェクトでRubyが使われていますが、それもこれもRailsが誕生してからのことです。それ以前は、Rubyは日本発の無名のプログラミング言語にすぎませんでした。これは、「この手の言語はこれで決まり」と思われているところに、別の言語のキラーアプリケーション/フレームワークが登場して、その言語の人気を高めていくという完ぺきな例です。そのプロセスの中で優れたコミュニティが生まれ、さらに優れたキラーアプリケーション/フレームワークが作られていくのです。

 多くのRuby開発者から聞かされることであり、私自身も経験のあることですが、この言語のいいところは、その使い勝手にあります。言い換えると、これはイライラする言語の対極にある言語なのです。これがこの言語自体の特徴なのかRailsのおかげなのかは分かりませんが。metasploitの開発者たちは、当初からこの長所を明確に感じていたようです。

 以下はPythonでお見せしたものと同じアルゴリズムをRubyで書いたものです。異なるアプローチをとっていて、Rubyの方がわずかに関数型寄りであることが分かります。

hamming = Enumerator.new do |yielder|
next_ham = 1
queues = { 2 => [], 3 => [], 5 => [] }

loop do
yielder << next_ham # or: yielder.yield(next_ham)

[2,3,5].each {|m| queues[m]<< (next_ham * m)}
next_ham = [2,3,5].collect {|m| queues[m][0]}.min
[2,3,5].each {|m| queues[m].shift if queues[m][0]== next_ham}
end
end

idx = 1
hamming.each do |ham|
case idx
when (1..20), 1691
p [idx, ham]
when 1_000_000
p [idx, ham]
break
end
idx += 1
end

 (訳者注)この記事は途中までの翻訳になります。ScalaやPerlを含めたさらに多くの言語の紹介はコチラからどうぞ』

Post has attachment
An interesting tour by Álvaro Castro-Castilla exploring various different programming languages, including Haskell, Scheme, Ruby, and Python, in search of the "best" programming language.

Castro-Castilla categorizes programming languages into three groups: "reasonable" languages, "dinosaur" languages, and "unreasonable" languages. Some of the languages discussed are classified as follows:

"Reasonable":

* Haskell
* Scheme
* Ruby
* Python

"Dinosaur":

* BASIC
* Common Lisp
* Perl
* Smalltalk

"Unreasonable":

* F#
* Prolog
* Oz
* Shen

Of particular interest is the comparison of equivalent code snippets between Ruby and Python. Personally, I completely disagree with the author's assessment of the two languages, and highly prefer the style of the quoted Ruby code to that of the equivalent Python code because of the following reasons:

* The Ruby code is written in a more functional style.
* The Ruby code is not whitespace-sensitive. This is especially important if I write code that many include Japanese comments that include double-byte spaces, which are visually indistinguishable from both single-byte spaces and tab characters, because it can be very easy to mistype one double-byte space instead of two single-byte spaces in a very long Python program, and then be forced to stare at the code to figure out if what seems to be two spaces in a row is really:

- two single-byte spaces, or
- one double-byte space, or
- a tab character that is identical to both of the above

* The Ruby code tends to flow upon reading (giving it a more poetic feel), whereas the Python code seems to force me to keep going up and down in order to follow the logic. Specifically, the following Ruby code seems to flow more smoothly than the equivalent Python code:

Ruby code:

hamming = Enumerator.new do |yielder|
next_ham = 1
queues = { 2 => [], 3 => [], 5 => [] }

loop do
yielder << next_ham # or: yielder.yield(next_ham)

[2,3,5].each {|m| queues[m]<< (next_ham * m)}
next_ham = [2,3,5].collect {|m| queues[m][0]}.min
[2,3,5].each {|m| queues[m].shift if queues[m][0]== next_ham}
end
end

idx = 1
hamming.each do |ham|
case idx
when (1..20), 1691
p [idx, ham]
when 1_000_000
p [idx, ham]
break
end
idx += 1
end

Python code:

from itertools import islice

def hamming2():
'''\
A text documenting this function (stripped)
'''
h = 1
_h=[h] # memoized
multipliers = (2, 3, 5)
multindeces = [0 for i in multipliers] # index into _h for multipliers
multvalues = [x * _h[i] for x,i in zip(multipliers, multindeces)]
yield h
while True:
h = min(multvalues)
_h.append(h)
for (n,(v,x,i)) in enumerate(zip(multvalues, multipliers, multindeces)):
if v == h:
i += 1
multindeces[n] = i
multvalues[n] = x * _h[i]
# cap the memoization
mini = min(multindeces)
if mini >= 1000:
del _h[:mini]
multindeces = [i - mini for i in multindeces]
#
yield h

According to the blog entry,

"Haskell

"This language truly feels as a more advanced thinking tool than the others in this list. It has libraries for almost any need and it has a hard-core community. Arguably it’s a language with a high barrier of entry. It will expand your mind, and surround you with some of the brightest minds in the programming languages communities, in my opinion.

"I think Haskell is well worth learning, even if you don’t build any real program with it. Being a relatively obscure language, I chose to classify it as reasonable since it is actually used in several areas, and especially in the financial industry. Haskell’s code tends to be very compact and expressive, albeit a bit abstract, in the sense that you need lots of functions that are actually conceptual operations rather than steps of a process. I personally don’t like its syntax (I think it has way too much syntax), but at least it serves a purpose and doesn’t feel like clutter (I’m looking at you Perl!). This language feels beautiful and coherent. Take a look by yourself:

binarySearch :: Integral a => (a -> Ordering) -> (a, a) -> Maybe a
binarySearch p (low,high)
| high < low = Nothing
| otherwise =
let mid = (low + high) `div` 2 in
case p mid of
LT -> binarySearch p (low, mid-1)
GT -> binarySearch p (mid+1, high)
EQ -> Just mid

...

"Python

"A pretty language.I definitely like its whitespace-based block structure: you don’t need ugly semicolons all the time. I like this so much that I tend to write my Javascript this way. But this is very much a matter of taste, and as a matter of fact is the very reason many people don’t like the language. It’s a clean language that tries to take the burden of the syntax out of you shoulders. While it is debatable that it succeeds at this, the language is definitely supported by a great community, that put the it in a very strong position when compared to its pal Ruby. It’s always hard to choose between these two languages, although Python seems more widespread, and a more sensible choice for a variety of fields and applications. When would I use Python?

* Web development.
* Scientific computing and data analysis.
* System administration and tools.
* Game/3d application scripting.
* Cross-platform support.

"Nice Python code:

from itertools import islice

def hamming2():
'''\
A text documenting this function (stripped)
'''
h = 1
_h=[h] # memoized
multipliers = (2, 3, 5)
multindeces = [0 for i in multipliers] # index into _h for multipliers
multvalues = [x * _h[i] for x,i in zip(multipliers, multindeces)]
yield h
while True:
h = min(multvalues)
_h.append(h)
for (n,(v,x,i)) in enumerate(zip(multvalues, multipliers, multindeces)):
if v == h:
i += 1
multindeces[n] = i
multvalues[n] = x * _h[i]
# cap the memoization
mini = min(multindeces)
if mini >= 1000:
del _h[:mini]
multindeces = [i - mini for i in multindeces]
#
yield h

...

"Ruby

"Ruby on Rails. The single reason this language could ever be part of this list. Of course, nowadays it’s easy to see it in many other projects, but it all began with Rails. Before that, Ruby was an obscure programming language from Japan. This is a perfect example of how a killer app/framework spawned a great community which in turn made more killer apps/frameworks and made the language popular even though the place for this sort of language was supposedly taken.

"One thing I’ve heard from many Ruby developers and I had experienced myself, is the actual joy that comes from using it. In other words, it’s the contrary of a frustrating language, although I don’t know if this is something from the language or Rails itself. The guys at metasploit seemed to have it very clear since the beginning as well.

"Here’s the same algorithm shown in Python, this time in Ruby. It follows a different approach, which shows also the tendency of Ruby to use a slightly more functional style.

hamming = Enumerator.new do |yielder|
next_ham = 1
queues = { 2 => [], 3 => [], 5 => [] }

loop do
yielder << next_ham # or: yielder.yield(next_ham)

[2,3,5].each {|m| queues[m]<< (next_ham * m)}
next_ham = [2,3,5].collect {|m| queues[m][0]}.min
[2,3,5].each {|m| queues[m].shift if queues[m][0]== next_ham}
end
end

idx = 1
hamming.each do |ham|
case idx
when (1..20), 1691
p [idx, ham]
when 1_000_000
p [idx, ham]
break
end
idx += 1
end

...

"Scheme

"This is probably a controversial language to be on this list, but I have an explanation. The three main issues associated with this language are:

1. Lack of one true implementation and multiple competing ones of dubious quality.
2. Lack of libraries.
3. Poor performance.

"Well, the first one is partially true (there are too many implementations), but there are only a handful of good ones and you need to choose the one that best fits you. The second is also partially true: there are libraries, but they are scattered. There are some projects that offer alternatives, and lots of tiny projects out there. The fragmentation of the language is made obvious when looking for support code: you need to make it work with your implementation. However, this is often not so difficult or time-consuming, and most importantly, if you use Scheme implementations with good FFI support, such as Gambit or Chicken Scheme, you have easy access to all those libraries in C. I actually do it, and works great, contrary to what you may think. Finally, poor performance. This one is actually completely false. Implementations such as Gambit are very fast, and you have plenty of options for optimization (starting from algorithmic optimization, global Scheme compiler declarations, and of course, C code that can be easily interwoven with the Scheme code when necessary).

"Yes, I’m fanatical about Scheme, however, I admit it has one deadly weakness: it’s an awful language for sharing code, with a not-so-good community. It’s so flexible, that every single programmer wants its own little perfect solution to the task. It’s the complete opposite to Java: great for individual/small-team projects, prototyping and exploratory programming, unproven for large teams. But in those situations, is perfectly fine, and you can actually ride an extremely fast and pleasant development cycle. Lastly, another very interesting feature of the language: you can easily compile to Javascript with one of the Scheme-to-Js compilers, so you could enjoy the same kind of symmetry that you get when developing with Node.js on the server. The following are concrete examples where I’d use this language:

* For exploratory programming, when I don’t exactly know where I’m heading.
* For fast prototyping of ideas that don’t really require a large library only available in languages like Python or Ruby.
* For scripting large programs or platforms developed in C/C++.
* For building an application with large portions that need to be written from scratch.
* For games and OpenGL/ES-based multiplatform applications.

"Here you have three examples of Scheme code. You actually have to implement these functions yourself as they are not directly available across all implementations, even though they are rather useful and common enough. These would work across all implementations (provided they are R5RS-compatible).


;;! Recursive map that applies function to each node
(define (map** f l)
(cond
((null? l) '())
((not (pair? l)) (f l))
(else
(cons (f (map** f (car l))) (f (map** f (cdr l)))))))

;;! Explicit currying of an arbitrary function
(define (curry fun arg1 . args)
(if (pair? args)
(let ((all-args (cons arg1 args)))
(lambda x
(apply fun (append all-args x))))
(lambda x
(apply fun (cons arg1 x)))))

;;! Implementation of filter, with the match macro
(define (filter p lst)
(match lst
('() '())
(((? p) . tl) (cons (car lst) (filter/match p tl)))
((hd . tl) (filter/match p tl))))

"Take a look at these other interesting examples too.

"If you solve the issue of a minimal development framework (yourself or via projects like Scheme Spheres, then you are on a flywheel."
Wait while more posts are being loaded