Hello!
Can anyone explain that?
p a,b,c=1,2,3
what shall I say?
If someome is interested in a new "Ruby-like" language, please let me know!
Opti
Hello!
Can anyone explain that?
p a,b,c=1,2,3
what shall I say?
If someome is interested in a new "Ruby-like" language, please let me know!
Opti
Hello!
Can anyone explain that?
a,b,c=1,2,3
p a,b,c = 1,2,3
what shall I say?
If someome is interested in a new "Ruby-like" language, please let me know!
Opti
Two different views:
A. parser gem:
$ ruby -r parser/current -e 'p
Parser::CurrentRuby.parse("a,b,c=1,2,3\np a,b,c = 1,2,3")'
s(:begin,
s(:masgn,
s(:mlhs,
s(:lvasgn, :a),
s(:lvasgn, :b),
s(:lvasgn, :c)),
s(:array,
s(:int, 1),
s(:int, 2),
s(:int, 3))),
s(:send, nil, :p,
s(:lvar, :a),
s(:lvar, :b),
s(:lvasgn, :c,
s(:int, 1)),
s(:int, 2),
s(:int, 3)))
B. calling a different method:
$ cat foo.rb
def foo(*args)
args.each_with_index { |a,i| p [i, a] }
end
a,b,c = 1,2,3
foo(a,b,c = 1,2,3)
#=> [0, 1] (from variable 'a')
#=> [1, 2] (from variable 'b')
#=> [2, 1] (from variable 'c')
#=> [3, 2] (from literal '2')
#=> [4, 3] (from literal '3')
puts
p [?a, a]
#=> ["a", 1]
p [?b, b]
#=> ["b", 2]
p [?c, c]
#=> ["c", 1]
On 9/20/21, Die Optimisten <inform@die-optimisten.net> wrote:
Can anyone explain that?
a,b,c=1,2,3
p a,b,c = 1,2,3
what shall I say?
From what I know, there's a difference in Ruby - which is not as pronounced as in some other languages - between expressions and statements. In C or JavaScript a statement doesn't have a return value, eg.
if (1) {
1;
}
else {
2;
}
In Ruby, an equivalent to this has a return value, but it's still treated differently by a parser. Should it, or shouldn't it - this is a different topic. You can always wrap a statement in parentheses to make it pass as an expression.
(Take all this above with a grain of salt - I'm not too experienced with parsers in general, I may be wrong on one thing or another)
The issue, while also a strength of Ruby is that... our parser has already touched its limits. There are a lot of ideas of new syntax proposals, but such a syntax can be ambiguous and we even have to treat spaces specially - which is not an issue in easier syntaxes like C. One of the biggest problems (but also - strenghts) is that Ruby allows you to write method calls without parentheses. All this makes an attempt to unify expressions and statements a futile and impossible effort.
On 9/20/21 8:23 PM, Die Optimisten wrote:
Hello!
Can anyone explain that?
a,b,c=1,2,3
p a,b,c = 1,2,3
what shall I say?If someome is interested in a new "Ruby-like" language, please let me know!
Opti
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
> Hello!
>
> Can anyone explain that?
>
> a,b,c=1,2,3
> p a,b,c = 1,2,3
> what shall I say?
>
> If someome is interested in a new "Ruby-like" language, please let me
> know!
>
> Opti
Hey Opti, have you taken a look at Crystal or Elixir ? Some cool stuff
going on there as well.
On 9/20/21 8:23 PM, Die Optimisten wrote:
--
A musician must make music, an artist must paint, a poet must write, if he
is to be ultimately at peace with himself.
- Abraham Maslow