#11 ✓resolved
Philipp Pirozhkov

error in tuple matching using variables

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


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

Comments and changes to this ticket

  • Jared Kuolt

    Jared Kuolt December 10th, 2008 @ 12:20 PM

    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

    
    
  • Jared Kuolt

    Jared Kuolt December 10th, 2008 @ 12:22 PM

    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
    
    
  • Philipp Pirozhkov

    Philipp Pirozhkov December 10th, 2008 @ 01:46 PM

    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.

  • Tony Arcieri

    Tony Arcieri December 10th, 2008 @ 01:57 PM

    • State changed from “new” to “resolved”
  • Tony Arcieri

    Tony Arcieri December 10th, 2008 @ 01:59 PM

    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.

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Reia a dynamic scripting language for the Erlang virtual machine (BEAM)

People watching this ticket

Pages