dekudekuplex

プロフィール


DekuDekuplexです。

主に、Scheme言語、Haskell言語、そしてSmalltalk言語(Squeak実装)を勉強中です。

特に、SqueakベースのCroquet SDKベースのCobaltメタバースブラウザー兼ツールキット・アプリケーションには興味があります(「Main Page - Croquet Consortium」(http://www.opencroquet.org/index.php/Main_Page 参照)のビデオを参照)。

Smalltalkは一見、オブジェクト指向言語の為、関数型言語とは縁がないように見えるが、それは違う。実は、特徴的には関数型言語にある特徴を多く備えている(「Functional Objects, Functional Classes」(Matthias Felleisen著)(http://www.ccs.neu.edu/home/matthias/Presentations/ecoop2004.pdf 参照) のスライドを参照してください)。一般的な「オブジェクト指向言語」とは全然違う。最大の特徴は、手続きのパラメータによる変数の値の受け渡しをせず、オブジェクト同士のメッセージの受け渡し(「message passing」)にのみ頼ることです。これにより、オブジェクト同士のデータの受け渡しを大幅に簡素化出来、論理的構造も簡素化されます。

元々SqueakプロジェクトもあのApple社でAlan Kay氏とDan Ingalls氏によって始められたそうです(「Smalltalk.org™ | smalltalk | history.html」(http://www.smalltalk.org/smalltalk/history.html 参照)を参照):

> Squeak Smalltalk project started at Apple by Alan Kay and Dan Ingals. Squeak > is based on the Apple Smalltalk-80 system (and presumably license).

いつか、このツールを使って、現実の世界とバーチャル・ワールドをリンクさせ、現実の世界で現在行われているあらゆる価値を生む行為(勉強、仕事、経済取引など)をすべてバーチャル・ワールド内で実現出来るようにしたいのです!

そうすれば、朝寝坊も怖くなくなるし、無駄な交通費や交通時間を無くすことが出来るし、それに、何より、人付き合いが苦手な人間にとって住みやすい世界が作れる!貧乏人であっても、背が低くても、太っていても、痩せていても、仕草がヘンでも、夜行性であっても、友達がいなくても、もう怖くない!自分の能力だけを信じて、思いっきり世界を制覇出来る!そう、能力だけがものを言う、デジタルネイティブ(「NHKスペシャル デジタルネイティブ」(http://www.nhk.or.jp/digitalnative/ 参照)を参照)の理想の世界が作れる!

【今までのこのページに続く。現在(2009.10.21(水)現在)Squeak実装を勉強中です。何かが出来ましたら、そのウェブページのURLをここに掲載させて頂きます。勿論、Scheme言語のことも、Haskell言語のことも、まだまだ勉強中で、新しい何かが出来ましたら、それもここに掲載させて頂きます!】

「ハノイの塔」の問題

好きな電気計算科学関連の問題はハノイの塔です。以下に僕の作った「ハノイの塔」の問題を解決する為のプログラムをHaskell言語とPLT Typed Scheme言語で紹介させて頂きます:

Haskell言語

※このhanoiプログラムは、必ず「putStr (hanoi_shower (hanoi 1 2 3 n))」または「putStr (hanoi_shower (hanoi 'a' 'b' 'c' n))」のように使ってください。

-- hanoi_general_merged_v1.1.hs
-- Revised version of hanoi_general.hs, which was a Haskell function to compute the Towers 
-- of Hanoi problem recursively, merging hanoi and hanoi_helper
-- 
-- Usage: putStr (hanoi_shower (hanoi 1 2 3 n)), or 
--        putStr (hanoi_shower (hanoi 'a' 'b' 'c' n)), 
--        where the first three arguments of hanoi may be polymorphic types
--        (i.e., Chars, Ints, or any other suitable type), and n is the number
--        of discs to move from the source peg to the destination peg
-- 
-- Copyright(c) April 17, 2008, at 15:47, 
-- by Benjamin L. Russell
-- 
-- Update History:
-- 
-- Version 1.1
-- Added usage information.
-- April 22, 2008, at 21:47

hanoi :: a -> a -> a -> Int -> [(a, a)]
hanoi source using dest n
    | n == 1 = [(source, dest)]
    | otherwise = hanoi source dest using (n-1) 
                  ++ hanoi source using dest 1
                         ++ hanoi using source dest (n-1)

hanoi_shower :: Show a => [(a, a)] -> String
hanoi_shower moves = unlines ["Move " ++ show a ++ " to "++ show b ++ "." | (a, b) <- moves]

実行例:

__   __ __  __  ____   ___      _______________________________________________
||   || ||  || ||  || ||__      Hugs 98: Based on the Haskell 98 standard
||___|| ||__|| ||__||  __||     Copyright (c) 1994-2005
||---||         ___||           World Wide Web: http://haskell.org/hugs
||   ||                         Bugs: http://hackage.haskell.org/trac/hugs
||   || Version: Sep 2006       _______________________________________________

Haskell 98 mode: Restart with command line option -98 to enable extensions

Type :? for help
Hugs>:load "C:\\Program Files\\WinHugs\\hanoi_general_merged_v1.1.hs"
Main>putStr (hanoi_shower (hanoi 'a' 'b' 'c' 3))
Move 'a' to 'c'.
Move 'a' to 'b'.
Move 'c' to 'b'.
Move 'a' to 'c'.
Move 'b' to 'a'.
Move 'b' to 'c'.
Move 'a' to 'c'.
 :: IO ()
Main>
PLT Typed Scheme言語
普通のPLT Typed Scheme言語関数
;; hanoi-typed.ss
;; Typed Scheme version of Towers of Hanoi
;; 
;; Based on regular-plus function by Carl Eastlund.
;; Copyright(C) October 16, 2008, at 20:54, 
;; by Benjamin L. Russell

#lang typed-scheme

(: hanoi-typed (Number -> Void))
(define (hanoi-typed n)
  (hanoi-helper-typed 'A 'B 'C n))

(: hanoi-helper-typed (Symbol Symbol Symbol Number -> Void))
(define (hanoi-helper-typed source using destination n)
  (cond ((= n 1)
         (printf "Moving from disc ~a to ~a.\n" source destination))
        (else
         (hanoi-helper-typed source destination using (- n 1))
         (hanoi-helper-typed source using destination 1)
         (hanoi-helper-typed using source destination (- n 1)))))

実行例:

Welcome to DrScheme, version 4.1.1 [3m].
Language: Module.
> (hanoi-typed 3)
Moving from disc A to C.
Moving from disc A to B.
Moving from disc C to B.
Moving from disc A to C.
Moving from disc B to A.
Moving from disc B to C.
Moving from disc A to C.
> 
カリー化されたPLT Typed Scheme言語関数
;; hanoi-curried.ss
;; Curried Typed Scheme version of Towers of Hanoi
;; 
;; Based on curried-plus function by Carl Eastlund.
;; Copyright(C) October 16, 2008, at 20:54, 
;; by Benjamin L. Russell

#lang typed-scheme

(: hanoi-curried (Number -> Void))
(define (hanoi-curried n)
  ((((hanoi-helper-curried 'A) 'B) 'C) n))

(: hanoi-helper-curried (Symbol -> (Symbol -> (Symbol -> (Number -> Void)))))
(define ((((hanoi-helper-curried source) using) destination) n)
  (cond ((= n 1)
         (printf "Moving from disc ~a to ~a.\n" source destination))
        (else

         ((((hanoi-helper-curried source) destination) using) (- n 1))
         ((((hanoi-helper-curried source) using) destination) 1)
         ((((hanoi-helper-curried using) source) destination) (- n 1)))))

実行例:

Welcome to DrScheme, version 4.1.1 [3m].
Language: Module.
> (hanoi-curried 3)
Moving from disc A to C.
Moving from disc A to B.
Moving from disc C to B.
Moving from disc A to C.
Moving from disc B to A.
Moving from disc B to C.
Moving from disc A to C.
> 

これから・・・・・・

現在(平成20年10月17日(金曜日)現在)、回帰的な定義の「ハノイの塔」に代わる、高等関数的な定義の究極の面白い、創造しやすい、魔法的なプログラミング問題を模索中です。数値をいじるだけでは面白くありません。何か、もっと代表的でカタチとして想像し易い、楽しくて不思議な問題を探しています。見つけましたら、またここで報告させて頂きます。御楽しみに・・・・・・。

好きなことば

関連ページ

More ...