You are not logged in.
Hi, after completing a course in concurrent programming I came in to contact with Erlang for the first time. I've now been bitten by the Erlang bug and I've started doing some old assigments from a functional programming course, in Haskell, in Erlang. It's going quite well and I'm not missing the strong types yet
I've got some strange behavior that I need help understanding though. I want to check the length of each list within a list. Easy enough I though, but I got strange behavior when I started messing around with the creation of the matrix.
Random atom seems to work:
26> lists:duplicate(9,(lists:duplicate(9,null))).
[[null,null,null,null,null,null,null,null,null],
[null,null,null,null,null,null,null,null,null],
[null,null,null,null,null,null,null,null,null],
[null,null,null,null,null,null,null,null,null],
[null,null,null,null,null,null,null,null,null],
[null,null,null,null,null,null,null,null,null],
[null,null,null,null,null,null,null,null,null],
[null,null,null,null,null,null,null,null,null],
[null,null,null,null,null,null,null,null,null]]
Some integers work:
29> lists:duplicate(9,(lists:duplicate(9,4))).
[[4,4,4,4,4,4,4,4,4],
[4,4,4,4,4,4,4,4,4],
[4,4,4,4,4,4,4,4,4],
[4,4,4,4,4,4,4,4,4],
[4,4,4,4,4,4,4,4,4],
[4,4,4,4,4,4,4,4,4],
[4,4,4,4,4,4,4,4,4],
[4,4,4,4,4,4,4,4,4],
[4,4,4,4,4,4,4,4,4]]
Some don't:
30> lists:duplicate(9,(lists:duplicate(9,9))).
["\t\t\t\t\t\t\t\t\t","\t\t\t\t\t\t\t\t\t",
"\t\t\t\t\t\t\t\t\t","\t\t\t\t\t\t\t\t\t",
"\t\t\t\t\t\t\t\t\t","\t\t\t\t\t\t\t\t\t",
"\t\t\t\t\t\t\t\t\t","\t\t\t\t\t\t\t\t\t",
"\t\t\t\t\t\t\t\t\t"]
Actually, everything >7 and <255 gives this behavior.
┌─[gishten@hyperion]-[~]
└─[1680]-[22:21:45]> locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
Running x86_64 and erlang R13B04-3. To me it looks like some kind of charcode error, but google didn't help much.
Any Erlangers here?
Last edited by gishten (2010-04-19 15:54:19)
Believe in the Ideal, not the Idol.
Offline
Ah, crap!
Just realised that it's printing the ascii char for the argument.
I guess the solution is to use atoms for the integers aswell? That kind of bums me out since I'll need to put '' around every int.
I miss Haskells strong types already
Believe in the Ideal, not the Idol.
Offline
this is due to erlang's interpretation of bytes.
9 is the ascii value of "\t", so the output is totally valid.
for erlang it doesn't matter if something is given as a character or by number:
1> <<"hello">> =:= <<104,101,108,108,111>>.
true
Last edited by badboy (2010-04-17 20:39:03)
Offline
this is due to erlang's interpretation of bytes.
9 is the ascii value of "\t", so the output is totally valid.
for erlang it doesn't matter if something is given as a character or by number:1> <<"hello">> =:= <<104,101,108,108,111>>. true
I now realise where the error in my code was. I got a litte confused with theerror message.
I wanted to do.
(length(Sud) == 9) and lists:map(fun(X) -> length(X) end, Sud)
To check the matrix size and got:
76> sudoku:isSudoku(sudoku:filledSudoku(4)).
** exception error: bad argument
in operator and/2
called as true and "\t\t\t\t\t\t\t\t\t"
in call from sudoku:isSudoku/1
Adding the lists:all function fixed it.
Thank you for your help!
Believe in the Ideal, not the Idol.
Offline