Author Topic: show contents of a list  (Read 1392 times)

0 Members and 1 Guest are viewing this topic.

motee-z

  • Newt
  • Posts: 40
show contents of a list
« on: October 04, 2022, 05:22:34 PM »
hello all
how to show the contents of a list consist of real number, through alert
example
(setq lstv(list 2 5 8 10 18 19 20 25 30 31 41 42 ......... n))
how to prompt on screen by alert
(alert ???????????????????????????????????????)
thanks for any help

BIGAL

  • Swamp Rat
  • Posts: 1410
  • 40 + years of using Autocad
Re: show contents of a list
« Reply #1 on: October 04, 2022, 08:04:38 PM »
Fairly straight forward if all numbers

Code: [Select]
(setq lstv (list 2 5 8 10 18 19 20 25 30 31 41 42) str "")
(foreach val lstv
(setq str (strcat str " " (rtos val 2)))
)
(alert (strcat "List is " str))
A man who never made a mistake never made anything

dexus

  • Bull Frog
  • Posts: 207
Re: show contents of a list
« Reply #2 on: October 05, 2022, 02:41:07 AM »
This is a really weird way of doing it I guess, but it seems to work  :-D
Princ works with any variable and alert only works with a string.
The last line of the commandline is saved in the lastprompt sysvar and returned as a string.
So you end up with this:
Code - Auto/Visual Lisp: [Select]
  1. (defun alert-all (lstv)
  2.   (princ "\n")
  3.   (princ lstv)
  4.   (princ "\n")
  5.   (alert (getvar 'lastprompt))
  6.   (princ)
  7. )
« Last Edit: October 05, 2022, 02:58:32 AM by dexus »

dexus

  • Bull Frog
  • Posts: 207
Re: show contents of a list
« Reply #3 on: October 05, 2022, 03:01:06 AM »
Or using this build in function:
Code - Auto/Visual Lisp: [Select]

*Offtopic*
Wonder why most conversion functions have a -> arrow in the name, but this one has -to-.
Might be more consistent if it was vl-princ->string instead.
« Last Edit: October 05, 2022, 03:05:59 AM by dexus »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8696
  • AKA Daniel
Re: show contents of a list
« Reply #4 on: October 05, 2022, 03:44:53 AM »
Or using this build in function:
Code - Auto/Visual Lisp: [Select]

*Offtopic*
Wonder why most conversion functions have a -> arrow in the name, but this one has -to-.
Might be more consistent if it was vl-princ->string instead.

a conspiracy by a sinister and powerful group of anti pointer people

motee-z

  • Newt
  • Posts: 40
Re: show contents of a list
« Reply #5 on: October 05, 2022, 01:09:12 PM »
thank you

Pepe

  • Newt
  • Posts: 87
Re: show contents of a list
« Reply #6 on: October 07, 2022, 08:34:04 AM »
Other way...

Code - Auto/Visual Lisp: [Select]
  1. (alert (apply 'strcat (mapcar '(lambda (x) (strcat " " (itoa x))) lstv)))