From: [Invalid-From-Line]
Subject: Help with escape method, please?
Date: 
Message-ID: <6p8cf6$fhi$1@winter.news.erols.com>
Can you offer any suggestions please?

I am trying to do the following:

1.  Recursively obtain points from a user (Collect_Points).
2.  When the user has completed the list of points have him/her
     enter the letter D for done.
3.  When D is entered start entering a new set of points.

The above should be a simple task but the LISP manual on arbitrary keyboard
input is rather cryptic...
I keep getting 'invalid point' errors when D is entered at the command line.
Basically, how can I have the user escape from the recursion???

Any advice would be much appreciated.

Yours,
Elliot G.

My routine is below:

(defun C:MY_COMMAND ()
; other functions in here
  (Collect_Points)
)

(defun Collect_Points ()
 (setq Points_Complete "N")
 (while (= Points_Complete "N")
  (setq p1 (getpoint "\nEnter next point (enter D when done): "))

; Routine never gets beyond the Enter next point prompt if D is entered
; Below tests to see if p1 is a string but it is never reached...would like
to
; make Points_Complete = "Y" if D is entered

  (if
   (= 'STR (type p1))
    (setq p1 (eval (read p1)))
   p1
; (setq Points_Complete "Y")
  )
 )
)

From: Barry Margolin
Subject: Re: Help with escape method, please?
Date: 
Message-ID: <I5Qt1.20$fm5.273589@cam-news-reader1.bbnplanet.com>
In article <············@winter.news.erols.com>,  <········@erols.com> wrote:
>1.  Recursively obtain points from a user (Collect_Points).
>2.  When the user has completed the list of points have him/her
>     enter the letter D for done.
>3.  When D is entered start entering a new set of points.
>
>The above should be a simple task but the LISP manual on arbitrary keyboard
>input is rather cryptic...
>I keep getting 'invalid point' errors when D is entered at the command line.
>Basically, how can I have the user escape from the recursion???

I don't see any recursion in your code.  I see a while-loop.

>Any advice would be much appreciated.
>
>Yours,
>Elliot G.
>
>My routine is below:
>
>(defun C:MY_COMMAND ()
>; other functions in here
>  (Collect_Points)
>)
>
>(defun Collect_Points ()
> (setq Points_Complete "N")
> (while (= Points_Complete "N")

What dialect of Lisp is this?  In most Lisps = is only for numbers, and
there are other functions for comparing strings (equal, equalp,
string-equal in Common Lisp).

>  (setq p1 (getpoint "\nEnter next point (enter D when done): "))
>
>; Routine never gets beyond the Enter next point prompt if D is entered
>; Below tests to see if p1 is a string but it is never reached...would like
>to
>; make Points_Complete = "Y" if D is entered

You haven't shown us the getpoint function.  It sounds like that function
is what's reporting the "invalid point" error.

>  (if
>   (= 'STR (type p1))
>    (setq p1 (eval (read p1)))

Shouldn't that be something like READ-FROM-STRING?  And why do you need to
evaluate it?  Without knowing more about what these points are like, it's
hard to critique this code.

>   p1
>; (setq Points_Complete "Y")
>  )
> )
>)
>
>
>


-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
From: Martti Halminen
Subject: Re: Help with escape method, please?
Date: 
Message-ID: <35B86D0D.7122@dpe.fi>
Barry Margolin wrote:
> 
> In article <············@winter.news.erols.com>,  <········@erols.com> wrote:

> >My routine is below:
> >
> >(defun C:MY_COMMAND ()
> >; other functions in here
> >  (Collect_Points)
> >)
> >
> >(defun Collect_Points ()
> > (setq Points_Complete "N")
> > (while (= Points_Complete "N")
> 
> What dialect of Lisp is this?  In most Lisps = is only for numbers, and
> there are other functions for comparing strings (equal, equalp,
> string-equal in Common Lisp).

Seems to be AutoLisp. (AutoCAD extension language: somewhat MacLisp
-like, I seem to remember originated from XLISP. Dynamic scoping,
usually just an interpreter (There has been some talk about their moving
to a more CL direction. Visual LISP, anyone?), no macros, no let, most
other interesting tools also missing.)



> >  (setq p1 (getpoint "\nEnter next point (enter D when done): "))
> >
> >; Routine never gets beyond the Enter next point prompt if D is entered
> >; Below tests to see if p1 is a string but it is never reached...would like
> >to
> >; make Points_Complete = "Y" if D is entered
> 
> You haven't shown us the getpoint function.  It sounds like that function
> is what's reporting the "invalid point" error.
> 


Getpoint is an AutoCAD built-in function.



Generally, this kind of question would probably be better answered in
comp.cad.autocad (or whatever it was). Is there any kind of consensus in
this group about redirecting the queries?

-- 
________________________________________________________________
    ^.          Martti Halminen
   / \`.        Design Power Europe Oy
  /   \ `.      Tekniikantie 12, FIN-02150 Espoo, Finland
 /\`.  \ |      Tel:+358 9 4354 2306, Fax:+358 9 455 8575
/__\|___\|      ······················@dpe.fi   http://www.dpe.fi
From: Reini Urban
Subject: Re: Help with escape method, please?
Date: 
Message-ID: <35b8a134.20105920@judy>
Martti Halminen <···@dpe.fi> wrote:

>> What dialect of Lisp is this?  In most Lisps = is only for numbers, and
>> there are other functions for comparing strings (equal, equalp,
>> string-equal in Common Lisp).

In AutoLISP = is the usual comparison function, just like eql, but
extended for strings.
(= 'a 'a)   => T
(= "a" "a") => T

funny, isn't it?

>Seems to be AutoLisp. (AutoCAD extension language: somewhat MacLisp
>-like, I seem to remember originated from XLISP. Dynamic scoping,
>usually just an interpreter (There has been some talk about their moving
>to a more CL direction. Visual LISP, anyone?), no macros, no let, most
>other interesting tools also missing.)

Well, there is some work done on it. 
Technically it is no problem to give most of the CL functionality to the
users (lexical scoping, let, do, macros, arrays, structs, destructive
list operations, packages, simplified CLOS, reader macros and such)
The problem is to update the users to a new language :)

Backward compatibility, you know. And bad habits. And increased costs
for user support.

>Generally, this kind of question would probably be better answered in
>comp.cad.autocad (or whatever it was). Is there any kind of consensus in
>this group about redirecting the queries?

General consensus is just to ignore the autolisp fellows.
This was the first time someone (in fact two) from this group didn't
realize that it was posted to the wrong group.
I would love to see the guys face trying to understand Steve response.
:)

---
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
"C makes it easy to shoot yourself in the foot.  C++ makes it
 harder, but when you do, it blows away your whole leg."
                                  -- Bjarne Stroustrup on C++ 
From: [Invalid-From-Line]
Subject: Re: Help with escape method, please? OK I surrender already!!!
Date: 
Message-ID: <6pa9pn$rhc$1@winter.news.erols.com>
Thanks for all of your thoughts...I'll send any AutoLISP questions to
comp.cad.autocad in the future.

Yours,

Elliot G.
From: Steve Gonedes
Subject: Re: Help with escape method, please?
Date: 
Message-ID: <6pan3p$q00@bgtnsc02.worldnet.att.net>
Reini Urban <······@sbox.tu-graz.ac.at> writes:


< General consensus is just to ignore the autolisp fellows.
< This was the first time someone (in fact two) from this group didn't
< realize that it was posted to the wrong group.
< I would love to see the guys face trying to understand Steve response.
< :)

Yeah, my mistake - I'm real slow; sorry for the confusion. I changed
newsgroups but somehow GNUS forgot to update my brain...
From: Steve Gonedes
Subject: Re: Help with escape method, please?
Date: 
Message-ID: <6pamvj$q00@bgtnsc02.worldnet.att.net>
Martti Halminen <···@dpe.fi> writes:

< > >My routine is below:
< > >
< > >(defun C:MY_COMMAND ()
< > >; other functions in here
< > >  (Collect_Points)
< > >)
< > >
< > >(defun Collect_Points ()
< > > (setq Points_Complete "N")
< > > (while (= Points_Complete "N")
< > 
< > What dialect of Lisp is this?  In most Lisps = is only for numbers, and
< > there are other functions for comparing strings (equal, equalp,
< > string-equal in Common Lisp).
< 
< Seems to be AutoLisp. (AutoCAD extension language: somewhat MacLisp
< -like, I seem to remember originated from XLISP. Dynamic scoping,
< usually just an interpreter (There has been some talk about their moving
< to a more CL direction. Visual LISP, anyone?), no macros, no let, most
< other interesting tools also missing.)

When I originally read the post I though I was in comp.emacs. You'll
have to excuse my boneheadedness. I realized this because I wanted to
say that I forgot to include the (require 'cl), and that catch/throw
is not like goto, rather it's more like setlongjump. Return from and
prog are more like goto. Oh well, wrong newsgroup; sorry.
From: Steve Gonedes
Subject: Re: Help with escape method, please?
Date: 
Message-ID: <6p9opm$fmm@bgtnsc03.worldnet.att.net>
<········@erols.com> writes:

< Can you offer any suggestions please?
<
< I am trying to do the following:
<
< 1.  Recursively obtain points from a user (Collect_Points).
< 2.  When the user has completed the list of points have him/her
<      enter the letter D for done.
< 3.  When D is entered start entering a new set of points.


(defun my-read-points-recurse (i max points)
  (if (= max i) points
      (let ((input (read-from-minibuffer
                    (format "Point (%d): " (1+ i)))))
        (cond ((string= input "")
               (my-read-points-recurse i i (subseq points 0 i)))
              ((string= input "D")
               (vector (my-read-points-recurse i i (subseq points 0 i))
                        (my-read-points max)))
              (t
               (setf (aref points i)
                 (string-to-number input))
               (my-read-points-recurse (1+ i) max points))))))

(defun my-read-points (max)
  (my-read-points-recurse 0 max (make-vector max nil)))


< The above should be a simple task but the LISP manual on arbitrary keyboard
< input is rather cryptic...
< I keep getting 'invalid point' errors when D is entered at the command line.
< Basically, how can I have the user escape from the recursion???
<
< Any advice would be much appreciated.

I used vectors because I hardly ever get to use vectors recursively like
that (plus points seem like they should be in a vector).

The recursion stops when the user types enter with no number (or i =
max because I am not going to implement fill-pointers in emacs right
now - a tad bit too tired for that). The vectors may be a bit awkward,
so here is a normal list method.

(defun my-read-points-recurse (i points)
  (let ((input (read-from-minibuffer
                (format "Point (%d): " i))))
    (cond ((string= input "") (nreverse points))
          ((string= input "D")
           ;; This is a very proud moment for myself. I feel like I have
           ;; been waiting my whole life to use probably one of the most
           ;; obscure functions in all of lispdom, `nreconc'. Now that
           ;; moment has come. joy.
           (nreconc points (my-read-points)))
          (t (my-read-points-recurse
              (1+ i) (cons (string-to-number input) points))))))

