Ocaml's Graphics.open_graph does not work

2019-08-12 04:28发布

I am trying to follow the ocaml manual to draw something. But here is a strange response from Ocaml's toplevel. Anyone sees why? Thanks.

# #load "graphics.cma";;
# Graphics.open_graph "foo:0";;
_X11TransSocketINETConnect() can't get address for foo:6000: nodename nor servname provided, or not known
Exception: Graphics.Graphic_failure "Cannot open display foo:0".

2条回答
虎瘦雄心在
2楼-- · 2019-08-12 05:01

foo term is a common way to specify parts of examples that should be substituted by the user to match local environment. In your case you probably want to read 3 lines below and open default display :

Graphics.open_graph ""

connects to the default display and creates a window with the default geometry.

查看更多
乱世女痞
3楼-- · 2019-08-12 05:07

I use Graphics.open_graph " 600x400", and it works. Note the space before the resolution specification.

As to why foo:0 would or would not work, that is not OCaml-specific but something about the X11 server. You probably don't need to, and therefore don't want to, use such specialized feature (opening a window on another display).

查看更多
登录 后发表回答