Basic questions of a beginner

Hello,

I’m a beginner with Sonic Pi. I read the tutorial included with the software but I still have some questions.

I found a code on the internet which contains that part:

notes.each do |n|
        2.times do
          amps.each do |a|
            play n, amp: a
            s = sleeps.shift
            sleep sleeps.push(s).last
          end
        end

In fact I don’t understand elements like “.shift”, “.push” or “.last”. What these elements are supposed to do ? i don’t find them in the “Langage part” of the software. Nothing is explained about them. Also, I do not clearly understand what is the aim of “.” (the point) between elements/characters.

I got another question too: what means “+=”. I saw that in codes of some users but I have no idea about what it is used for.

Thanks by advance for your answers.

Regards,

A.

Hi there,

the code snippet you shared is very much a non-idiomatic bit of code. It is using features from the Ruby programming language (ruby-lang.org) which Sonic Pi is based on. However, it’s important to point out that given that these features aren’t documented (as you describe) they aren’t officially supported - so users should use them with this caveat in mind - a future version of Sonic Pi may break this undocumented behaviour without warning.

If you’re interested in looking gat these things in more detail, then you might enjoy reading some Ruby tutorials, but personally I would leave this until you’ve mastered all the basics :slight_smile:

Thank you for your answer Sam.