(defun my-read-points ()
  (my-read-points-recurse 1 ()))


You may be wondering what the "D" will do. I don't know, but I got it to use
nreconc so all is well.

Here's my iterative try.

(defun get-point (str)
  (read-from-minibuffer str))

(defun collect-points ()
  (let ((points (cons nil nil)))
    (catch 'yadda-yadda-hey!
      (while t
        (let ((p1 (get-point "Enter next point (D to exit): ")))
          (cond ((string-equal p1 "n")
                 (throw 'yadda-yadda-hey! 
                   ;; this will reverse them and remove the possible nil
                   ;; from the car of POINTS (for the acons below)
                   (mapcar #'nreverse
                           (delete nil points))))
                ((string-equal p1 "d")
                 (setq points (cons nil points)))
                (t
                 (setq points (acons (string-to-number p1)
                                     (car points) (cdr points))))))))))


The function `acons' is just like (cons (cons ...) ...). Notice the throw
and catch. This is the equivalent of a goto statement. I figure catch,
throw, dynamic extent; what's the difference.

Point is, use let rather than setq. The function `read-from-minibuffer'
will read a string from the minibuffer. Use `string-equal' to test the
equality of two strings when case is _not_ significant, if case is
significant, use `string='. Last, but certainly not least, I finally got to
use the function nreconc => (nreverse (nconc ...) ...).