2003-09-01から1ヶ月間の記事一覧

The Philosophy of Ruby

Interview on artima.com http://www.artima.com/intv/ruby.html

http://www-ia.tu-ilmenau.de/~czarn/gmcl/

hello.txt

This code works in ruby, tcl, expect. # Although expect is subset of tcl. $ cat > hello.txt puts "Hello, world" ^D $ ruby hello.txt Hello, world $ tclsh hello.txt Hello, world $ except hello.txt Hello, world common points No need ( ... ) t…

#!/usr/bin/awk -f BEGIN { print "Hello, world" }

program hello; begin writeln ('Hello, world'); { Comment } end. $ gpc hello.pas $ ./a.out Hello, world

Tab

---------------------------------------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- -------7------------------------------------…

How to use unittest

import unittest define a class for test that extends TestCase override setUp, tearDown method implement test* methods for test cases run unittest.main() import unittest class Person: def __init__(self, name): self.name = name def getname(s…

How to make server program

import SockServer class for request that extends BaseRequesthandler class for server that extend TCP/UDP Server If you needs, with Fork/Thread MixIn import SocketServer ECHO_PORT = 23456 CRLF = '\r\n' class EchoRequestHandler(BaseRequestHa…

時間を所得

string date = ctime(time()) - "\n"; 文字列A - 文字列B で、文字列Aの中から文字列Bを取り除ける。 文字列A / 文字列B で、文字列Aを文字列Bでsplitした配列を返す。

YatAnotherWayToDo ...

from operator import mul def fact(num): if num

Python, Ruby, Pike でDesignPatternのBridgeパターンを実装してみた。 C++にも挑戦してみるが、インターフェースの定義で行き詰まる(TODO)

アキュームレータ

# let accgen n = let m = ref n in fun x -> m := m!+x; !m;;

C/C++言語ライクな関数

PeterNorvig氏のPython IAQより・・・ 他にも EnumやStructの簡単な実装が書かれてあった。 enumは、僕が昨日日記に書いたのとは別の方法だった。 簡単な例では、red,green,blue=range(3)から、 他の例ではクラスを使ってクラスの__dict__に直接読み込む方法…

Adapter/Adaptee pattern

pythiusプロジェクトのaop.pyも使ってみたが、 独自の実装でAdapterパターン with AOP from types import FunctionType from __future__ import nested_scopes import sys if sys.version_info[0:2] api(_adapter, adaptee): for name,value in _adapter.ite…

Enum

Pythonで列挙体を生成するユーティリティ関数作ってみた。 コンパイル時に型チェックしない言語/環境では、 その恩恵を受けられないため軽視されがちだけど。値の生成だけでも欲しくなった。ここでは名前のリストを渡して、 値が適当に重複しない値になって…

Stringクラスにメソッドを追加する。 String.prototype.toTwoDigit = function () { return (this.length) ? "0".concat(this) : this; } Ruby等の動的なスプリプト言語なら大抵はサポートしてる機能。 Python でプリミティブ型のクラスの拡張どうやってやる…

MEMO

SeRuby : Implement Self by Ruby http://kumiki.c.u-tokyo.ac.jp/~ichiyama/mt/archives/000026.html Python 構文木へのアクセス http://kumiki.c.u-tokyo.ac.jp/~ichiyama/mt/archives/000025.html とりくんの MT http://f15.aaacafe.ne.jp/~maco/blog/tri…

http://nice.sf.net/ class Person { String : word; String : say(); } say(p@Person) { return p.word; } void main(String[] args) { let p = new Person(word: "Hello, world"); System.out.prinln(p.say()); } JAVAの拡張だけあって、JAVAで出来ること…

types and subtypes

Ada

type Hours24 is new Integer range 0 .. 23; type Hours is new Integer range 1 .. 12; Hours24 and Hours are different types. You can not assignment Hours's var to Hours24 variables. type Hours24 is new Integer range 0 .. 23; subtype Hours is…

print "Hello\ world label "Hello\ world print だとコンソールに、labelだとキャンバスの方に文字を描写する。 aptのパッケージにあった、バークレイのLOGOを使ってみたんだけど、 ウィンドウ重ねると線が消えてしまうのはバグだろうか?それとも仕様?

hello.adb with Text_IO; use Text_IO; procedure Hello is begin Put_Line("Hello, world"); end Hello; > gnatmake hello 前々からコードは読んでいたけど、コンパイルの仕方がわからなかった。 gnatmakeを使うと簡単に出来るらしい。ファイル名は拡張子 .…