Group Abstract Group Abstract

Message Boards Message Boards

1
|
3.5K Views
|
0 Replies
|
1 Total Like
View groups...
Share
Share this post:

Understand Entity property assignment inside Do/Table?

Posted 6 years ago

Hello, everybody.

Assigning property of an Entity changes the value of a property (or creates a new Entity and even EntityType and registers it in EntityStores).

Syntax like assigning to the property seems to be the only documented way to change the value associated with the property:

Entity["NewClass", "NewEntity"]["prop"] = 1;

But mass updating of Entities using Do does not work:

Do[e["prop"] = 2, {e, EntityList["NewClass"]}] (*Set::write: Tag Entity in NewEntity[prop] is Protected.*)

I think this is because of magic of how Do (and Table) handle expressions.

Surprisingly, isolating the variables using With solves the issue:

Do[With[{a = e}, a["prop"] = 1000], {e, EntityList["NewClass"]}]

Is this an expected behaviour?

Any insights on how Do-like functions process their first arguments are welcome.

Best regards, Pavel

POSTED BY: Pavel Perikov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard