Erlang can match right when 'Passing parameters'

Source: Internet
Author: User

Under normal circumstances:

{A, B, C }={ 1, 2, 3 }.

But it cannot be {1, 2, 3} = {a, B, c }.

 

However, when the data is passed as a parameter, it can be right-aligned, for example:

Print ({Name, name} = nametup, {age, age})-> and

Print (nametup = {Name, name}, {age, age})->

Both methods can match nametup to the first parameter.

Modify: think about this problem in another way. In fact, the so-called "right-direction matching" is the first method, which is to first match the parameter to nametup and then cascade to {name, name. Therefore, the above statement is incorrect.

 

In particular, for example, if the parameter is record:

-Record (person, {name = {'lastname', 'firstname'}, Age, Sex }).

Printhw2 (# person {name = {_, name}, age = age} = someone)->

When matching the elements in a record, you must also match them right. I don't know if it's a syntax bug...

In the same way, we can understand that the Parameters match someone first, and then cascade to an anonymous {_, name} and age, the next step is the new record operation. So this is the right method, and my previous ideas are wrong.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.