# Custom OpName with int converted to string

**URL:** <https://itensor.discourse.group/t/custom-opname-with-int-converted-to-string/2533>\
**Category:** ITensor Julia Questions\
**Created:** [November 20, 2025, 12:57am UTC](https://itensor.discourse.group/t/custom-opname-with-int-converted-to-string/2533 "2025-11-20T00:57:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![colo4k](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@colo4k](https://itensor.discourse.group/u/colo4k)\
**Post date:** [November 20, 2025, 12:57am UTC](https://itensor.discourse.group/t/custom-opname-with-int-converted-to-string/2533/1 "2025-11-20T00:57:13Z")

</div>

Hi, I am new to julia and itensor and got a problem in defining custom operators. I want to define a sequence of custom ITensors.op like

`function ITensors.op(::OpName"M1", ::SiteType"Boson", d::Int)`  
`function ITensors.op(::OpName"M2", ::SiteType"Boson", d::Int)`  
`function ITensors.op(::OpName"M3", ::SiteType"Boson", d::Int)`  
`function ITensors.op(::OpName"M4", ::SiteType"Boson", d::Int)`

and so on. I tried to do this

`for i in 1:4`  
` function ITensors.op(::OpName"M"*string(i), ::SiteType"Boson", d::Int)`  
`end`

But then got an error saying:

syntax: “(::ITensors.SiteTypes.OpName{:M} \* string(i))” is not a valid function argument name

How could I convert an int to a string and then use the string in the OpName?

I am using julia 1.12 and ITensor 0.9.15. Thanks.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [November 20, 2025, 3:50pm UTC](https://itensor.discourse.group/t/custom-opname-with-int-converted-to-string/2533/2 "2025-11-20T15:50:46Z")

</div>

You can do that with `@eval`:

```julia
for i in 1:4
    @eval begin
        function ITensors.op(::OpName{Symbol("M", $i)}, ::SiteType"Boson", d::Int)
            # ...
        end
    end
end

```

---

<div class="post-metadata">

**Author:** ![colo4k](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@colo4k](https://itensor.discourse.group/u/colo4k)\
**Post date:** [November 20, 2025, 10:58pm UTC](https://itensor.discourse.group/t/custom-opname-with-int-converted-to-string/2533/3 "2025-11-20T22:58:28Z")

</div>

Thanks! This is very helpful

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)\
**Post date:** [November 30, 2025, 10:58pm UTC](https://itensor.discourse.group/t/custom-opname-with-int-converted-to-string/2533/4 "2025-11-30T22:58:41Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
