From: LuisGLopez
Subject: Problem with CLX
Date: 
Message-ID: <1141850311.007327.287030@j33g2000cwa.googlegroups.com>
Dear people,

I'm sorry; I think this is not a pure lisp issue, but I don't know any
other place for finding help for this...

I'm trying to re-run an old app; it worked perfect with my old linux
distro (Mandrake 10.0); but now (Ubuntu 5.10), it gives me this error:

---------
Error in function CONNECT-TO-INET-SOCKET:
   Error connecting socket to [localhost:6000]: Connection refused
   [Condition of type SIMPLE-ERROR]

Restarts:
  0: [ABORT] Abort handling SLIME request.
  1: [ABORT] Return to Top-Level.

Backtrace:
  0: (CONNECT-TO-INET-SOCKET "localhost" 6000 :STREAM)
  1: (XLIB::OPEN-X-STREAM "localhost" 0 :TCP)
  2: (XLIB:OPEN-DISPLAY "localhost" :DISPLAY 0 :PROTOCOL ...)
  3: (OPEN-WINDOW)
  4: (MANDELBROT :|MáXIMO| 100 :X0 -2.0 ...)[:OPTIONAL]
 --more--
----------

According to Synaptic, I have 'libx11-6' installed. I don't know if
that is of help.

This is the full code so far:

--------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; X11 routines

(require :clx)
(unuse-package :XLIB)

(defparameter *dpy* nil)
(defparameter *win* nil)
(defparameter *gctxt* nil)
(defparameter *window-width* 600)
(defparameter *window-height* 600)

