2011-10-15

Art of Audrey Kawasaki

sheent02
Art of Audrey Kawasaki

programing language with BEGIN END; Google Dart

2011-10-15

Any programing language, that uses keywoards like BEGIN END instead of any [({brackets})] , is a fuckedup language.

2011-10-10

so, Google introduced a new language, Dart.

Q: What's Dart in a nutshell?
A: Javascript with Java syntax.

taxidermy high heels

dove high heel shoes
dove taxidermy high heels. Original source seems to be www.iris-schieferstein.de

2011-10-14

Emacs Lisp, Perl, Python: Building a Multiplication Table

So, i was reading Jon Snader (aka jcs)'s blog @ irreal.org, which lead me to watch a video of so-called VimGolf, but using emacs:

  • VimGolf in Emacs e003: Multiplication Table (2011-07) By Tim Visher. @ Source vimeo.com

The task is to generate a multiplication table like this:

1   2   3   4   5   6   7   8   9   10
2   4   6   8   10  12  14  16  18  20
3   6   9   12  15  18  21  24  27  30
4   8   12  16  20  24  28  32  36  40
5   10  15  20  25  30  35  40  45  50
6   12  18  24  30  36  42  48  54  60  
7   14  21  28  35  42  49  56  63  70
8   16  24  32  40  48  56  64  72  80
9   18  27  36  45  54  63  72  81  90
10  20  30  40  50  60  70  80  90  100

I thought this is interesting.

For this particular problem, i thought the most simple and practical way is just to use a programing language to spit it out. So i quickly wrote this:

(let (x i )
  (setq x 1 )
  (while (< x 10)
    (setq i 1 )
    (while (< i 10)
      (insert (format "%2d " (* x i)))
      (setq i (1+ i) )
      )
    (insert "\n")
    (setq x (1+ x) )
    )
  )

then just select the text and call “eval-region”. Or, with cursor at the end, call “eval-last-sexp” 【Ctrl+x Ctrl+e】.

the output is this:

 1  2  3  4  5  6  7  8  9 
 2  4  6  8 10 12 14 16 18 
 3  6  9 12 15 18 21 24 27 
 4  8 12 16 20 24 28 32 36 
 5 10 15 20 25 30 35 40 45 
 6 12 18 24 30 36 42 48 54 
 7 14 21 28 35 42 49 56 63 
 8 16 24 32 40 48 56 64 72 
 9 18 27 36 45 54 63 72 81 

Lisp is a bit verbose for this kinda thing due to the nested syntax. But you can write it in perl, python, ruby, bash, or any dynamic lang quickly, and press a button to have emacs call it and insert the result.

here's a python version:

for x in range(1,10):
    for i in range(1,10): 
        print "%(n)2d" % {"n":x*i},
    print "\n",

You can save this in a file, for example 〔temp.py〕. Then type 【Ctrl+u Alt+| python temp.py】, then it'll insert the output in your cursor position. (The 【Alt+|】 is the hotkey for “shell-command-on-region”. The 【Ctrl+u】 is “universal-argument”. When the command “shell-command-on-region” gets a empty argument, it'll insert output in buffer. Normally, it places output in the “*Messages*” buffer.)

Here's a perl version:

for $x (1..9) {
  for $i (1..9) {
    printf "%3d", $x*$i, " ";
  }
  print "\n";
}

Emacs Lisp Exercise of the Day: extract-url

Emacs Lisp Exercise of the Day: extract-url

Here's a fun exercise: write a command “extract-url” that will extract all url in a text selection and put them in a buffer.

For example, suppose you have this text:

<div>1, <a href="iraq_pixra2.html">2</a>, <a href="http://en.wikipedia.org/wiki/Idiom">Idiom</a>, <a href="iraq_pixra3.html">3</a></div>

After calling the command, you'll get in a separate buffer this text, one url per line:

iraq_pixra2.html
http://en.wikipedia.org/wiki/Idiom
iraq_pixra3.html

You can assume that the url will always be in href="…". For extra bonus, also extract URL enclosed in single quotes: href='…'. The extracted URLs must be in the order they apppear.

I'll post a solution tomorrow.

2011-10-13

Stephen Wolfram: The Background and Vision of Mathematica

“Stephen Wolfram: The Background and Vision of Mathematica”

