Skip to content

Commit 0b80902

Browse files
authored
Merge pull request #3144 from emlyn/funcnames
Be less strict with initial capitals in function names
2 parents 0412210 + 6ec3d20 commit 0b80902

File tree

1 file changed

+16
-3
lines changed
  • app/server/ruby/lib/sonicpi/lang

1 file changed

+16
-3
lines changed

app/server/ruby/lib/sonicpi/lang/core.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,7 +2751,9 @@ def define(name, &block)
27512751
raise ArgumentError, "A function called #{name} is already part of Sonic Pi's core API. Please choose another name."
27522752
end
27532753

2754-
raise ArgumentError, "Function names can't start with a capital letter." if name.to_s =~ /^[A-Z]/
2754+
if block.arity == 0 && name.to_s =~ /^[A-Z]/
2755+
__delayed_warning "Functions with no required parameters shouldn't start with a capital letter."
2756+
end
27552757

27562758
if already_defined
27572759
__info "Redefining fn #{name.inspect}"
@@ -2768,7 +2770,9 @@ def define(name, &block)
27682770
accepts_block: true,
27692771
requires_block: true,
27702772
intro_fn: true,
2771-
doc: "Allows you to group a bunch of code and give it your own name for future re-use. Functions are very useful for structuring your code. They are also the gateway into live coding as you may redefine a function whilst a thread is calling it, and the next time the thread calls your function, it will use the latest definition.",
2773+
doc: "Allows you to group a bunch of code and give it your own name for future re-use. Functions are very useful for structuring your code. They are also the gateway into live coding as you may redefine a function whilst a thread is calling it, and the next time the thread calls your function, it will use the latest definition.
2774+
2775+
Note, it is not recommended to start a function name with a capital letter if it takes no parameters.",
27722776
examples: ["
27732777
# Define a new function called foo
27742778
define :foo do
@@ -2783,7 +2787,16 @@ def define(name, &block)
27832787
# For example, in a block:
27842788
3.times do
27852789
foo
2786-
end",]
2790+
end",
2791+
2792+
"
2793+
# Define a new function called play2, taking one parameter
2794+
define :play2 do |x|
2795+
play x, release: 2
2796+
end
2797+
2798+
# Call play2, passing in a value for the parameter
2799+
play2 42"]
27872800

27882801

27892802

0 commit comments

Comments
 (0)