How to force inner variable to resolve first?

inner is a dictionary that resolves to text. outer is a function that receives two strings, name and attitude. attitude is one of “kind” and “rude”. However I get this error:

Dictionary does not contain key “attitude” (line 6)

Is this because attitude is being considered a key of inner rather than a parameter of outer? How can I fix my code?

#let inner = (
  kind: "Hello,",
  rude: "What up,"
)

#let outer(name, attitude) = inner.attitude + name

#outer("Steve", "rude")

Hello,

you are correct, if you write it like that Typst tries to access the key attitude. You have to use at: inner.at(attitude)

From the documentation:

You can access and create dictionary entries with the .at() method. If you know the key statically, you can alternatively use field access notation (.key) to access the value.

1 Like