functional language lambda logo tour

plt scheme lisp logo 1996
PLT Scheme's logo, ~1996.

Updated: A Lambda Logo Tour

emacs lisp: replace-digits-by-subscript solutions

Perm url with updates: http://xahlee.org/emacs/elisp_replace_subscript.html

Emacs Lisp Exercise: replace-digits-by-subscript

, 2011-10-13, 2011-10-19

Here's a interesting elisp coding exercise. I have this elisp functon:

(defun replace-digits-by-subscript (string)
  "Replace digits by Unicode subscript characters in STRING.
For example, 「103 and 42」 ⇒ 「₁₀₃ and ₄₂」."
  (let ((myStr string))
    (setq myStr (replace-regexp-in-string "0" "₀" myStr))
    (setq myStr (replace-regexp-in-string "1" "₁" myStr))
    (setq myStr (replace-regexp-in-string "2" "₂" myStr))
    (setq myStr (replace-regexp-in-string "3" "₃" myStr))
    (setq myStr (replace-regexp-in-string "4" "₄" myStr))
    (setq myStr (replace-regexp-in-string "5" "₅" myStr))
    (setq myStr (replace-regexp-in-string "6" "₆" myStr))
    (setq myStr (replace-regexp-in-string "7" "₇" myStr))
    (setq myStr (replace-regexp-in-string "8" "₈" myStr))
    (setq myStr (replace-regexp-in-string "9" "₉" myStr))
    myStr
    ))

You might think it's a bit verbose, or inefficient. But i can't think of way to improve it. Can you come up with a better version?

See also: Semantics of Symbols: Use of Unicode Subscript Digit Characters @ http://xahlee.blogspot.com/2011/10/semantics-of-symbols-use-of-unicode.html

Solution

Rob Shinn suggested that the subscript chars can be obtained from the digit chars by a trip to their character set code points. I implemented his idea like this:

(defun replace-digits-by-subscript2 (string)
  (let ((myStr string) (ii 0))
    (while (< ii 10)
      (setq myStr (replace-regexp-in-string (char-to-string (+ ii 48)) (char-to-string (+ ii 48 8272)) myStr) )
      (setq ii (1+ ii))
      )
    myStr
    ))

This is a good solution, though a bit hack, because it depends on the code points in a charset. In this case, it can be carried out because their code point happens to have a constant difference. The char “0” has unicode code point 48, the char “1” has unicode code point 49, etc. The char “₀” has code point 8320, the char “₁” has code point 8321, etc. They have a constant difference of 8272.

Independently, Jon Snader (aka jcs) gave the following solution (irreal.org), similar in idea but without the loop. Here's the code:

(defun replace-digits-by-subscript3 (string)
  (replace-regexp-in-string "[0-9]"
    (lambda (v) (format "%c" (+ (string-to-number v) 8320))) string) )

This code is a excellent use of “format”. But more importantly, new to me is that:

• The second argument to “replace-regexp-in-string” can be a function. Elisp will feed this function the matched text and use the function's return value as replacement string.

Independently, Anonymous wrote this solution:

(defun replace-digits-by-subscript4 (string)
  (replace-regexp-in-string "[0-9]"
    (lambda (arg) (string (aref "₀₁₂₃₄₅₆₇₈₉" (string-to-number arg)))) string) )

This is a excellent solution, probably best of all possible solutions. It is very clever, yet doesn't rely on charset. It relies on this fact:

• The subscript chars can be indexed by the corresponding digits. e.g. (string (aref "₀₁₂₃₄₅₆₇₈₉" 3)).

The use of “aref” is also new to me. Salute to Anonymous!

Note that “aref” is for extracting elements of array (e.g. string, vector). “elt” is for extracting elements of any sequence (e.g. string, vector, list). “nth” is just for list.

(info "(elisp) Sequences Arrays Vectors")

See also: Emacs Lisp Tutorial: List & Vector.

2011-10-19 Extra thanks to Jon Snader for discussion.

2011-10-12

Steve Yegge's Google Platforms Rant

this article is starting to circulate wildly. It's related to google, amazon, microsoft, tech start ups, engineering, vision.

〈Steve Yegge's Google Platforms Rant〉 @ http://xahlee.org/w/steve_yegge_google_platforms_rant.html

