Question: Write an Erlang function called sort_of_sum that takes one argument List . The function should behave as follows: (PLZ USE PATTERN MATCHING TO SOLVE THIS

Write an Erlang function called sort_of_sum that takes one argument List. The function should behave as follows:

(PLZ USE PATTERN MATCHING TO SOLVE THIS QUESTION)

  • If List is a list with no elements, print There is nothing there!
  • If List is a list with one element, print The sum is sum. where sum is the element.
  • If List is a list with two elements, print The sum is sum. where sum is the sum of the two elements.
  • If List is a list with three elements, print The sum is sum. where sum is the sum of the three elements.
  • If List is a list with more than three elements, print Thats too many to add! Hint: You will probably need to make use of the tail construct | somehow to pattern match this.
  • If List is anything else, print I cant add that!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!