Unification of variables and methods

C

Charles Lowe

The one thing that bothers me about ruby is the (as i see it?) separate
namespaces for locals and functions.

Variables take precedence, but you can override and get the functional
form in 2 ways:

def x; 1; end
x = 2
x # => 2
x() # => 1
self.x # => 1

1. It seems somewhat messy, and prohibits using () as a message (eg,
sending :call)

x = proc { 1 }
x() # NoMethodError...
x[] # => 1

2a. It also leads to a more complex language to parse, and to those
interesting issues like:

def x; 1; end
x # => 1
x = 2 if false
x # => nil

2b. And other confusion as `*', '&' and '/' being mistaken at times,
with certain whitespace dependencies:

def foo1; end
foo2 = ''

foo1 / 1 # this / is division
foo1 /1 # this / starts an (as-yet unterminated) regexp.
foo2 / 1 # this / is division also
foo2 /1 # this / is also division! yet actually IRB trips up, looks
# for the rest of /, then gives a SyntaxError on
compilation.

a = [1, 2]
foo1 * a # * means splat
foo2 * b # * means multiply


I don't understand why they both just can't get along? :)
(ie at least in the same namespace, optionally with parsing not
dependent on the guessed type).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top