Archive for the ‘Thoughts’ Category.

Test post from my phone

iPhone 3G in Hong Kong (only in the New Territories?)

So I was watching some clips from Job’s WWDC keynote yesterday, and I saw that the iPhone 3G will be released in Hong Kong, one of the 77 countries (markets?) where Apple will be selling the new phone.

That’s all well and good, but let’s look at the close up:

Hong Kong island, Kowloon, and Lantau Island are totally missing.

For those not in the know, here’s a map of Hong Kong:

It’s disappointing that even a supposedly ‘classy’ joint like Apple gets simple things like this (ahem, geography) wrong.

Another case in point: CNN and France.

Reflection in Scheme

I’ve been mulling over this idea for a while.

Now that I’ve been programming (exclusively) in Scheme for the past two years, I realized that I have slowly — but surely — learned to accept and embrace one of the most controversial surface syntax in a programming language: the S-Expression.

The criticism to sexpr syntax are numerous, and most of them can be seen as silly once you have gotten used to it, however here lies the problem: most people never get past their initial reaction to sexpr. They see the parenthesis and just freeze up.

Lispers and Schemers are the first to point out the advantages to having such a syntax: it’s simple, easy to understand and parse, and concise. In the end, however, it actually all boils down to just one single thing: We know how to write awesome macro systems with a sexpr surface syntax.

And this is all well and good.

However, now that we have decided to stick with this syntax, and we have used it to our advantages to write many wonder macro systems, what else can we do with this decision?

In Scheme, when you write down a list of four elements, beginning with the word list like this:

