Jump to content

Need help detecting error in LISP


ottooo

Recommended Posts

Hi there,

 

I am a bit lost with my current LISP project.

 

With this program, I determine the angle of a line and compare this to a list. If this angle is present in this list, then it should return true, otherwise false.

 

However, I can't seem to get the red part of the code working. When I would use a number it works like it should, but when I use "ang1", it fails. However, when I use (princ ang1), it shows me the angle which I want to compare to the list.

 

I think the mistake is somewhere in the RtD calculation, but I'm not sure.

 

If you need any additional information, please let me know.

 

(defun c:OneBend ( / savesnap comech )

(initget 1 "Forward Backward")
(setq richting (getkword "Is this a Forward or a Backward bend? "))

(setq bend 90)

;;; DETERMINE ANGLE

(setq pt1 (getpoint "\nSelect point 1: "))
(setq pt2 (getpoint "\nSelect point 2: "))

(setq ang (angle pt1 pt2))
(setq ang0 (/ ang pi))
(setq ang1 (* ang0 180.0))

(if (>= ang1 180.0) (setq ang1 (- ang1 180.0)))
(if (>= ang1 90.0) (setq ang1 (- ang1 180.0)))
(setq ang1 (abs ang1))

(terpri)
(princ ang1)
(terpri)

(setq f90_list '(0.0 8.0 10.0 12.0 14.0 16.0 18.0 20.0 22.0 24.0 26.0 34.0))

(setq b90_list '(0.0 16.0 20.0 22.0 24.0 26.0 28.0 30.0 32.0 34.0 36.0 39.0 40.0 42.0
			44.0 45.0 46.0 48.0
			50.0 52.0 55.0 58.0 60.0 63.0 64.0 65.0))

(setq stnd_list '(0.0))

(cond
	((and (= bend 90) (= richting "Forward"))
		(setq angle_list f90_list))

	; FOR FUTURE USE
	((and (= bend 45) (= richting "Forward"))
		(setq angle_list f45_list))

	((and (= bend 90) (= richting "Backward"))
		(setq angle_list b90_list))

	; FOR FUTURE USE
	((and (= bend 45) (= richting "Backward"))
		(setq angle_list b45_list))

	(t (setq angle_list stnd_list))
)

; ANGLE PART OF LIST

[color="red"];	(setq apol (member 20.0 angle_list)) ; This works

(setq apol (member ang1 angle_list)) ; This does not work ???[/color]

(if apol (princ "Success!") (princ "Fail!"))


; PROGRAM CONTINUES HERE
)


Link to comment
Share on other sites

You need to round your variable ang1 to match those angle values specified in angles list in order to make it possible for member function to detect its presence... Another approach would be to use vl-position function instead of member as it is faster, but you still have to do rounding. Maybe the best choice is actually vl-member-if function with adequate lambda function in which you don't have to do rounding, but rather specify equal comparation function with adeqate fuzz tolerance value...

Link to comment
Share on other sites

I think what he is trying to say is that you are trying to match 20.0000 to 20.0 and it's not working out.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...