Some thoughts on duck typing

David Bovill david at vaudevillecourt.tv
Wed Jan 12 06:37:28 EST 2011


If it quacks like a duck it is a duck.

So I have some data in a variable that I want to display. I can use is an
array/number/date - but for other types of data I'm wandering... xml should
be easy, but harder would be to distinguish long text files from binary. Any
ideas for hacks to distinguish:

   1. images
   2. sounds
   3. video
   4. binary blob
   5. text
   6. rtftext
   7. utf8

I think a lot of these can be tested by trying them out in various
containers - ie can I create an image? What happens if I set the unicodetext
of a field... but some of the work needs to be done by looking at the data
first. So what would a duck_Type handler look like for LiveCode:

function duck_Type someData
  switch
    case someData is an array
      return "array"
    case someData is a date
      return "date"
    case someData is a number
      return "number"
    case ???
      return "???"
  end switch
end duck_Type

Note - the idea is to work on data in a variable, not a file. I have a few
handlers for looking at files - any suggestions / snippets of code?



More information about the use-livecode mailing list