Ocaml's Graphics.open_graph does not work

2019-08-12 04:36发布

问题:

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".

回答1:

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).



回答2:

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.