Friday, February 20, 2009

Erlang, you are holding out on me!

So I was playing around with list comprehensions today and found myself looking at permutations of strings when I noticed I wasn't getting "everything" back from the shell.

I'm sure there is a good reason for this, but I'm unclear as to what to search for in order to find an answer. The code I'm talking about is as follows:

[ [String1]++[String2] || String1<-"ABCDEFGHIJKLMNOPQRSTUVWXYZ", String2<-"ABCDEFGHIJKLMNOPQRSTUVWXYZ"].


which produces:

["AA","AB","AC","AD","AE","AF","AG","AH","AI","AJ","AK",
"AL","AM","AN","AO","AP","AQ","AR","AS","AT","AU","AV","AW",
"AX","AY","AZ","BA","BB",
[...]|...]


I'm sure it is just trying to save some horrendous output, but what if for some un-Godly reason I needed it all, how do I turn those [...]'s into more values?

Anyway, just thought this was interesting.

2 comments:

beerriot said...

In case you haven't found your answer yet, the thing you wanted to search for was "pretty printing", and the specific function you're most likely interested in is rp/1:

rp(lists:seq(1, 1000000)).

will actually print all 1m elements to the shell. You can get the same effect with an io:format/2.

Ulf Wiger has a nice list of other pretty printing methods.

BradfordW said...

Yea, I stopped being lazy and dug into it. Thanks for the link though, that seems much nicer than writing some more "verbose" code.