莊周夢蝶

          生活、程序、未來
             :: 首頁 ::  ::  :: 聚合  :: 管理

          最近的工作

          Posted on 2008-05-21 11:45 dennis 閱讀(1960) 評論(4)  編輯  收藏 所屬分類: 動態語言涂鴉計算機科學與基礎
              轉眼間,來廣州快半年了,感覺還不錯。廣州如死魚所說的那樣,是個包容并且很有活力的城市,習慣了周末煲湯,去天河公園跑跑步,這生活還是挺舒適的,除了比較潮的天氣。
              最近跟公司鬧了點不愉快,在轉正時間上,其實不是多大的事,只是心里不舒服罷了,干起活來也沒什么激情了,呵呵。當然,手頭的工作咱還是要高效率地完成,做完兩個游戲后,現在轉到棋牌類,棋牌類游戲核心就兩個算法:隨機發牌和出牌判斷。隨機發牌算法,學習了云風的blog上提到的方法,感覺還可以接受;出牌規則判斷,倒是沒想象中的復雜,建立牌型的OO模型,一切都很簡單了。另外一個發現,用jdk6跑jruby1.1.1,比用jdk5跑效率(包括內存和CPU)好上很多,例如我們一個游戲進程,在使用jdk5時,CPU穩定在15%,內存85M,而改用jdk6后,cpu降到了%5以下,內存也縮減到70多M。
              搞完了之后,時間有點空閑,就想學點新東西,最后選擇了Prolog。Yep,非常地有趣,真正的聲明式編程語言。Prolog本質上就是兩個東西:規則和事實,由事實和規則出發,Prolog的推理系統將回答你的查詢(query)。有點類似現在流行中的規則引擎的概念,在對效率不是很考慮的場景中,嵌入一個Prolog引擎做規則引擎完全是可以的,java中有個tuProlog項目,可以關注一下。然后就是一直在讀的sicp,延時求值模擬無窮級數實在是相當地cool,大開眼界。這兩天一直在理解continuation這個概念,小有所得。一個表達式的求值可以分為兩個階段:“What to evaluate?”和“What to do with the value”,“What to do with the value”就是計算的Continuation。例如,scheme求值下列表達式:
          (if (null? x) (quote ()) (cdr x))
          先求值表達式(null? x),(null? x)就是“What to evaluate”,當(null? x)求值后,需要根據這個值來決定是執行(quote ())還是(cdr x),這個根據值來決定的過程就是Continuation。如果在每次函數調用時,同時傳入當前的continuation,那么就完全可以不要堆棧。call/cc就提供了這樣的一個語法糖,call/cc全稱就是call-with-current-continuation,要求參數是一個過程,調用這個過程,并且向這個過程傳入當前的continuation(一般稱為k,kont,或者Ruby中一般是c,cont),這就是call/cc為我們做的。call/cc是實現Continuation的方式之一,coroutine/fiber/yield也是實現continuation的方式。《The Scheme Programming Language》給出的輕量級進程機制的例子比較有趣:
          (define lwp-list '())
          (define (lwp thunk)
            (set! lwp
          -list (append lwp-list (list thunk))))
          (define start
            (
          lambda()
              (let ((p (car lwp
          -list)))
                (set! lwp
          -list (cdr lwp-list))
                (p))))
          (define pause
            (
          lambda()
              (callcc (
          lambda(k) 
                         (lwp (
          lambda () (k #f)))
                         (start)))))
          (lwp (
          lambda () (let f () (display "h") (pause) (f))))
          (lwp (
          lambda () (let f () (display "e") (pause) (f))))
          (lwp (
          lambda () (let f () (display "y") (pause) (f))))
          (lwp (
          lambda () (let f () (display "!") (pause) (f))))
          (lwp (
          lambda () (let f () (newline) (pause) (f))))
          (start)
          實現了代碼級的進程調度。


          評論

          # re: 最近的工作  回復  更多評論   

          2009-02-10 11:01 by QQ75902706
          你也在廣州天河.

          # seo11813  回復  更多評論   

          2015-12-28 14:57 by For example in the following example, the rhyme pa
          For example in the following example, the rhyme pattern is ABAB. Articles Writing Services are good for any kind of article that should be well-written. 4) Provide a good attention-grabbing title or header.

          # seo27677  回復  更多評論   

          2016-01-05 21:01 by No matter what product you sell or service you pro
          No matter what product you sell or service you provide, your website needs to cater to your customers. With the advent of Google's stated goal to improve a user's search experience, many websites and articles lost their coveted positions in Search Engine Ranking Positions (SERPs). Your product or service is written about in the form of short articles that usually offer information or some other useful content to readers.

          # bbbergamo92458  回復  更多評論   

          2016-01-19 23:33 by Having read this I thought it was rather enlighten
          Having read this I thought it was rather enlightening. I appreciate you spending some time and effort to put this content together. I once again find myself personally spending a significant amount of time both reading and posting comments. But so what, it was still worthwhile!
          主站蜘蛛池模板: 贵德县| 郧西县| 昭觉县| 台湾省| 尖扎县| 永城市| 吉木乃县| 呼伦贝尔市| 黄平县| 兴和县| 永康市| 苏尼特左旗| 临武县| 永丰县| 云南省| 株洲市| 胶南市| 平远县| 常山县| 奎屯市| 山东省| 柯坪县| 思茅市| 南丹县| 芜湖市| 平安县| 安阳市| 兴业县| 都匀市| 本溪| 息烽县| 西华县| 五峰| 梨树县| 浠水县| 固原市| 阳江市| 剑阁县| 浑源县| 永和县| 大余县|