Jump to content

Recommended Posts

Posted

Hi

 

cant figure out what is the different?

Posted
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
_$ 

Posted
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.

Posted

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?

Posted
Facepalm.gif

 

:oops:

 

what is the different ?

 

_1_$ (set' a 10)
10
_1_$ (set 'a 10)
10

Posted
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.

Posted

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?

Posted
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

Posted
so... set() function is useless
:lol: 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?;)
Posted

It's set in setq

Missing the arbitrary

set quoted value

....I...don't think this will be helpful. It is a haiku though

Posted
:lol: 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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...