How to create a function with parameters without a name?

Hello! Please tell me how I can create a function in Tipst, in which one of the parameters will not have a name, but will have the type content. For example, in the function text, in it the parameter text, when passed does not require to name the name.

#let function1(param1: [], param2: "") = {
param1 + param2
}

#function1(param1: [text123], param2: "textt22")

In the example above, I created a function that takes two parameters. I need the first parameter to not require writing its name when passing it to the function. As in the same function, text.

thanks in advance!

This is quite common in typst functions, they can have both positional and named parameters. But positional parameters can’t have default values, so the regular way to write it would be like this:

#let function1(param1, param2: "") = {
  param1 + param2
}

Now the function can be used like in these ways:

#function1([text123], param2: "2")
#function1(param2: "2")[text123]
#function1[text123]

They all work. Similar to how you might call a built in element like block[x]; block(width: 2cm)[y] and so on, which also has 1 positional parameter and many optional named parameters.

3 Likes