文字列中のバックスラッシュ

OCaml では

print_endline "\(^_^)/"

を実行すると「illegal backslash escape in string」という警告が出るがエラーにはならず、「\(^_^)/」と表示される。
一方 Ruby

puts "\(^_^)/"

は警告は出ずに「(^_^)/」と表示される。しかし、

puts '\(^_^)/'

は「\(^_^)/」が表示される。
普段はどうでもいいことだが、ゴルフでは役に立ったりする…かもしれない。

puts

OCamlRuby の puts もどき。可変個の引数を取る。

$ ocaml -rectypes
        Objective Caml version 3.09.3

# let rec puts s = print_endline s; puts;;
val puts : string -> 'a as 'a = <fun>
# puts "foo" "bar";;
foo
bar
- : string -> 'a as 'a = <fun>
# puts "one" "two" "three";;
one
two
three
- : string -> 'a as 'a = <fun>
# puts "xxx"; puts "yyy";;
Warning F: this function application is partial,
maybe some arguments are missing.
xxx
yyy
- : string -> 'a as 'a = <fun>

-rectypes 使わないといけなかったり ; で繋げると警告出るから嫌だ。

ledit

OCamlの対話環境でヒストリー機能とか色々使いたくなったのでleditを入れる。
ledit-1.11.tar.gz を落としてmake…すればいいはずなのだが、

$ make
camlp4r pa_extend.cmo q_MLast.cmo pa_local.ml -o pa_local.ppo
File "pa_local.ml", line 34, characters 13-65:
use of antiquotation syntax deprecated since version 3.06+18
ocamlc -I `camlp4 -where` -c -impl pa_local.ppo
File "pa_local.ml", line 19, characters 0-1:
Unbound value _loc
make: *** [pa_local.cmo] エラー 2

なんかエラー。OCamlのバージョンの問題? 原因がcamlp4にあるっぽいのでわけわからねえのれす。うぐう。でも "Unbound value _loc" とかでググったりして、勘で expr_of_patt の中の loc を _loc にしてみる。…おお、通った。ledit超便利だ。感動。
欲を言えばirbのクラス名やメソッド名補完みたいなことしたいけど OCaml と ledit が分かれてたら難しいだろうなー

Obj

Objヤバイ

# type foo = { count : int };;
type foo = { count : int; }
# let x = { count = 4 };;
val x : foo = {count = 4}
# Obj.set_field (Obj.repr x) 0 (Obj.repr 8);;
- : unit = ()
# x;;
- : foo = {count = 8}

うぎゃ。Obj.set_field (Obj.repr x) 4 (Obj.repr 8) とかやったりすると何が起こるか想像もつかない。凄い。