Found some weird behavior. Thought I would ask here

I was starting with a base from another song, so I dropped the code in, and made some slight changes. However, instead of giving me any errors. I get some weird behavior.

This is the code
https://pastebin.com/3hd0aTb0

For some reason, when I run it, nothing happens, and then, my enter key will not work in Sonic Pi at all. I can back space, I can type, but I can’t hit enter and go to the next line for the life of me.

When I use it outside of Sonic Pi, it is fine, and when I restart it.

Does anyone here seen something like this? It seems like an extremely weird error.

Just for the record, in case the pastebin link disappears here’s the code that was pasted:

use_bpm 132

#Arpeggios and Note Methods
define :intro do
  introNotes = [:cs4,:fs3,:fs4,:cs3,:fs4,:fs2,:cs3,:es3, :d3, :bs4].choose
  puts intro
  x = 0
  #Sleep 5 total
  10.times do
    play introNotes, release: 4, sustain: 4
    x = x + 1
    sleep 8
  end
end

with_synth :blade do
  intro
end

The issue here is in the following line defined in the function :intro:

 puts intro

This is an example of infinite recursion.

In order to print the value of intro the function intro must be called. Of course, the definition of intro includes this line, so it calls itself again again until the computer can’t keep up.

Remove this line, or if you just want to log that the intro function was called, simply convert it to a string:

puts "intro"

I hope that this helps :slight_smile:

ohhhhhh. I gotcha. I was trying to debug something and thought I was putting out the note. Thank for that catch.

So, if i see this behavior, it’s because I got a infinite loop. I gotcha.

Thanks for the help. I couldn’t figure what in the code could cause my keyboard to stop working. haha