<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">"sam1" is a list of length 4 whose first element is the integer $s.</div><div class="gmail_default" style="font-family:monospace,monospace">["sam1","sam2"] is a list 2 whose first element is the list "sam1".</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">I'm guessing that you're heading towards a problem that I discussed</div><div class="gmail_default" style="font-family:monospace,monospace">in my Prolog book: "How do I design a data structure in this language?"</div><div class="gmail_default" style="font-family:monospace,monospace">The basic rule is</div><div class="gmail_default" style="font-family:monospace,monospace"> - what are the different situations I need to represent?</div><div class="gmail_default" style="font-family:monospace,monospace"> - for each of these different situations, what additional</div><div class="gmail_default" style="font-family:monospace,monospace"> information is there?</div><div class="gmail_default" style="font-family:monospace,monospace"> - decide how to represent that context-dependent information</div><div class="gmail_default" style="font-family:monospace,monospace"> - in Prolog, give each situation its own function symbol;</div><div class="gmail_default" style="font-family:monospace,monospace"> in Erlang, consider the {Case_Label,Case_Dependent,Info...}</div><div class="gmail_default" style="font-family:monospace,monospace"> approach. Whatever you do, make each case OBVIOUSLY different</div><div class="gmail_default" style="font-family:monospace,monospace"> by a trivial pattern match (or a similarly trivial guard test</div><div class="gmail_default" style="font-family:monospace,monospace"> in Erlang).<br></div><div class="gmail_default" style="font-family:monospace,monospace"> - if some cases have one chunk of info and that is a sequence,</div><div class="gmail_default" style="font-family:monospace,monospace"> you might use a bare list but ONLY for one.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">With a well-designed Erlang data structure, there won't be any</div><div class="gmail_default" style="font-family:monospace,monospace">point in asking the question 'how do I tell the difference</div><div class="gmail_default" style="font-family:monospace,monospace">between "sam1" and ["sam1","sam2"]' because you will have made</div><div class="gmail_default" style="font-family:monospace,monospace">sure it is never the case that both are live possibilities.</div><div class="gmail_default" style="font-family:monospace,monospace">For example, if you want to model JSON, you might choose</div><div class="gmail_default" style="font-family:monospace,monospace">true | false | null -- the corresponding Erlang atom</div><div class="gmail_default" style="font-family:monospace,monospace">Number -- the same number</div><div class="gmail_default" style="font-family:monospace,monospace">String -- {string,String}</div><div class="gmail_default" style="font-family:monospace,monospace">[T1,....,Tn] -- {array,[T'1,....,T'n]}</div><div class="gmail_default" style="font-family:monospace,monospace">{K1:V1,...,Kn:Vn} -- [{K1,V1},...,{Kn,Vn}]</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Of course in current Erlang you might use a 'map' for the last.</div><div class="gmail_default" style="font-family:monospace,monospace">The point is that {string,"..."} and {array,[...]} are trivially</div><div class="gmail_default" style="font-family:monospace,monospace">easy to distinguish.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">You might want to give some consideration to using</div><div class="gmail_default" style="font-family:monospace,monospace"><<"sam1">> and</div><div class="gmail_default" style="font-family:monospace,monospace">[<<"sam1">>,<<"sam2">>]</div><div class="gmail_default" style="font-family:monospace,monospace">instead.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Perhaps you could go into more detail about what you want to achieve.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 17 Sep 2019 at 15:44, Sam Overdorf <<a href="mailto:soverdor@gmail.com">soverdor@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">How do I tell the difference between:<br>
"sam1"<br>
["sam1","sam2"]<br>
They are both lists but behave differently when I apply<br>
[H|T] = List.<br>
H = "s"<br>
H = "sam1".<br>
The second one is what I want and then stop breaking them down.<br>
<br>
Weird problem...<br>
<br>
Thanks,<br>
Sam<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>