Steve Yegge is a programer at Google, well-known to public due to his blog. The article is his opinion and criticism about how Google is not a platform and how it should be.

By the way, for you programers out there, Yegge is a well-known emacs and lisp fan from his infamous blog. His articles tend to be verbose and meandering and long, but always very thoughtful. He is also a expert at Java, Javascript, perl, python, ruby, lisp, among others. Of his emacs work, he has implemented a advanced javascript mode called “js2-mode”, which features real-time syntax validation. It's about 10k elisp lines, which includes a javascript parser. He has also written, a separate but abandoned project, called “ejacs”, which is a javascript interpreter implemented in emacs lisp. Also ~10k lines. See:

Emacs Lisp Quiz: replace-digits-by-subscript

Emacs Lisp Quiz: replace-digits-by-subscript

Here's a interesting question. I have this elisp functon:

(defun replace-digits-by-subscript (string)
  "Replace digits by Unicode subscript characters in STRING.
For example, 「103 and 42」 ⇒ 「₁₀₃ and ₄₂」."
  (let ((myStr string))
    (setq myStr (replace-regexp-in-string "0" "₀" myStr))
    (setq myStr (replace-regexp-in-string "1" "₁" myStr))
    (setq myStr (replace-regexp-in-string "2" "₂" myStr))
    (setq myStr (replace-regexp-in-string "3" "₃" myStr))
    (setq myStr (replace-regexp-in-string "4" "₄" myStr))
    (setq myStr (replace-regexp-in-string "5" "₅" myStr))
    (setq myStr (replace-regexp-in-string "6" "₆" myStr))
    (setq myStr (replace-regexp-in-string "7" "₇" myStr))
    (setq myStr (replace-regexp-in-string "8" "₈" myStr))
    (setq myStr (replace-regexp-in-string "9" "₉" myStr))
    myStr
    ))

You might think it's a bit verbose, or inefficient. But i can't think of way to improve it. Can you come up with a better version?

See also: Semantics of Symbols: Use of Unicode Subscript Digit Characters @ http://xahlee.blogspot.com/2011/10/semantics-of-symbols-use-of-unicode.html

2011-10-18 See solutions at http://xahlee.org/emacs/elisp_replace_subscript.html

Semantics of Symbols: Use of Unicode Subscript Digit Characters

Found a new use of unicode subscript characters. These: {₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉}. In many of my web articles, they are devided into several pages. For example, titled: “Algorithmic Mathematical Art (page 1)”, and the second page would be titled “Algorithmic Mathematical Art (page 2)”, etc. I find those “(page 1)” etc too verbose and distracting. Now i just use subscripts. Like this:

Am not completely satisfied. I think i should add a subscript "p" there too, like these: {ₚ₁ ₚ₂ ₚ₃}, so it makes the semantics more unique. With just subscript digits, it's still too syntactically ambiguous, because subscript of digits could appear in lots other places for different purposes. But for now, i'll let it be.

For more articles about semantics of symbols, see:

The Musical Qualities of Languages

new: 〈The Musical Qualities of Languages〉 @ http://wordy-english.blogspot.com/2011/10/musical-qualities-of-languages.html

Microsoft Arc Touch Mouse

Perm url with updates: http://xahlee.org/kbd/arc_touch_mouse.html

Microsoft Arc Touch Mouse

Xah Lee, 2011-10-12

Microsoft's got a new mouse, the Microsoft Arc Touch Mouse. Here's a video of its designer Young Kim introducing it:

Young Kim introducing the mouse in a interview.
Infomercial of Young Kim speaking on the design.
Review by Zollotech
ms arc mouse-s ms arc mouse side view-s ms arc mouse flat-s
“Microsoft Arc Touch Mouse” amazon

Now, let's philosophize about it the Xah Way. First of all, it's a portal mouse. That means, it's not the most comfortable, ergonomic, mouse. It's not for professional heavy-duty 8-hours-per-day gaming, 3D modeling, image editing.

Being a portable mouse, its attraction is limited, because, if you are on the go, you may not need a mouse at all. For example: ① You don't carry a mouse at all. The trackpad does fine for the occasional 1 or 2 hours use of a computer. ② These days, many will do fine with a tablet computer such as iPad amazon. With a tablet, you just touch the screen, you don't need a mouse at all. ③ For those programers on the go, tablet is out, but then, programers don't need to use the mouse that much.

