Hallo -- I'm trying to be as object-oriented as possible when I code (because I have a simple brain that can't keep track of too many things), but I must admit, as a C++ coder, I am rather lost w/out pointers. Let's say I create a list called door-data that contains information I need to create a door. Using this data, I will create a list called door, which in turn will create lists called doorstop and arc. If I was doing this in C, I would have each of the sub lists contain a pointer to the object (here list) that created them, thus having access at all times to the data in the calling object (or list). As this would be a pointer there would be practically no overhead involved in this. But if I use setq, don't I end up duplicating loads of data? Wouldn't I end up copying loads of lists? Sorry if I haven't explained this well, but if anyone knows any techniques to work around this, or maybe a handy FAQ or list of good LISP coding practices, I'd be eternally grateful! Cheers for wading through this, doug.
so you are saying you want the sublists to point to the parents? In general, lisp is a super clucky language that works fast because computers are powerful. If you want a sublist to look to a parent list, the sublist would simply be a list of the parent list index's (indicies?...). Then you have to have your own "rebuild function" to get the actal sublist with values. The rebuld function would be specfici to the number of sublists you have and the relationships. Like if you had multiple levels, anytime a value of the table above had a nil, it would look one level higher and so on. So you are creating your own domino game to get to a sublist based on other lists. I regularly set up systems like this for various things in lisp. You have to create your own version of how objects work. A good example is how I handle global variables. I make them a list so i can pass around multiple values at once. This is improtant when grabbing defaults from a file or the registry, then checking them, then passing to a dialog box or something. You need libraries of your own set and get functions, then its almost like an object. You can set up subre=outines that use the global vars, then you have methods that almost act like objects. You have to really need it to do it but serious acad programmers can do large lisp programs if things are handled in this way. I have a lisp prog with like 25 different pieces to it, its like 50,000 lines of code or so and it runs with no real problems in terms of data passing. The tricky stuff is the finickyness of com objects, they like to be released all the time and care about how you set properties and run methods... biot023 <> |>Hallo -- I'm trying to be as object-oriented as possible when I code (because I have a simple brain that can't keep track of too many things), but I must admit, as a C++ coder, I am rather lost w/out pointers. |>Let's say I create a list called door-data that contains information I need to create a door. |>Using this data, I will create a list called door, which in turn will create lists called doorstop and arc. |>If I was doing this in C, I would have each of the sub lists contain a pointer to the object (here list) that created them, thus having access at all times to the data in the calling object (or list). As this would be a pointer there would be practically no overhead involved in this. |>But if I use setq, don't I end up duplicating loads of data? |>Wouldn't I end up copying loads of lists? |>Sorry if I haven't explained this well, but if anyone knows any techniques to work around this, or maybe a handy FAQ or list of good LISP coding practices, I'd be eternally grateful! |>Cheers for wading through this, |>doug. James Maeding jmaeding at hunsaker dot com Civil Engineer/Programmer
Your C++ brain damage is showing . In C++, when you put stuff in a list etc, most of the time it creates a copy. Lisp doesn't do that: it actually mostly uses pointers. Almost everything in Lisp is done with pointers, even though they don't exist as a user-manipulable object in the language. (Numbers and characters may be immediate data.) So: (setq *door-data* (list 1 2 3 4 5 6)) (setq doorstop (list 'a 'b *door-data*)) doorstop -> (A B (1 2 3 4 5 6)) This looks like it was a copy, but actually the third field is only a pointer to the list that happens to be the value of *door-data* at this time. I'd suggest as learning material the first chapters of some Common Lisp book, though most of the advanced stuff won't work in AutoLisp. See for example http://www.lisp.org/alu/res-lisp-education --