From: G
Subject: List question
Date: 
Message-ID: <dpr8pa02e5u@news4.newsguy.com>
Hello I'm learning autolisp. I'm familiar with the
C programming language so naturally I try to
find an equivalent way of doing something that
I'm used to. However there is limited info on
Autolisp, and I'm wondering if you guys could
tell me is there any way to work with the interior
List variable data types? In other words it appears
that in AutoLisp a List is the same thing as a
Structure in C. So here is an example of how one
works with interior structure data with C and
below that is one I found with AutoLisp but it does
not work directly with the typename but rather
uses a displacment nth command or the foreach
command. Is there any way to match the more
convenient C method which frees you from keeping
tract of the array location of a List item?

//Define data type
typedef struct
{char name[21];
 char city[21];
 char state[3];
}Rec;

//Declare a Structure of this type
Rec StructName;

//Operate on the structure
strcpy StructName.name, "Leigh");
strcpy StructName.city, "Raleigh");
strcpy StructName.state, "NC");

// etc or whatever.
--------------------
However in AutoLisp it doesn't seem to
give a way to work directly with names
but holds you to keeping track of a location
of the item within the list.
(setq myList(list "e" "b" "c" "m" "at"))
 (foreach myVar myList
  (princ (strcat myVar (nth 4 myList)))
  )
 )
)

From: Frank Buss
Subject: Re: List question
Date: 
Message-ID: <1g39yzw6n7hz$.1xy6gm090hiaw.dlg@40tude.net>
G wrote:

> Hello I'm learning autolisp. 

perhaps the newsgroup comp.cad.autocad is a better place to ask.

> and I'm wondering if you guys could
> tell me is there any way to work with the interior
> List variable data types? 

In Common Lisp you can do this:

CL-USER > (defparameter my-list '(a b c d))
MY-LIST

CL-USER > (elt my-list 2)
C

CL-USER > (setf (elt my-list 2) "hello")
"hello"

CL-USER > my-list
(A B "hello" D)

But for large lists you should use a vector instead of a list.

-- 
Frank Buss, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Rainer Joswig
Subject: Re: List question
Date: 
Message-ID: <BFE6F5CA.253C2%joswig@lisp.de>
Am 08.01.2006 16:45 Uhr schrieb "Frank Buss" unter <··@frank-buss.de> in
·······························@40tude.net:

> G wrote:
> 
>> Hello I'm learning autolisp.
> 
> perhaps the newsgroup comp.cad.autocad is a better place to ask.
> 
>> and I'm wondering if you guys could
>> tell me is there any way to work with the interior
>> List variable data types?
> 
> In Common Lisp you can do this:
> 
> CL-USER > (defparameter my-list '(a b c d))
> MY-LIST
> 
> CL-USER > (elt my-list 2)
> C
> 
> CL-USER > (setf (elt my-list 2) "hello")
> "hello"

Small problem here. '(a b c d) is a constant data structure and not supposed
to be modified. Yeah, that's really ugly, I know.

For example if you have:

(defparameter foo '(1 2 3 4))
(defparameter bar '(1 2 3 4))
(defparameter baz '(2 3 4))

If you compile a file containg above statements, the compiler is allowed to
share structure of the lists. So FOO and BAR could share the same list and
BAZ could reuse a sublist from FOO or BAR.

So, for example, if you could modify the second element from BAZ,
then FOO or BAR might or might not change too.

Yes, there are compiler that use this data sharing.

So, if you safely want to modify a list, it should be consed together by
something like CONS, LIST or consing functions.

> 
> CL-USER > my-list
> (A B "hello" D)
> 
> But for large lists you should use a vector instead of a list.
From: G
Subject: Re: List question
Date: 
Message-ID: <dprrif013u@news4.newsguy.com>
>perhaps the newsgroup comp.cad.autocad is a better place to ask

Well I could try there, I had already tried at
autodesk.autocad.customization but I got zero replies.
From what you guys have said it's prolly just not
available in practical form from autolisp.
Thanks though.
From: Pascal Bourguignon
Subject: Re: List question
Date: 
Message-ID: <878xtqy9om.fsf@thalassa.informatimago.com>
"G" <······@NoSpam> writes:

> [...] In other words it appears
> that in AutoLisp a List is the same thing as a
> Structure in C. [...]

No, it's not the same.  But if there is no way to make a structure or
a vector in autolisp, if there are macros you could implement a
structure abstraction over lists.  Or fetch some autolisp library
implementing defstruct for you.  Then you'd write:

(defstruct rec name city state)

(setf s (make-rec :name "Leight" :city "Raleigh" :state "NC"))
(print (rec-name s))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Kitty like plastic.
Confuses for litter box.
Don't leave tarp around.
From: John Thingstad
Subject: Re: List question
Date: 
Message-ID: <op.s23onmpgpqzri1@mjolner.upc.no>
On Sun, 08 Jan 2006 15:49:19 +0100, G <······@NoSpam> wrote:
Autolisp is in autocad right?
Well in CL there is defstruct..
http://www.lispworks.com/documentation/HyperSpec/Body/m_defstr.htm



>
> //Define data type
> typedef struct
> {char name[21];
>  char city[21];
>  char state[3];
> }Rec;
>
> //Declare a Structure of this type
> Rec StructName;
>
> //Operate on the structure
> strcpy StructName.name, "Leigh");
> strcpy StructName.city, "Raleigh");
> strcpy StructName.state, "NC");
>
> // etc or whatever.
> --------------------
> However in AutoLisp it doesn't seem to
> give a way to work directly with names
> but holds you to keeping track of a location
> of the item within the list.
> (setq myList(list "e" "b" "c" "m" "at"))
>  (foreach myVar myList
>   (princ (strcat myVar (nth 4 myList)))
>   )
>  )
> )
>
>



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/