Erlang on Windows List Comprehension multiply gives “\f”

后端 未结 2 1470
春和景丽
春和景丽 2021-01-25 22:23

Hi i have a weird problem with Erlang on Windows i am running 16B and WinXP.

I have the following code

-module(test).
-export([cost/1,total/1]).
cost(ora         


        
相关标签:
2条回答
  • 2021-01-25 22:36

    Note your cost/1 function returns a number. But total/1 returns a list (of numbers). The results on that list are ok, this is just how erlang happens to display lists of small integers. See http://www.erlang.org/faq/problems.html 9.3

    to see what I mean, try with larger numbers

    test:total([{orange,2000}]).
    

    Again, this is just a display issue, the value in the lists are what you expect. Try it:

    [Value] = test:total([{orange,2}]).
    Value.
    
    0 讨论(0)
  • 2021-01-25 22:37

    A string is a list of integers. The value you're returning is a list of integers.

    Erlang uses a simple heuristic for when to show something as a string, or as a list of integers: is it a flat list containing only numbers in the range {55,250}. (I made those numbers up, but it's something like that. If there are control characters or low characters, it bails.)

    Since Erlang doesn't do this to tuples, tuples make it easy to see.

    1> {72,101,108,108,111,44,32,83,116,101,112,104,101,110,46}.
    {72,101,108,108,111,44,32,83,116,101,112,104,101,110,46}
    
    2> [72,101,108,108,111,44,32,83,116,101,112,104,101,110,46].
    "Hello, Stephen."
    

    Erlang is just guessing wrongly what's inside the list.

    HTH.

    0 讨论(0)
提交回复
热议问题