TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on August 20, 2014, 04:48:00 PM

Title: question on the use of foreach
Post by: andrew_nao on August 20, 2014, 04:48:00 PM
when using foreach, do you need to use a (progn..) in there if you want to do more than 1 expression?


example would be:
Code - Auto/Visual Lisp: [Select]
  1. (foreach x lst
  2.    (progn
  3.       (do this)
  4.       (do this)
  5.       (do this)
  6.       (do this)
  7.       (do this)
  8.       (do this)
  9.     )
  10.  )


EDIT by Se7en: Fixed code tags, adjusted formatting slightly.
Title: Re: question on the use of foreach
Post by: Lee Mac on August 20, 2014, 04:57:50 PM
No.

As specified in the documentation (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6a1e.htm):
Quote from: foreach documentation
The foreach function steps through a list, assigning each element in the list to a variable, and evaluates each expression for every element in the list. Any number of expressions can be specified.
Title: Re: question on the use of foreach
Post by: snownut2 on August 20, 2014, 07:14:18 PM
Code - Auto/Visual Lisp: [Select]
  1. (foreach x '(1 2 3 4 5 6)
  2.   (setq lst (append lst (list(1+ x))))
  3.   )
  4.  

Will return  lst = (2 3 4 5 6 7)
Title: Re: question on the use of foreach
Post by: JohnK on August 21, 2014, 06:36:48 AM
Off topic reminder:

...
As specified in the documentation (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6a1e.htm):
Quote from: foreach documentation
The foreach function steps through a list, assigning each element in the list to a variable, and evaluates each expression for every element in the list. Any number of expressions can be specified.

As a reminder to all, TheSwamp now has it's own Autolisp help which can be linked to (to use the example above) like this:
http://www.theswamp.org/~john/avlisp/#foreach
or to remove the url:
foreach (http://www.theswamp.org/~john/avlisp/#foreach)

Also note that this help file can be added to or corrected by our members. If you want a section revised, please feel free to ask me or any of the moderators.
Title: Re: question on the use of foreach
Post by: Kerry on August 21, 2014, 07:25:23 AM

Not only,  but also :: if we use the cadlisp-7 code tag

Code - Auto/Visual Lisp: [Select]
  1. (foreach thingystuff
  2.     select foreach or any blue highlighted stuff with the mouse using CLICK or CTRL-CLICK and watch the magic
  3. )
  4.  
Title: Re: question on the use of foreach
Post by: JohnK on August 21, 2014, 08:31:14 AM
Yes, and that too. :)

On a side note: I know it's not the prettiest webpage but I did try to offer some helpful things when creating that help file. Like, I tried to keep the HTML to a minimum so it would be as quick (fast loading) as possible and wash out the colors a little to make it more "readable" (be more like a "paper white" and "ink type black").

This place is an amazing resource and I feel that everything we can do to separate ourselves from the pack of other Autodesk related help forums the better (we should continue to be the standard those other places strive to be like).
Title: Re: question on the use of foreach
Post by: Kerry on August 21, 2014, 08:52:19 AM

Yes, you've done a great job with it John.

The file is a couple of years out of date, so it probably needs a couple of hours of TLC ... but I can't make time to do it and I'm bloody sure you won't be able to either.

Perhaps one of the newer members will volunteer :-D
Title: Re: question on the use of foreach
Post by: JohnK on August 21, 2014, 09:03:36 AM

Yes, you've done a great job with it John.

The file is a couple of years out of date, so it probably needs a couple of hours of TLC ... but I can't make time to do it and I'm bloody sure you won't be able to either.

Perhaps one of the newer members will volunteer :-D

You are correct about that. I don't know what "free time" is anymore.

That is a wonderful idea! I hope someone volunteers.
Title: Re: question on the use of foreach
Post by: andrew_nao on August 21, 2014, 09:06:42 AM
hmm.. i must be using it wrong.. thanks for the info

thanks for the format correction
Title: Re: question on the use of foreach
Post by: Kerry on August 21, 2014, 09:15:26 AM
Another option to remember ...

Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 10:03:07 AM

Not only,  but also :: if we use the cadlisp-7 code tag

Code - Auto/Visual Lisp: [Select]
  1. (foreach thingystuff
  2.     select foreach or any blue highlighted stuff with the mouse using CLICK or CTRL-CLICK and watch the magic
  3. )
  4.  
Not sure why ... but those code tags have not worked for me in quite a while.  :?
Title: Re: question on the use of foreach
Post by: Kerry on August 21, 2014, 10:09:26 AM

Not only,  but also :: if we use the cadlisp-7 code tag

Code - Auto/Visual Lisp: [Select]
  1. (foreach thingystuff
  2.     select foreach or any blue highlighted stuff with the mouse using CLICK or CTRL-CLICK and watch the magic
  3. )
  4.  
Not sure why ... but those code tags have not worked for me in quite a while.  :?