(defun get-environment-variable (string)
  #-clisp (cdr (assoc string ext:*environment-list* :test #'string=))
  #+clisp (ext:getenv string))

(defun parse-display-variable (s)
  (let* ((colon (position #\: s))
         (dot (position #\. s :start colon))
         (host-name (if (zerop colon) "localhost" (subseq s 0 colon)))
         (display-number (parse-integer s :start (1+ colon) :end dot)))
    (values host-name display-number)))

(defun open-window ()
  (multiple-value-bind (host display)
      (parse-display-variable (get-environment-variable "DISPLAY"))
    (let* ((dpy (xlib:open-display host :display display))
           (screen (xlib:display-default-screen dpy))
           (black (xlib:screen-black-pixel screen))
           (white (xlib:screen-white-pixel screen))
           (win (xlib:create-window :parent (xlib:screen-root screen)
                                    :background white
                                    :x 0 :y 0 :width *window-width*
                                    :height *window-height*))
           (gcontext (xlib:create-gcontext :drawable win
                                           :background white
                                           :foreground black)))
      (xlib:map-window win)
      (xlib:display-force-output dpy)
      (setf *dpy* dpy
            *win* win
            *gctxt* gcontext)
      win)))

(defun rgb (r g b)
  (xlib:make-color :red r :green g :blue b))

(defun set-color (color)
  (setf (xlib:GCONTEXT-FOREGROUND *gctxt*) color))

(defun set-color-rgb (r g b)
  (setf (xlib:GCONTEXT-FOREGROUND *gctxt*)
        (xlib:make-color :red r :green g :blue b)))

(defun draw-point (x y)
  (xlib:draw-point *win* *gctxt* x y))

(defun draw-square (x y size)
  (xlib:draw-rectangle *win* *gctxt* (round x) (round y) size size
'fill))

(defun clear-window ()
  (xlib:clear-area *win* :width *window-width* :height *window-height*)
  (xlib:display-force-output *dpy*))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Conjunto de Mandelbrot

(defun modulo (z)
  (sqrt (+ (expt (realpart z) 2) (expt (imagpart z) 2))))

(defun intensidad (valor)
  (let ((color 0))
    (loop for k to 16 by 8 do
	  (setf (ldb (byte 8 k) color) valor))
    color))

(defun calcular-color (valor)
  (round (* (expt 2 16) valor)))

(defun mandelbrot (&key (máximo 100) (x0 -2.0) (y0 -2.0) (x1 2.0) (y1
2.0))
  (open-window)
  (let* ((ancho    (/ *window-width*  (- x1 x0)))
	 (alto     (/ *window-height* (- y1 y0)))
	 (paso-x   (/ ancho))
	 (paso-y   (/ alto)))
    (do ((i x0 (+ i paso-x))) ((> i x1))
      (do ((j y0 (+ j paso-y))) ((> j y1))
	(let ((c (complex i j)))
	  (set-color (calcular-color (/
				      (do ((z           #c(0 0) (+ (* z z) c))
					   (iteraciones 0       (1+ iteraciones)))
					  ((or (> (modulo z) 2) (= iteraciones máximo))
					   iteraciones))
				      máximo)))
	  (draw-point (round (+ (* ancho (- i x0))))
		      (round (+ (* alto  (- j y0)))))
	  (xlib:display-force-output *dpy*))))))
----------------

From: Christophe Rhodes
Subject: Re: Problem with CLX
Date: 
Message-ID: <sqlkvk1x1j.fsf@cam.ac.uk>
"LuisGLopez" <············@gmail.com> writes:

> I'm sorry; I think this is not a pure lisp issue, but I don't know any
> other place for finding help for this...
>
> I'm trying to re-run an old app; it worked perfect with my old linux
> distro (Mandrake 10.0); but now (Ubuntu 5.10), it gives me this error:
>
> ---------
> Error in function CONNECT-TO-INET-SOCKET:
>    Error connecting socket to [localhost:6000]: Connection refused
>    [Condition of type SIMPLE-ERROR]
>
> Restarts:
>   0: [ABORT] Abort handling SLIME request.
>   1: [ABORT] Return to Top-Level.
>
> Backtrace:
>   0: (CONNECT-TO-INET-SOCKET "localhost" 6000 :STREAM)
>   1: (XLIB::OPEN-X-STREAM "localhost" 0 :TCP)
>   2: (XLIB:OPEN-DISPLAY "localhost" :DISPLAY 0 :PROTOCOL ...)
>   3: (OPEN-WINDOW)
>   4: (MANDELBROT :|MáXIMO| 100 :X0 -2.0 ...)[:OPTIONAL]
>  --more--
> ----------

Your CLX is attempting to connect over TCP, whereas your X server is
not listening there; it is probably only listening on a unix socket.
At a guess, your $DISPLAY environment variable is something like
localhost:0.0 (where it should be :0.0 or unix:0.0 to request a unix
socket connection), or else your display-variable parsing code is
wrong (probably the latter).

You may be interested in the code to parse the display variable in
either McCLIM, Backends/CLX/port.lisp, function PARSE-CLX-SERVER-PATH,
or else the similar code in the portable-clx darcs repository.

Christophe
From: LuisGLopez
Subject: Re: Problem with CLX
Date: 
Message-ID: <1141852049.565265.91280@i39g2000cwa.googlegroups.com>
Christophe Rhodes wrote:
> Your CLX is attempting to connect over TCP, whereas your X server is
> not listening there; it is probably only listening on a unix socket.
> At a guess, your $DISPLAY environment variable is something like
> localhost:0.0 (where it should be :0.0 or unix:0.0 to request a unix
> socket connection), or else your display-variable parsing code is
> wrong (probably the latter).
>
> You may be interested in the code to parse the display variable in
> either McCLIM, Backends/CLX/port.lisp, function PARSE-CLX-SERVER-PATH,
> or else the similar code in the portable-clx darcs repository.

Hi!

Hey! You are great! Trying to follow your advice (I don't know much
about X server, sockets, etc.), I just change this line:

   (host-name (if (zerop colon) "localhost" (subseq s 0 colon)))

into this:

   (host-name (if (zerop colon) "" (subseq s 0 colon)))

and it worked!

I don't know if it's elegant... but it worked ;)

Thank you so much,

Luis.