as we know that variables can’t be variable in erlang. but consider this code,why each value of [1,2,3,4] is sequentially pattern matched to N,and don’t throw exception??
1> [2*N || N <- [1,2,3,4]].
[2,4,6,8]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Saying that a variable can’t be variable isn’t quite true. It’s more that a variable can only be assigned once. So the following psuedo-code is illegal:
However, the following is legal:
When we call fact(4) N will take the value 4 then 3 then 2 then 1 for each different function call. The code you are showing above is similar. For each item in the list N takes on a different value. But you never assigned the value of N more than once.