Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

repetitive proccess (while ....(do ...until...

6 REPLIES 6
Reply
Message 1 of 7
pipouchette
464 Views, 6 Replies

repetitive proccess (while ....(do ...until...

hi, i'm trying to make a repetitive proccess that makes something like this:
(while (/= a b)
(do (setq a (+ a 10) b (- b 10))

and so on until (= a b)

and my initial code is the following:

(defun pipu ()
(setq a 0)
(setq b 100)
(if (= a b)
(progn
(princ "\nA = B "))
(setq a (+ a 10) b (- b 10))))



thanks to everyone that could help me Edited by: pipouchette on Dec 6, 2009 1:22 PM
6 REPLIES 6
Message 2 of 7
Kent1Cooper
in reply to: pipouchette

All you need to do, basically, is apply the function already mentioned in your description within your code, get rid of the unnecessary (progn) function while you're in there, and rearrange slightly, for example:

{code}
(defun pipu ()
(setq a 0)
(setq b 100)
(while (/= a b)
(setq a (+ a 10) b (- b 10))
); end while
(prompt "\nA = B ")
(princ)
); end defun
{code}

--
Kent Cooper
Kent Cooper, AIA
Message 3 of 7
Anonymous
in reply to: pipouchette

You are very close:

(setq a 0 b 100)
(while (/= a b)
(setq a (+ a 10) b (- b 10)))


The problem comes if your results are never equal. You'll get into a
continuous loop. -David


pipouchette wrote:
> hi, i'm trying to make a repetitive proccess that makes something like this:
> (while (/= a b)
> (do (setq a (+ a 10) b (- b 10))
>
> and so on until (= a b)
>
> and my initial code is the following:
>
> (defun pipu ()
> (setq a 0)
> (setq b 100)
> (if (= a b)
> (progn
> (princ "\nA = B "))
> (setq a (+ a 10) b (- b 10))))
>
>
>
> thanks to everyone that could help me
>
> Edited by: pipouchette on Dec 6, 2009 1:22 PM
Message 4 of 7
cab2k
in reply to: pipouchette

Exactly David.

My version.

{code}(defun pipu (/ a b inc)
(setq a 0
b 100
inc 10
)

(while (< a b)
(setq a (+ a inc)
b (- b inc)
)
)

(princ "\nNew A = ") (princ a)
(princ "\nNew B = ") (princ b)

(princ)
){code}
Message 5 of 7
Anonymous
in reply to: pipouchette

Hi:

What about the restrictions over a,b and the increment?

in some situations the final condition will never be acomplished (example:
a:=5;b:=100;inc:=10), in other cases you will end up with the average(a,b)
:(a+b)/2.
If you use a while (/= a b) loop, will never stop in a lot of initial
conditions.
If you use a while (a < b) the loop will end, but never with a=b.
The result of the loop will be (ever) a:=a+n*inc ; b:=b-n*inc, so if the
equation (in n integer) : a+n*inc=b-n*inc can be solved you have good
initial conditions and the result will be the average(a,b), otherways they
are ill conditioned over the final restriction a=b.

So the question is: what are you trying to find out?

Gaston

"pipouchette" wrote in message news:6300108@discussion.autodesk.com...
> hi, i'm trying to make a repetitive proccess that makes something like
> this:
> (while (/= a b)
> (do (setq a (+ a 10) b (- b 10))
>
> and so on until (= a b)
>
> and my initial code is the following:
>
> (defun pipu ()
> (setq a 0)
> (setq b 100)
> (if (= a b)
> (progn
> (princ "\nA = B "))
> (setq a (+ a 10) b (- b 10))))
>
>
>
> thanks to everyone that could help me
>
> Edited by: pipouchette on Dec 6, 2009 1:22 PM
Message 6 of 7
pipouchette
in reply to: pipouchette

hi to all

I arrived yesterday at home and found your answers to this filosofical question i've been fighting all the week.
ouw it works!!!!!
thanks to all,Gaston , cab, david & kent
I'll also be so gratefull if anyone could recomend me some book about lisp for autocad, actually I'm bloked whith the ones I have

thanks another time.
Message 7 of 7
cab2k
in reply to: pipouchette

To get off the ground in a hurry you should read from these sites:

Start at the beginning http://www.afralisp.net/

http://jefferypsanders.com/autolisp.html
http://ronleigh.info/autolisp/index.htm
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=770225


Intermediate to Advanced:
http://pages.cs.wisc.edu/~vernon/cs367/notes/6.RECURSION.html



Advanced:
http://www.atablex.com/htmls/excel-bible.htm
http://www.steinvb.net/vldb/ The Visual LISP Developer's Bible (eBook) [*** Get this ***]
http://www.caddigest.com/subjects/autocad/tutorials/select/parsai_vlx.htm


References:
http://www.hyperpics.com/commands/index.asp
http://www.autodesk.com/techpubs/autocad/acad2000/dxf/


Extra credit:
http://www.analogx.com/contents/articles/howtoprg.htm
http://www.paulgraham.com/progbot.html
http://www.dreamsongs.com/SeatBelts.html
http://www.dreamsongs.com/ArtOfLisp.html

I found these links too but have not explored them.

Link to pdf Lessons:
http://forums.augi.com/showpost.php?p=190406&postcount=21

14 lessons by Dave Pitzer
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=2309147
follow the link at the bottom of each lesson

Free AutoLisp course
http://forums.augi.com/attachment.php?attachmentid=3425&d=1093637254

Computer Science 50: Introduction to Computer Science I Harvard College
http://cs50.tv/


http://www.asmitools.com/Files/Programs.html
http://www.asmitools.com/Files/Tutorials.html

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost