title: Differentiate between atom and list in SML
body: <p>I am new to SML programming and I have a problem to create a function to remove occurrences of an atom A from a list of integers. This list can be nested to any levels, 
  means we can have list like [1,2,3] and we can have list like [[1,2],[2,3]] as well as list like [[[1,2],[1,2]],[[2,3],[2,3]]].<br>
  So my problem is how can I check if the given item is a list or an atom as I have not found any such function in SMLNJ so far?<br>
  I have created a function that checks if the list is empty or not and then it calls a helper iterative function to check if the head of the list is a list or an atom. If it's an atom then replace it with another atom and continue with the rest of the tail.</p>
  
  <p>Inside the helper function if I check that tail of the head of list is empty then it gives an error as tail function can have a list only.<br>
  So I have to do it like 
  <code>tl([hd(a))</code>, and if I do that, then it will always be empty.<br>
  If I apply it on the first list I get head as 1 and wrapping it in [] results in [1], so tail of this will be []. Same way if I get head of second list it will be [1,2] and wrapping it in [] will result in [[1,2]], so tail of this is again [].
  So is there any way how I can check if the given item is an atom or again a list?</p>
  
  <p>Thanks in advance for all responses.</p>