This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

this queue program is not running showing error

5 posts · 9822 views

(defun make-queue
    (lambda ()
      (let ((front '()) (back '()))
        (lambda (cmd . data)
          (define exchange
           (lambda ()
              (set! front (reverse back))
              (set! back '())))
          (case cmd
           ((push) (push (car data) back))
           ((pop) (or (pop front)
                       (begin
                         (exchange)
                         (pop front))))
            ((peek) (unless (pair? front)
                     (exchange))
                      (car front))
            ((show) (format #t "~s\n" (append front (reverse back))))
            ((fb) (format #t "front: ~s, back: ~s\n" front back))
            (else (error "Illegal cmd to queue object" cmd)))))))

Last edited by bhupi on , edited 2 times in total.

Re: this queue program is not running showing error

still this program is not working

plss help i need it by tomorrow morning

Re: this queue program is not running showing error

Which dialect of Scheme are you running? (I don't know of any that use 'defun'.)

Also, you need to define all of your procedures push, pop, peek, show, and fb somewhere (so that they evaluate properly during invocation).

Re: this queue program is not running showing error

My bad. This first post was in the moderation queue. From a quick glance, my tired eyes saw Scheme so I moved the topic. Bhupi's other post is clearly CL code.

In CL,
(defun make-queue
  (lambda ()
...
should probably look like
(defun make-queue ()
  ...
But the use of "set!" looks like Scheme (use "setf" in CL); so I'm still not sure what dialect is intended.

Re: this queue program is not running showing error

The following is "valid" CL. It approximates the basic form of the original post using CL idioms, but it almost certainly does not work.
(defun make-queue ()
  (let ((front '()) (back '()))
    (lambda (cmd data)
      (flet
	  ((exchange ()
		     (setf front (reverse back))
		     (setf back '())))
	(case cmd
	  ((:push) (push (car data) back))
	  ((:pop) (unless (pop front)
		    (exchange)
		    (pop front)))
	  ((:peek) (unless (consp front)
		     (exchange))
	   (car front))
	  ((:show) (format t "~s\n" (append front (reverse back))))
	  ((:fb) (format t "front: ~s, back: ~s\n" front back))
	  (t (error "Illegal cmd to queue object" cmd)))))))