So, now for the few who really like to have a mouse for the go, i suppose this is fine. Not sure the space-saving matters that much. As far as ergonomic and efficiency goes, it couldn't be worse than Apple's input devices.

2011-10-10

Writing Style: Logic and Phraseme

new article: Writing Style: Logic and Phraseme

A Story of Web Tech Politics: The Evolution of Javascript's Script Tag

Yesterday, i removed all type="text/javascript" on my site. That is:

<script type="text/javascript">

becomes

<script>

This is a story of political chaos of the web.

In the beginning of time, a time of Netscape kingdom, ~1996, it was just <SCRIPT>. Then, with Microsoft's meddling, with JScript and VBScript, it became language="JavaScript" or language="JScript". By ~1999, a entity called W3C emerged, over-peering correctness on earth, it declared that the attribute should be type="text/javascript", and is required. However, in practice, both the “language” and “type” are always optional, and no browser's parser actually give a flying fuck about it. Then, around ~2007, the standard body changed its mind and thought that the type really should be type="application/javascript" or type="application/ecmascript". (See: Internet media type) Nobody in their right mind ever used that. Then, in our glorious HTML5 era, ~2009, ruled by Google and Apple, in their HTML5 spec, it's back to <script>.

Epiphany In a Dream: Seat as Inverted Ass

Epiphany In a Dream: Seat as Inverted Ass

Had a weird dream. Hard to remember the details, but the gist is that it's a epiphany about a elegant description of a idea that's a mix of linguistics and art, and was said (or written) by someone, that i need to blog about it with reference.

Here i'll try to describe what i remember. You know that human ass is padded by muscle for sitting? Seats, leather seats, are in some sense its inverse. That is, a padded surface of skin. (think of bar stool) That's the epiphany part. Then, this was mentioned somewhere, i forgot where, but described in such a elegant way that shows some linguistic elegance and the gist of the idea.

while lucid dreaming near waking, i vividly recall i need to write it down and blog about it because it's such a gem, but then i was debating whether i should, because at the time the whole thing is crystal clear, and that this idea seems well known. But then i was trying hard to go over it again, get the details, just in case. What that little effort is what made this writting now possible. Of course, in the dream, it carries quite far more significance than what little sense i described here.

bar stool

Seat as inverted ass. LOL. That was the dream.

Embedding Computer Language Source Code on Web Pages

Semantic Web: Emerging Practice of Including Language Name in Embedding Computer Language Source Code on Web Pages

There's a new practice since HTML5 about embedding computer language source code on web pages.

Normally, you just use “pre”, like this:

<pre>
x = 5
print x
</pre>

However, there's no indication of what language it is. Indicating a language is desired because search engines and other tools can get that info and process it accordingly (such as syntax coloring tool). (this is the idea of semantic web.)

So, it appears, there's this practice of introducing the language info, by embedding a “code” tag with “class” set to “language-‹name›”. Like this:

<pre>
<code class="language-python">
x = 5
print x
</code>
</pre>

However, there's no standardized string for the language string.

Overall, this practice seems ad-hoc and questionable, but a mob-standard might be better than none.

What's the problem? For example, the semantic of “class” tag isn't designed to be used to encode language names. Also, having “code” nested inside “pre” is a redundant hack. A improvement might be:

<code class="language-python" style="white-space:pre;display:block">
x = 5
print x
</code>

But this throws-off intuition, because most people are much more familiar with “pre” tag. So, perhaps we can do:

<pre class="language-python">
x = 5
print x
</pre>

All of the above are hacks in using HTML Microformat as a way to embed info for semantic web. A proper solution is a dedicated tag in XHTML, but XHTML is going the ways of dinosaur. Among the html microformat hacks above, i can't say which one is superior.

For the politics of HTML5 and XHTML, see: Are You Intelligent Enough to Understand HTML5?HTML6: Your JSON and SXML SimplifiedHTML5 Doctype, Validation, X-UA-Compatible, and Why Do I Hate Hackers.

For pratical tips on syntax coloring source code on the web, see: Emacs: Syntax Color Source Code in HTMLSyntax Coloring with Google-Code-Prettify.