Interpolated string got memoized?

Is it a bug or am I doing something wrong?

julia> function testme2(note)
           for i ∈ 65:68
               c = Char(i)
               print("c=$c ")
               note = replace(note, "_" => "$c")
               println("testing: $note")
           end
       end
testme2 (generic function with 1 method)

julia> testme2("hello world _")
c=A testing: hello world A
c=B testing: hello world A
c=C testing: hello world A
c=D testing: hello world A

julia> function testme3(note)
           for i ∈ 65:68
               c = Char(i)
               print("c=$c ")
               note2 = replace(note, "_" => "$c")
               println("testing: $note2")
           end
       end
testme3 (generic function with 1 method)

julia> testme3("hello world _")
c=A testing: hello world A
c=B testing: hello world B
c=C testing: hello world C
c=D testing: hello world D

Since you replaced _ in the first loop iteration, there is nothing to replace in subsequent iterations. Don’t overwrite variable note.

1 Like

haha… my stupid mistake. Thanks!