Author Topic: Visual LISP: Understanding Variants and Safearrays  (Read 24038 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Visual LISP: Understanding Variants and Safearrays
« Reply #15 on: January 17, 2010, 05:25:39 PM »
From one of my reference books:
Quote
The vlax-make-safearray function creates a safearray of a dimension 1 to 16 and initializes it.

(vIax-make-safearray <type> '(<from1> . <to 1>) '( <from2> . <to2>) ... '(<from16> . <to16>)]. ..])
The first argument, <type>, is an integer constant. All subsequent arguments are dotted pairs, and their number is equal to the dimension of the array. In each pair, both elements are integer numbers. The first of them is the start value of the array index, while the second is its end value. The index values may be both positive and negative but the end value must not be less than the start value.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

nivuahc

  • Guest
Re: Visual LISP: Understanding Variants and Safearrays
« Reply #16 on: January 17, 2010, 05:38:19 PM »
Thats interesting that you should say that - I wondered whether the numbers should be the other way around, as I described in this post in the thread, the dimensions seem to run from the right to the left, but then I'm not entirely sure that the innermost element is the "first" dimension, or the "last"...

Perhaps I don't understand as much as I think I do...

Lee, you're much better at all of this stuff than I am but I'ma try to explain how I understand it by running a test against my belief of how it works.

Code: [Select]
(setq SATest (vlax-make-safearray vlax-vbString '(0 . 4) '(1 . 6) '(2 . 4)))
(vlax-safearray->list SATest)

(
  (("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
 )
  (("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
  )
  (("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
  )
  (("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
  )
  (("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
  )
)


The first dimension '(0 . 4) should contain 5 elements, or lists. Basically, 5 groups like this:

  (("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
    ("" "" "")
  )

It does.

The second dimension '(1 . 6) says that each of those lists should contain 6 elements, or lists. Basically, 6 groups like this:

    ("" "" "")

Yep. The third dimension '(2 . 4) says that each of those lists should contain 3 elements (an empty string in this case) and, looking at the list, it's obvious that it does.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Visual LISP: Understanding Variants and Safearrays
« Reply #17 on: January 17, 2010, 05:47:01 PM »
Thanks CAB for that clarification.

Chauvin, I think we are both on the same lines, but I took the first dimension as the innermost elements - i.e. "", whereas you took it as the entire list. But I believe you are correct, when looking at CAB's post.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Visual LISP: Understanding Variants and Safearrays
« Reply #18 on: January 18, 2010, 03:33:29 AM »
The small explanatory on structure SafeArreys :)

Code: [Select]
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 0)))
;>> ("")
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 0) '(1 . 1)))
;>> ((""))
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 0) '(1 . 1) '(2 . 2)))
;>> ((("")))
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 0) '(1 . 1) '(2 . 2) '(3 . 3)))
;>> ((((""))))
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 0) '(1 . 1) '(2 . 2) '(3 . 3) '(4 . 4)))
;>> ((((("")))))

Code: [Select]
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 1)))
;>> ("" "")
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 1) '(1 . 1)))
;>> (("") (""))
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 1) '(1 . 2)))
;>> (("" "") ("" ""))
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 1) '(1 . 1) '(2 . 2)))
;>> ((("")) (("")))
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 1) '(1 . 2) '(2 . 2)))
;>> ((("") ("")) (("") ("")))
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 1) '(1 . 2) '(2 . 3)))
;>> ((("" "") ("" "")) (("" "") ("" "")))

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Visual LISP: Understanding Variants and Safearrays
« Reply #19 on: January 18, 2010, 03:46:08 AM »
It is necessary to add, records
Code: [Select]
'(0 . 0) and
Code: [Select]
'(4 . 4) are completely equal as arguments.

Code: [Select]
(equal
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 0)))
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(10 . 10))))