[erlang-questions] Help with tuple pattern match?

Deryk Barker dbarker@REDACTED
Wed Jun 18 20:59:15 CEST 2008


Caitlin Gibbons wrote:
> Hi all.
>
> I'm looking at:
>
> Person={person,{name,{first,joe},{last,armstrong}},{footsize,42}}.
>
> and trying to extract the value of 'last', i.e., 'armstrong'.
>
> {_,{_,{_,{_,Last},_}=Person.
>
> was unsuccessful. Any help?
I think your tuple nesting went slightly awry; shouldn't that be:

{_,{_,{_,_},{_,Last}},{_,_}} = Person.

or - from my limited experience - preferably:

{person,{_Name,{first,_First},{last,Last}},{footsize,_Footsize}} = Person.

which only matches tuples with the appropriate tags in them.

-- 
|Deryk Barker, Computer Science Dept. | Music does not have to be understood|
|Camosun College, Victoria, BC, Canada| It has to be listened to.           |
|email: dbarker@REDACTED         |                                     |
|phone: +1 250 370 4452               |         Hermann Scherchen.          |





More information about the erlang-questions mailing list