(list 'apple 'banana 'cactus) => '(apple banana cactus)

You get a list with three elements. You can query it in the following ways:

(list?  '(apple banana cactus)) => #t
(length '(apple banana cactus) => 3
(first  '(apple banana cactus))   => apple
(last   '(apple banana cactus))   => cactus

So you are able to find out that it is a list, and from that, its length and its first and last element.

This is elementary stuff, and anyone learning Scheme would know this by the end of their first week in class. However, what about this?

(define hello (lambda () (display "Hello")))

This is again a list, of three elements. The first element is define, then hello and last is another list (which begins with the word lambda).

In R5RS Scheme, there’s virtually nothing you can do to query this structure. The most that you can do, as far as I know, is with MIT Scheme’s procedure? and procedure-arity procedures, which corresponds to list? and length for lists.

Wouldn’t it be cool if one could manipulate Scheme code (procedures) as easily as one could manipulate Scheme data (lists, vectors)? I don’t mean that there should be a procedure-car and procedure-cdr, but something more specific, like procedure-name and procedure-body. This can be extended to other constructs as well. Given:

(if (list? l) (length l) 0)

We could have

(expression-type? ##) => <if-expression>
(if-test          ##) => (list? l)
(if-then-clause   ##) => (length l)
(if-else-clause   ##) => 0

Why hasn’t this been done before? I did some literature research, and am surprised to see so little on this topic.

Recently, I came across Charlotte Herzeel’s talk at the S3 workshop, but I think she’s going about it in the wrong way because she’s only thinking about the manipulation of code as lists, using variations of car and cdr instead of something with more specific semantics attached to it. Perhaps her background in Common Lisp (instead of Scheme) maybe have something to do with that.

冷戰再冷戰再冷戰

Clarification

Digging the Scheme Underground

Now that I’m blogging again, I ought to write down what I have been doing for the past few months.

When I got back to the US last spring, I went to talk to Olin Shivers about my idea of implementing R5RS on top of Alan and Ian’s COLA runtime. While I think that is still a good idea, it didn’t pan out then and I moved on to work on something else.

Instead I have been working with Olin to restart the Scheme Underground effort that has (pretty much) been abandoned since the early 90s. Our initial plan was to work on a nice interactive shell that’s based on Olin’s work on scsh, however that idea was abandoned after realizing that the Tüebingen crew already did something similar with Commander S. However, with its customizable viewers, Commander S is actually quite a bit more than just a normal interactive shell, so I still think it’s interesting to implement our original (simpler) concept.

To get up to speed on Scheme, I learned about Termcap and Terminfo and ported Paul Foley’s terminfo.lisp to Scheme. I also took another Common Lisp project, Linedit, as inspiration and wrote my own Scheme version from scratch.

Lately, I have been working on porting MIT Scheme’s Edwin editor to Scheme48. I hope to get a terminal-based text-only version done before the beginning of the summer. Wish me luck.

A New Beginning

Didn’t feel like working this afternoon, so instead, I updated my blog software to WordPress 2.5.

Here’s some Scheme code for all of you fans out there:

(define-record-type keystroke
  (%make-keystroke %value %meta?)


  keystroke?
  (%value char-value)
  (%meta? meta?))

(define-record-discloser keystroke
  (lambda (k)
    `(


 Keystroke ,(keystroke->sexpr k) ,(keystroke-hash k) )))

(define
  

  (parse-key form)
  (if (list? form)
      (let ((tag (car  form))


            (val (cadr form)))
        (case tag
          ((


 control) (


 %control  (parse-key val)))
          ((meta)    (


 %meta     (parse-key val)))
          ((key)


      (%key     val))
          (


 else


       (error "This is not a valid key form " tag))))
      (%key form)))

Iran vs. USA

學習語言的心態

從台灣來的丸子在這裡給我留言,問該如何學習外語。她說,除了要有興趣之外,還有什麼技巧嗎?

我覺得,學習語言的技巧固然有,但是這些技巧在書裏寫着的多的是。技巧不是最大的問題。大多數的人都不會麻木地去讀,原因是他們懶,但也因此他們會有系統地去復習。再說,要學這些技巧並不難,技巧學多學少也不大重要。何況很多人雖然學會了各種各樣的技巧,但對學習語言還是感到非常困難。

這些人最大的障礙是心態,而不是技巧。

我以前常常會跟美國的朋友說笑。他們每次提起中文有多難的時候,我就對着說,「中文不難,11億人民的孩子都在學,他們不覺得難啊。」雖然是個笑話,但說的話是實在的。

最近,我跟一位北京人做了朋友。他在大學的時候移民到美國,已來了好十幾年了。閑聊時,他告訴了我他剛來到的經驗和故事,他說:

「我在大學裡的朋友,他們跟我一樣,都十幾二十歲。他們講了十幾年的英文,也上了十幾年的英文課。他們的一生都只在講英文。他們的心智,很理所當然的,也是十幾二十歲。」

「雖然我也是十幾歲,但是我在北京只上了五年的英語教育,英文也不是我的母語。來到美國,我照理也比不上一個比我有多四倍經驗的人。所以那時候的我,要講英文的話,心智也就只有五歲了-話我說錯了也沒關係,因為一個五歲大的小孩也會犯同一個錯誤的。」

有了一個這樣的看法,也像給了自己一張通行證:在說話的時候,與人交往的時候也可以想孩子一樣的大膽。這樣做,就很快能把要學的語言說的很流利了。

我覺得最重要是放膽去講,去寫。錯了的話要記得去把它改掉。這樣重複再重複,就夠了。

但是,放膽去練習了後,要知道自己的錯誤也並不容易。我覺得我自學的日本話就是這樣。雖然我已經到了可以和別人互相溝通的階段,而且遇見日本人時,他們也常會稱讚我,但是我知道我的日文並不是完美的。基於禮貌,他們也不想矯正我的錯誤了。到了這個地步,我知道的唯一的辦法就是要多注意別人說的話,希望可以把自己的錯了的盲點改正。

在學習外語的各位,一起努力吧!

城市

第二: 城市

最近開始看陳冠中的部落格,喜歡他看他描述中國的各個城市,也對他對中國社會的各種觀察感興趣。他說他最愛的是台北,說它是最有人情味的現代中文城市。我也很喜歡台北,覺得它的文化氣色比香港濃厚,也被它那種淡淡的古風吸引着。

我喜歡他筆下的香港。雖然離開了,我感覺到對香港的感情,他還是放不開。他分析近年香港和上海之間的鬥爭很精彩。這一篇令我察覺到香港的各種改變。現在的香港,我這一代的香港,是個金錢第一的世界大都會,而舊的香港,我爸媽那一代的香港,卻可能已在大眾的記憶裏,無影無蹤的消失了。

有趣的幾篇 :

其他的都值得一看。