Which browser ron ?
What do you mean 'don't work' > can't set or can't see what others have set ?
I wonder if it's a JavaScript setting ?
Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 10:30:10 AM
Kerry,


I'm using Chrome. I can see when others use the tags, but they don't get added to my posts. I also get strangeness (height change \ added spaces \ font change) with formatting when using copy paste ... even paste without formatting ( ctrl+shift+v )


 :|
Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 10:32:18 AM
Here is a test post using Firefox. Autolisp tags still don't work ..... hhhhmmm
No added spaces to the post though .. got some wonkiness going on.
Title: Re: question on the use of foreach
Post by: Mark on August 21, 2014, 10:43:57 AM
test post
Code - Auto/Visual Lisp: [Select]
  1.   ;-----------------------------------------
  2.   ; returns the x y point list of a caculated midpoint
  3.   ;
  4.   ; (midpt '(0.0 0.0 0.0) '(0.0 0.0 0.0) )
  5.   ;-----------------------------------------
  6.   (defun midpt (point_1 point_2)
  7.     (mapcar
  8.       '(lambda (x y) (/ (+ x y) 2.0)) point_1 point_2
  9.       )
  10.     )
  11.  

chrome, windows 7
Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 11:01:04 AM
Test post Chrome Win 8.1
Title: Re: question on the use of foreach
Post by: JohnK on August 21, 2014, 11:06:15 AM
Here is a test post using Firefox. Autolisp tags still don't work ..... hhhhmmm
No added spaces to the post though .. got some wonkiness going on.

Weird!

The display you see (the forum/post) is just HTML with some java script for the dynamic stuff mixed in but you shouldn't have a problem viewing or typing (most forum boards aren't anything fancy or difficult for browsers to render).
For example, here is a snip of the code tag after GeSHi and SMF get done parsing the page.
Code - Text: [Select]
  1. <div class="list_posts smalltext" id="msg_526915_body">test post<br /><div class="codeheader">Code - Auto/Visual Lisp: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">[Select]</a></div><pre class="cadlisp-7 geshi" style="font-family:monospace;"><ol><li style=""><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp;<span style="color: #666666; font-style: italic;">;-----------------------------------------</span></div></li><li style=""><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> &nbsp;<span style="color: #666666; font-style: italic;">; returns the x y point list of a caculated midpoint</span></div></li><li style=""><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">
Title: Re: question on the use of foreach
Post by: JohnK on August 21, 2014, 11:07:52 AM
Test post Chrome Win 8.1

I guess you'll have to just use the code tags and add "=cadlisp-7" to the opening tag. [ code=cadlisp-7 ]
Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 11:12:20 AM
Test post Chrome Win 8.1

I guess you'll have to just use the code tags and add "=cadlisp-7" to the opening tag. [ code=cadlisp-7 ]


Yup ... I'm going to do a test post from a Win 7 machine for $h!+$  :)
Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 11:27:11 AM
Same behavior with WinXP and Win7 maybe theme \ account related ?
Title: Re: question on the use of foreach
Post by: andrew_nao on August 21, 2014, 11:27:49 AM
Same behavior with WinXP and Win7 maybe theme \ account related ?

not me, win7 64 bit and it worked ok for me using chrome
Title: Re: question on the use of foreach
Post by: Mark on August 21, 2014, 11:34:34 AM
Same behavior with WinXP and Win7 maybe theme \ account related ?
Can you put the code tags in your post first then paste the text between them?

Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 11:41:38 AM
Code - Auto/Visual Lisp: [Select]
I can manually enter the tag, it just won't generate them.
Title: Re: question on the use of foreach
Post by: Mark on August 21, 2014, 01:12:25 PM
Code - Auto/Visual Lisp: [Select]
I can manually enter the tag, it just won't generate them.
to weird ....
Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 01:38:01 PM
What is weird is it can be reproduced on at least 4 different computers...
Title: Re: question on the use of foreach
Post by: JohnK on August 21, 2014, 01:56:44 PM
What is weird is it can be reproduced on at least 4 different computers...

I truly don't understand; do you live in the Bermuda triangle or some other anomalous geographic location? ...I'm at a loss. Sorry.
Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 02:03:08 PM
Interesting .. just tested in IE11 *shudder* and it works fine  :? . Still no go in Firefox or Chrome.
Title: Re: question on the use of foreach
Post by: JohnK on August 21, 2014, 02:04:41 PM
Interesting .. just tested in IE11 *shudder* and it works fine  :? . Still no go in Firefox or Chrome.

lmao!
Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 02:13:48 PM
Interesting .. just tested in IE11 *shudder* and it works fine  :? . Still no go in Firefox or Chrome.

lmao!


 :2funny:
Title: Re: question on the use of foreach
Post by: Kerry on August 21, 2014, 06:08:08 PM
Ron,
Do you have JavaScript enabled on the Browsers ??

I use Win 7 Pro x64 , Chrome(latest)
Title: Re: question on the use of foreach
Post by: ronjonp on August 21, 2014, 07:06:08 PM
Yup.