samifox Posted September 8, 2013 Posted September 8, 2013 Hi cant figure out what is the different? Quote
Lee Mac Posted September 8, 2013 Posted September 8, 2013 I've always thought this was a good explanation by MP. Quote
samifox Posted September 8, 2013 Author Posted September 8, 2013 I've always thought this was a good explanation by MP. actually im even more confused why this one wil work: ; error: bad argument type: symbolp nil _$ (mapcar 'set '(x y z) '(1 2 3)) (1 2 3) but this yells _$ (set d 1) ; error: bad argument type: symbolp nil _$ Quote
Lee Mac Posted September 8, 2013 Posted September 8, 2013 why this one will work: ; error: bad argument type: symbolp nil _$ (mapcar 'set '(x y z) '(1 2 3)) (1 2 3) but this yells _$ (set d 1) ; error: bad argument type: symbolp nil _$ Note from the explanation in the linked post: "The set function is similar to setq except that set evaluates both of its arguments whereas setq only evaluates its second argument."Your first example is equivalent to: (set 'x 1) (set 'y 2) (set 'z 3) However, in your second example, the symbol d is being evaluated by the set function (since it is not quoted). Hence your second example evaluates to: ([color=blue]set[/color] [color=green]<value-of-d>[/color] 1) Which, if the symbol d has no value, is: ([font=Courier New][color=blue]set [/color][/font][font=Courier New][color=blue]nil[/color][/font] 1) Returning the error as you have described. A similar example explaining the same thing is given in the post to which I had linked: But what if we don't quote the first term when using set? If you don't quote the first term it is evaluated, which can cause problems if you don't understand what the ramifications are, and haven't initialized a accordingly. As exists currently, a is bound to 42, so if we tried to execute this statement (set a 7) we would get an error, because we would be trying to bind the value 7 to ... the value of 42. I would suggest that you re-read the post. Quote
samifox Posted September 8, 2013 Author Posted September 8, 2013 so... set() function is useless by writing (mapcar 'set '(x y z) '(1 2 3)) im using quote, so its the same as setq by writing (set d 1) i'll always get en error because d can be null or anything else that impossible to assign can you tell me please how and where set() function can be used? Quote
samifox Posted September 8, 2013 Author Posted September 8, 2013 what is the different ? _1_$ (set' a 10) 10 _1_$ (set 'a 10) 10 Quote
Lee Mac Posted September 8, 2013 Posted September 8, 2013 what is the different ? _1_$ (set' a 10) 10 _1_$ (set 'a 10) 10 There is no difference in this case - since AutoLISP does not care for whitespace, the posted expressions are identical. Quote
samifox Posted September 8, 2013 Author Posted September 8, 2013 so in the help , they give the example code of setq() in the page of set()? can you give example where set(0 comes handy? Quote
Lee Mac Posted September 8, 2013 Posted September 8, 2013 can you give example where set comes handy? A simple example: Permuting variables _$ (setq a 123) 123 _$ (setq b 456) 456 _$ (mapcar 'set '(a b) (list b a)) (456 123) _$ a 456 _$ b 123 The same operation would require a slack variable (c) if using setq: _$ (setq a 123) 123 _$ (setq b 456) 456 _$ (setq c a a b b c) 123 _$ a 456 _$ b 123 Quote
neophoible Posted September 9, 2013 Posted September 9, 2013 so... set() function is useless A bit harsh, don't you think? If you read the link provided earlier, it states that it has limited use, and for most folks, it isn't intuitive enough to deal with directly. But it's far from useless. And really, what would you do without it, as it's actually the basis for setq? Quote
Bhull1985 Posted September 9, 2013 Posted September 9, 2013 It's set in setq Missing the arbitrary set quoted value ....I...don't think this will be helpful. It is a haiku though Quote
samifox Posted September 9, 2013 Author Posted September 9, 2013 A bit harsh, don't you think? If you read the link provided earlier, it states that it has limited use, and for most folks, it isn't intuitive enough to deal with directly. But it's far from useless. And really, what would you do without it, as it's actually the basis for setq? i think its handy when you need to deal with the value of the container and not with the container, for example setting vars in real time 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.