What is the difference between a variable and a function without parameters

Hi all,

I am just working through the super helpful Sonic Pi tutorial and I was wondering what the difference between a variable and a function without parameters is.

It seems to me that they both accomplish the same thing?

Thank you!

hi,

Briefly :
Variable is to store a value into a name you choose. The name will be used to recall this value.
Function without argument can be used for some code you want to recall easily


tempo = 60

define :someNotes do
  
  play :c3
  sleep 1
  play :d3
  sleep 1
  
end

define :otherNotes do
  
  play :g3
  sleep 1
  play :a3
  sleep 1
  
end

4.times do
  use_bpm tempo
  someNotes
  otherNotes
  otherNotes
  someNotes
  tempo = tempo + 20
end

Cheers

Thank you!! Now i got it.

1 Like

A variable stores data.
A function is a subalgorithm