Semantics of Multiple Values

Hi,

Isn’t * an array to values converter?
(like in method(1, *[2, 3, 4]))?

I don’t think so, even with your proposal. If * (splat operator) is
an array to values converter,

def func1(a,b)
[a,b]
end
func1(1, *[2, 3, 4])

should give [1,2], unless values work like LIST in Perl.

I tried it. It raises a wrong number of argument error (4 for 2).
However:
def func1(a,b,*rest)
[a,b]
end
func1(1, *[2, 3, 4])
do give [1,2]

  • Comparing multiple values
  • Unify operator

I have to confess I couldn’t understand those two proposals, how they
behave, and how they are useful.

The idea of comparing multiple values would be a kind of
syntactic sugar.
Instead of writing
x == 1 && y == 2
you could write
x, y == 1, 2
(which looks much clearer in my eyes).

Not for my eyes. YMMV.

Not obvious to me either. If feel like I would rather write
if [x, y] == [1, 2] then
OTOH, x, y == 1, 2 may help avoid building 2 Array objects and
speed things up (an optimizing compiler could do that too).

I don’t feel right to mix comparison operands x, 1, and y, 2.

                                                    matz.

I agree.
I feel like extending the syntax is worthwhile if the added
benefit is really significant.

Rather than allowing x, y == 1, 2, I would prefer a more
general x, y =~= 1, 2 whose semantic is richer due to the
fact that it may end up assigning either x, y or both if
they don’t exist already (or if they were unbound/freed).

Yours,

Jean-Hugues

···

At 08:53 28/04/2004 +0900, you wrote:

In message “Re: Semantics of Multiple Values (updated RCR)” > on 04/04/28, Kristof Bastiaensen kristof@vleeuwen.org writes:


Web: http://hdl.handle.net/1030.37/1.1
Phone: +33 (0) 4 92 27 74 17

Have a look at http://onestepback.org/index.cgi/Tech/Ruby/RubyBindings.rdoc
for a definition of a Reference class and a ref{var_name} factory method.

I like that code but I am looking for a better looking syntax.
ref{:a} is quite short, but I am looking for something shorter.

Ideally &a, but that is already valid syntax in Ruby for something else.

r{:a} is shorter, but pollutes Kernel space with a global r() method.

Is there an unary operator that can be redefined ?

Yours,

Jean-Hugues

oh, please no more obscure operators.
I think little people here would like this route when in the future we
found ourself using perl6-ish stuff like “@a >>=:=<< @b:slight_smile:

···

il Wed, 28 Apr 2004 13:35:09 +0900, Jean-Hugues ROBERT jean_hugues_robert@yahoo.com ha scritto::

Rather than allowing x, y == 1, 2, I would prefer a more
general x, y =~= 1, 2 whose semantic is richer due to the
fact that it may end up assigning either x, y or both if
they don’t exist already (or if they were unbound/freed).

Rather than allowing x, y == 1, 2, I would prefer a more
general x, y =~= 1, 2 whose semantic is richer due to the
fact that it may end up assigning either x, y or both if
they don’t exist already (or if they were unbound/freed).

oh, please no more obscure operators.
I think little people here would like this route when in the future we
found ourself using perl6-ish stuff like “@a >>=:=<< @b:slight_smile:

Oh, but it would pretty up the language so much!

   >

$@\ .-. //@$
@a >>=:=<< @b
// -~- \
LL ((z)) JJ

···

On Apr 28, 2004, at 12:14 AM, gabriele renzi wrote:

il Wed, 28 Apr 2004 13:35:09 +0900, Jean-Hugues ROBERT > jean_hugues_robert@yahoo.com ha scritto::

Well… once you have =~= you can get rid of both = and ==, =~= does
both (under certain circumstances). So I guess I am actually proposing
to have less operators ! kidding.

I agree with you. If something related to Unification is to be introduced,
say the pattern matching, I would rather have a “match()” builtin than
a rather contrived =~= binary operator.

Example: somewhere in a parser.

Get next token. If expecting a specific one, please specify it.

Returns next token or nil if it is not the expected one.

def next_tok( tok = free )
tok if match tok, $lex.next_tok()
end

def next_tok( tok = nil )
ntok = $lex.next_tok()
ntok unless tok and ntok != tok
end

x = next_tok()

syntax_err( “expected ‘end’”) unless next_tok( Tk::End)

Both methods serve the same purpose, but the first one’s body is
50% slimmer. It should be faster too.

I believe this is a significant increase in the expressiveness
of Ruby, for a rather low cost.

I will provide a user level prototypal implementation in Ruby soon.

Yours,

Jean-Hugues

···

At 16:14 28/04/2004 +0900, you wrote:

il Wed, 28 Apr 2004 13:35:09 +0900, Jean-Hugues ROBERT >jean_hugues_robert@yahoo.com ha scritto::

Rather than allowing x, y == 1, 2, I would prefer a more
general x, y =~= 1, 2 whose semantic is richer due to the
fact that it may end up assigning either x, y or both if
they don’t exist already (or if they were unbound/freed).

oh, please no more obscure operators.
I think little people here would like this route when in the future we
found ourself using perl6-ish stuff like “@a >>=:=<< @b:slight_smile:


Web: @jhr is virteal, virtually real
Phone: +33 (0) 4 92 27 74 17