Adventures in SonicPi! getting started: common issues and questions from newcomers

Hello lovely human and wise coders :slightly_smiling_face:

In week one learning / testing, with plans to share all my progress and ideas, however weird and wonderful they may be!

First question: it appears the log command is supported, but doesn’t output to the log panel (despite what bing-gpt claims:)

Is this outputting anywhere and how to access?
(Not sure if it’s writing to a file, or if a file can be set as logging option, or if log should simply be ignored as n/a and use print and puts

log 'hello'

Many thanks

:information_source: alias methods

Mainly as a proof-of-concept, but also after noticing repetition and keystrokes with comment and uncomment do blocks.

I saw use of the p alias to print with ruby, so defined this first

define :p  do |n| print n end

usage: p 'test'

I then made aliases for comment and uncomment

comment / uncomment

define :c do |code|
  comment do
    run_code(code)
  end
end

define :u do |code|
  uncomment do
    run_code(code)
  end
end

usage: c "puts 'hey'" to comment, u "puts 'hey'" to uncomment

Hi there,

log is an internal method and not part of the documented API so it should be ignored. As you mentioned prefer puts and print instead :slight_smile:

1 Like

adopting shorthand notation

def u(code)
  uncomment do
    run_code code
  end
end

same usage: u "puts 'hey'"