Attributes

There are 3 kind of attributes in nadi. Environment, Network and Node attributes. as their name suggests environment attributes are general attributes available in the current context. Network attributes are associated with the currenly loaded network. and node attributes are associated with each nodes.

nadi has special syntax where you can get/set attributes for multiple nodes at once.

network load_str("a -> b\n b -> d\n c -> d\n");
# environmental attribute
env.someattr = 123;
env.other = 1998-12-21;
env array(someattr, other)
# network attribute
network.someattr = true;
network.someattr
# node attributes
node.someattr = "string val";

node.someattr

Results:

[123, 1998-12-21]


true


{
  d = "string val",
  c = "string val",
  b = "string val",
  a = "string val"
}

like you saw with the array function, variables used are inferred as the attributes of the current env/network/node task.

you can use attributes from outside of current task type in some cases like:

  • env/network variables can be used anywhere
  • node variables are valid in node tasks
  • node tasks has special variables types like inputs and output
network load_str("a -> b\n b -> d\n c -> d\n");
# environmental attribute
env.someattr = 123;
env.other = 1998-12-21;
# network attribute
network.someattr = true;

# using network attr in env task
env array(network.someattr, other)

# using nodes in network task
network nodes.NAME

Results:

[true, 1998-12-21]

["d", "c", "b", "a"]

Similarly inputs:

network load_str("a -> b\n b -> d\n c -> d\n");

node inputs.NAME

Results:

{
  d = ["b", "c"],
  c = [],
  b = ["a"],
  a = []
}

Refer to the network diagram below to verify the output are correct:

network load_str("a -> b\n b -> d\n c -> d\n");
network svg_save("./output/attrs-simp.svg")

Results: