running a lisp program in Allegro CL

Posted on 2008-10-20
Last Modified: 2013-11-15
Hi all,

I'm new to the Lisp world. I'm using Allegro CL as my IDE. I have a program (2d.lisp) that I would like to run under this environment but I get an error every time I try to run this code.  All I do is to type in (load "2d.lisp") to load the file. Then when I try to run the function by typing in (path-planning-problem (*scene-4.17*)) I get an error. I have attached the 2d.lisp to this post.

I'm not sure what I'm doing wrong  and I'd appreciate your help.
;;; path-planning.lisp

;;; Definitions for the problem of finding optimal paths in two dimensions

;;; with convex polygonal obstcles. The scene is specified with the

;;; visible vertices precalculated for each vertex.

(defstruct (vertex (:print-function print-vertex))

  xy           ;; the xy point for the vertex

  c-neighbor   ;; neighbour in clockwise direction

  a-neighbor   ;; neighbour in anti-clockwise direction

  visible      ;; list of vertices visible from here


(defun print-vertex (v &optional (stream t) depth)

  (declare (ignore depth))

  (format stream "VERTEX~A" (vertex-xy v)))

(defstruct line

  xy1 xy2)

(defstruct polygon

  entry-vertex vertices n)

(defstruct scene

  polygons				; polygons comprising scene

  start-polygon				; polygon for start 

  goal-polygon				; polygon for goal


;;;; Creating a Path Planning Problem

(defun path-planning-problem (scene)

  "Create a path-planning problem from a description of a scene."

  ;; States are represented by a single vertex.

  (let ((start (polygon-entry-vertex (scene-start-polygon scene)))

	(goal  (polygon-entry-vertex (scene-goal-polygon scene))))


     :initial-state      start

     :successor-fn       #'(lambda (v1) (path-planning-successors v1 scene))

     :goal-test          #'(lambda (v1) (eq v1 goal))

     :g-cost-fn          nil

     :h-cost-fn          #'(lambda (v1) 

			     (xy-distance (vertex-xy v1) (vertex-xy goal)))

     :edge-cost-fn       #'(lambda (v1 v2) 

			     (xy-distance (vertex-xy v1) (vertex-xy v2)))

     :hash-key           #'vertex-xy

     :domain             "path-planning"


(defun path-planning-successors (v1 scene)

  "Return a list of (action . state) pairs, where the state is another

  vertex that is visible from here, and the action is a delta (dx dy)

  from the current vertex to the new one."

  (let ((p1 (vertex-xy v1)))

    (mapcar #'(lambda (v2) (let ((p2 (vertex-xy v2)))

			     (cons (make-xy :x (- (xy-x p2) (xy-x p1)) 

					    :y (- (xy-y p2) (xy-y p1)))


	    (vertices-visible-from v1 scene))))

;;; Functions for testing whether one vertex is visible from another

(defun vertices-visible-from (v1 scene)

  "Find all the vertices that can be seen from this vertex."

  ;; When you find them, cache them under the vertex-visible slot.

  (or (vertex-visible v1)

      (setf (vertex-visible v1) (vertices-in-view v1 scene))))


(defun vertices-in-view (v scene)

  "Find all the other vertices that can be seen from v."

  (delete v

   (with-collection ()

    (for each poly in (scene-polygons scene) do

	 (cond ((member v (polygon-vertices poly))

		(collect (vertex-c-neighbor v))

		(collect (vertex-a-neighbor v)))

	       (t (for each v2 in (polygon-vertices poly) do

		       (when (visible-p (vertex-xy v) (vertex-xy v2) scene)

			 (collect v2)))))))))

(defun visible-p (xy1 xy2 scene)

  "Predicate; return t iff xy1 is visible from xy2."

  (let ( (line (make-line :xy1 xy1 :xy2 xy2)) )

    (dolist (poly (scene-polygons scene) t)

      (if (line-intersects-poly? line poly) (return nil)))))

(defun line-intersects-poly? (line poly)

  "Predicate; return t iff line intersects poly."

  (dolist (v1 (polygon-vertices poly) nil)

    (let ((v2 (vertex-c-neighbor v1)))

      (if (intersects line 

                      (make-line :xy1 (vertex-xy v1) :xy2 (vertex-xy v2)))

	  (return t)))))

(defun intersects (l1 l2)   

;;; l1 is line ab; l2 is line cd

;;; assume the lines cross at alpha a + (1-alpha) b, 

;;;     also known as beta c + (1-beta) d

;;; line segments intersect if 0<alpha,beta<1 unless they're parallel

  (let* ((a (line-xy1 l1))

	 (b (line-xy2 l1))

	 (c (line-xy1 l2))

	 (d (line-xy2 l2))

	 (xa (xy-x a)) (ya (xy-y a))

	 (xb (xy-x b)) (yb (xy-y b))

	 (xc (xy-x c)) (yc (xy-y c))

	 (xd (xy-x d)) (yd (xy-y d))

	 (q (- (* (- xa xb) (- yc yd))

	       (* (- ya yb) (- xc xd)))))

    (unless (zerop q)

      (let ((alpha (/ (- (* (- xd xb) (- yc yd))

			 (* (- yd yb) (- xc xd)))


	     (beta (/ (- (* (- xd xb) (- ya yb))

			   (* (- yd yb) (- xa xb)))


	(and (< 0 alpha 1) (< 0 beta 1))))))

;;;; Code for constructing the scene data structure

(defun create-scene (start goal polygon-data)

  (let ((scene


	  :start-polygon (create-polygon (list start))

	  :goal-polygon  (create-polygon (list goal)))))

    (setf (scene-polygons scene)

	  (cons (scene-start-polygon scene)

		(cons (scene-goal-polygon scene)

		      (mapcar #'create-polygon polygon-data))))


(defun create-polygon (points)

  ;; Assumes that points are given in anticlockwise order (or in order, anyway)

  (let* ((vertices (mapcar #'(lambda (xy) (make-vertex :xy xy)) points))

	 (poly (make-polygon :vertices vertices)))

    (setf (polygon-entry-vertex poly) (first vertices))

    (setf (polygon-n poly) (length vertices))

    (dolist (v vertices)

      (let ((v2 (or (cadr (member v vertices :test #'eq))

		    (first vertices))))

	(setf (vertex-a-neighbor v) v2)

	(setf (vertex-c-neighbor v2) v)))



;;;; Specific scene, shown as Figure 4.17 [p 120]

(defparameter *scene-4.17*


   '(112 660) ;;start

   '(353 573) ;;goal

   ;; each polygon is represented as a list of (x y) coordinates of vertices

   '(((220 616) (220 666) (251 670) (272 647))

     ((341 655) (359 667) (374 651) (366 577))

     ((311 530) (311 559) (339 578) (361 560) (361 528) (336 516))

     ((105 628) (151 670) (180 629) (156 577) (113 587))

     ((118 517) (245 517) (245 557) (118 557))

     ((280 583) (333 583) (333 665) (280 665))

     ((252 594) (290 562) (264 538))

     ((198 635) (217 574) (182 574))


  "The scene in Figure 4.17 [p 120] with 8 obstacles.")

Open in new window

Question by:yourikh
1 Comment

Accepted Solution

yourikh earned 0 total points
ID: 22755862
pls close the question

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Creating and Managing Databases with phpMyAdmin in cPanel.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now