dak Posted May 30, 2013 Posted May 30, 2013 Hi everyone, Just trying to pass a list of points to a "pline" command. The problem is num of points is initially unknown, though being calculated within a routine. The following code (as smth to start with) evolves known num of points. (defun c:pltest6 () (setq pts (list '(0 0) '(0 10) '(10 10) '(10 20) '(20 20) '(20 30) '(30 30))) (setq ptqty 7) (setq ptnum 0) (command "pline" (car pts) (pt_retr pts) (pt_retr pts) (pt_retr pts) (pt_retr pts) (pt_retr pts) (pt_retr pts) "" ) ) (defun pt_retr (lst) (setq ptnum (1+ ptnum)) (repeat ptnum (setq lst (cdr lst)) ) (setq pt (car lst)) ) Repeat/foreach don't do, 'cause they return the value of the last iteration.. Now my Q is, is it possible to modify the code above to use loop instead of repeat one and the same line (moreover, unknown number of times ), OR some other approach would rather fix the task? Thank you in advance, Dmitro Quote
BlackBox Posted May 30, 2013 Posted May 30, 2013 (defun c:FOO (/ _FOO pts) (defun _FOO (pts /) (command "._pline") (foreach pt pts (command pt)) (command) ) (if (setq pts '((0 0)(0 10)(10 10)(10 20)(20 20)(20 30)(30 30))) (_FOO pts) ) (princ) ) Quote
Lee Mac Posted May 30, 2013 Posted May 30, 2013 Example: (defun c:pline-example ( / lst ) (setq lst '((0 0) (0 10) (10 10) (10 20) (20 20) (20 30) (30 30))) (apply 'command (append '("_.pline") lst '(""))) (princ) ) Quote
fixo Posted May 30, 2013 Posted May 30, 2013 Or (command "_pline")(mapcar 'command pt)(command "_cl") to make them closed, of course osmode is set to 0 before Quote
dak Posted May 31, 2013 Author Posted May 31, 2013 BlackBox, Lee Mac & fixo, Thank you so much. I see I need 1,000 x more practice to get accustomed to lisp. Sorry if you found my question borring. Regards, Dmitro P.S. Does there exist a Forum/Thread where LISP is compared with another languages? E.g. "THAT's C/Pascal/Basic code - and THIS is how we do it in LISP". Quote
neophoible Posted May 31, 2013 Posted May 31, 2013 P.S. Does there exist a Forum/Thread where LISP is compared with another languages?E.g. "THAT's C/Pascal/Basic code - and THIS is how we do it in LISP". You might ought to ask this in a separate thread. But note that AutoLISP and Visual LISP are not really LISP, but dialects of it intended specifically for AutoCAD. Also, LISP is not the same type of language, so if you want to do it "right", it may be better not to try to think too much in terms of such languages. BTW, interestingly, no one mentioned that while would be a substitute looping function for repeat when stepping through a variable number of items, or when the number is of no importance. Could this be because AutoLISP works differently than the other languages you mention? Quote
neophoible Posted May 31, 2013 Posted May 31, 2013 Or(command "_pline")(mapcar 'command pt)(command "_cl") to make them closed, of course osmode is set to 0 before Good point about OSMODE! Why not just apply instead of mapcar? (command "_pline")(apply 'command pts)(command "") Or were you just showing that there is yet another function option? Quote
BlackBox Posted May 31, 2013 Posted May 31, 2013 P.S. Does there exist a Forum/Thread where LISP is compared with another languages? E.g. "THAT's C/Pascal/Basic code - and THIS is how we do it in LISP". There is no specific place for that sort of comparison, but it makes logical sense to want to understand how to accomplish similar task in different languages... In terms of AutoCAD, methinks the most common is quickly becoming Visual LISP vs. .NET (predominantly C# from what I see, but also some VB.NET, and F#)... I suspect you might see more VBA now that VBA 7.1 is supported. As an aside, only when I was adept at coding LISP did I make the leap into the deep end of the .NET API, teaching myself C# & VB... It is then that I truly realized just how elegant LISP code can be, despite it's performance hit, with it's utter lack of Transactions, DocumentLocks, static Fields, permissions, etc.... It made me appreciate LISP even more than I thought I already had. If you really have something in mind that 'here's how I do this in LISP, how can I do the same in .NET?' etc., post a thread in the .NET forum, include your LISP code, and we'll help you out. Cheers Quote
dak Posted May 31, 2013 Author Posted May 31, 2013 neophoible, You right this could not of course! ; post #6 is concerned My problem was in fact that I had no idea of how I would "screw" loops to the "pline" command. And that was because since you used to code a great deal in some language, you have adopted its specific tricks. In this case I concluded list functions rule (which was not obvious for me when I raised this thread). Regards, Dmitro Quote
neophoible Posted May 31, 2013 Posted May 31, 2013 neophoible, You right this could not of course! ; post #6 is concerned My problem was in fact that I had no idea of how I would "screw" loops to the "pline" command. And that was because since you used to code a great deal in some language, you have adopted its specific tricks. In this case I concluded list functions rule (which was not obvious for me when I raised this thread). Regards, Dmitro Actually, what was not obvious to me, until I saw someone do it, is that you can split a command up with multiple calls to command. That was a great revelation for me. FWIW, here is a trivial example of how while could be used: (defun C:Q (/ P) (command "_.PLINE") (while (setq P (getpoint)) (command P) ) (command "") ) Quote
neophoible Posted May 31, 2013 Posted May 31, 2013 There is no specific place for that sort of comparison, but it makes logical sense to want to understand how to accomplish similar task in different languages...Yes, that does make sense....It made me appreciate LISP even more than I thought I already had. In this case I concluded list functions rule Yeah, from what I've read (meaning I really don't know anything about it myself!), after half a century plus, other languages (or their descendants) are starting to catch up to LISP. I vaguely recall decades ago when a well-meaning friend enthusiastically but futilely tried to explain its recursive powers. Alas, I'm a bit slow. All I could think was, Once is more than enough for me. I mean, who wants to be repeatedly cursed?:shock:Him::facepalm: But then I met AutoCAD. Quote
BlackBox Posted May 31, 2013 Posted May 31, 2013 LISP is great generally, and a good place to start if (like me) you've never written code before, methinks. Mode mode = this.Mode; this.Mode = Modes.Rant; My issues with LISP are not issues with the language, but with the VLIDE, lack of Autodesk enhancement to LispFunction Methods (especially for verticals like Civil 3D), etc.. this.Mode = mode; Quote
Recommended Posts
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.