Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

error in tuple matching using variables

#11

module Retem
  def simple((~number, val))
    val

>> Retem.simple((~number, 3))
=> 3 

>> v=(~number, 3)            
=> (~number,3)
>> Retem.simple(v)           
exception error: no function clause matching 'Retem':simple({number,3})
  in function  erl_eval:do_apply/5
  in call from reia_erl:erl_funcall/3
  in call from 'Eval':exprs/2

looks like that a tuple is not wrapped by e2r here, "{tuple,...}" is missing

Reported by Philipp Pirozhkov · December 10th, 2008 @ 03:40 AM

State: resolved
Milestone: none
Assigned to: Tony Arcieri Tony Arcieri

Activity

  1. Jared Kuolt
    Jared Kuolt

    Note that it works if you pass the actual tuple itself:

    @@@$ bin/ire Reia Interactive Shell (prerelease) Running on Erlang (BEAM) emulator version 5.6.3 [source] [64-bit] [smp:4] [async-threads:0] [kernel-poll:true]

    module Retem .. def simple((~number, val)) .. val .. => ~ok Retem.simple((~number, 1)) => 1 v = (~number, 1)
    => (~number,1) Retem.simple(v) exception error: no function clause matching 'Retem':simple({number,1}) in function erl_eval:do_apply/5 in call from reia_erl:erl_funcall/3 in call from 'Eval':exprs/2

    
    

    December 10th, 2008 @ 12:20 PM

  2. Jared Kuolt
    Jared Kuolt

    Ugh. Stupid formatted. Let's try that again:

    $ bin/ire
    Reia Interactive Shell (prerelease)
    Running on Erlang (BEAM) emulator version 5.6.3 [source] [64-bit] [smp:4] [async-threads:0] [kernel-poll:true]
    
    >> module Retem
    ..   def simple((~number, val))
    ..     val
    ..
    => ~ok
    >> Retem.simple((~number, 1))
    => 1
    >> v = (~number, 1)      
    => (~number,1)
    >> Retem.simple(v)
    exception error: no function clause matching 'Retem':simple({number,1})
      in function  erl_eval:do_apply/5
        in call from reia_erl:erl_funcall/3
          in call from 'Eval':exprs/2
    
    

    December 10th, 2008 @ 12:22 PM

  3. Philipp Pirozhkov
    Philipp Pirozhkov

    Yes, thanks! I've included this piece of code especially to show that it works fine if we are passing the value, not the variable. The second case shows the problem itself. Besides, ticket title speaks for itself.

    December 10th, 2008 @ 01:46 PM

  4. Tony Arcieri
    Tony Arcieri
    • State changed from new to resolved

    December 10th, 2008 @ 01:57 PM

  5. Tony Arcieri
    Tony Arcieri

    Note that this problem does not occur in compiled expressions:

    
    >> module Foo
    ..   def bar
    ..     val = (~number, 3)
    ..     baz(val)
    ..   def baz((~number, val))
    ..     val
    .. 
    => ~ok
    >> Foo.bar()
    => 3
    

    It only occurs when the expressions are evaluated because the tuple value bound to the variable is being clobbered.

    December 10th, 2008 @ 01:59 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.