Lee Mac Posted February 14, 2015 Posted February 14, 2015 This is all very, very helpful and informative. You speak my language, in the sense of explaining things; the way you explain it to me sounds a lot like the way i would explain things that i understand to others who don't, i.e. you make this very straight forward and easy for me to understand. I wish all of my college professors were this thorough and easily understandable (I had maybe a total of two who were, and I'll never forget them). Thank you Beeftimer - I like to explain things in great detail and remove as much ambiguity as possible; I find that it's only when you try to fully explain something to someone else do you test your own understanding of the subject - vague & 'hand-wavy' explanations tend to betray an underlying lack of understanding. 1. What is the meaning of _$ ? I've also seen this on your website. No meaning exactly, this is merely a directly copy of expressions evaluated through the Visual LISP IDE (VLIDE) console, which allows you to evaluate AutoLISP expressions 'on-the-fly'. Refer to my introduction tutorial on the Visual LISP IDE for information on how to access this utility. 2. The repeat function is basically a for-loop, yes? repeat will evaluate all expressions following the first argument a number of times equal to the first argument and will then return the value returned by the last evaluated expression, e.g.: _$ (repeat 5 (princ "\nHello World!")) Hello World! Hello World! Hello World! Hello World! Hello World!"\nHello World!" This could indeed be written as a for loop in the following way: for (int i=0; i<5; i++) { cout << 'Hello World!\n'; } 3. A dotted pair is simply a list with two atoms? In short, yes - a dotted pair is a list with two atoms, however, there are important differences in the way in which a list & dotted pair are stored in memory. In LISP a standard list is stored in memory as a linked list (or more precisely, a singly linked list). Each item in an AutoLISP list occupies an allocated amount of memory, for example, an integer will occupy 32-bits (4 bytes), an ASCII character 8-bits etc. However, rather than each list item being stored in consecutive memory addresses, each item will occupy an allocated quantity of memory known an Address Register, followed by a pointer giving the location of the memory address of the next item in the list - this pointer is known as the Decrement Register. Variables in AutoLISP act in much the same way: a variable is simply a pointer to the memory address which stores the data associated with the variable. Hence, a list variable is a pointer to the Address Register for the first list item. As noted in my earlier post, the car function will return the Contents of the Address Register, that is, the first item of a list; whereas, the cdr function will return the Contents of the Decrement Register, giving the location of the memory address of the Address Register for the second list item, which is effectively the same as having a variable pointing to the remainder of the list. A dotted pair differs from a standard list in that rather than using two registers for each list element (an Address Register & Decrement Register), the dotted pair uses two adjacent registers to store the first & second element. Hence, the car function is still accessing the value of the first register, however, rather than accessing a pointer, the cdr function is now accessing the associated value of the dotted pair and so the cdr function returns a value as opposed to a list. Also (to anyone who might know the answer), when using a single quote (e.g. when inputting a list), basically what that's doing is telling the computer that the expression inside the parentheses is not a function, right? For example, when you write: (foreach n '(a b c) print n)) the ' tells the function that (a b c) is a list instead of telling it that "a" is a function to be evaluated, correct? Do I understand this properly? Lee (if you're reading this), I know you went in depth explaining this on your website, but I just wanted to make sure that I've got a handle on this concept. You are correct in your understanding, however, the single quote has a more encompassing behaviour in that anything following the quote will not be evaluated by the interpreter - be it a list, integer, real, symbol etc. For example, consider the following set expression: _$ (set 'a 1) 1 set operates in much the same way as setq, however set evaluates both of the supplied arguments, therefore, to assign a value to a symbol using set, the symbol must be quoted so that it remains a symbol argument and is not evaluated to yield any value it may possess. Aside, note that the above example is just an emulation of the setq function, since setq is a 'convenience function' or shorthand for (set (quote)) As a further example, you can observe the difference between supplying a quoted & unquoted argument to the set function by considering the following example demonstrating a form of indirect addressing in AutoLISP: _$ (set 'a 'b) B _$ (set a 3) 3 _$ b 3 From your post, I understand you may have already studied my tutorial on The Apostrophe and the Quote Function, but notice that the tutorial describes the use of the single quote in several applications other than quoting list data. Lee Quote
psif82 Posted March 30, 2019 Posted March 30, 2019 I was trying to use your code Lee but it says error: extra cdrs in dotted pair on input. Any idea why? Quote
Lee Mac Posted March 31, 2019 Posted March 31, 2019 (edited) 14 hours ago, psif82 said: I was trying to use your code Lee but it says error: extra cdrs in dotted pair on input. I've updated my earlier code posts to remove the BBCode formatting displayed by the new forum software (previously one could apply colour formatting to code blocks). This thread was the inspiration for my tutorial Building Association Lists: A Simple Block Counter which you may also find useful. Lee Edited March 31, 2019 by Lee Mac Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.