Your Turn

  • Exercise: StringsAndBinaries-1

    Write a function that returns true if a single-quoted string contains only printable ASCII characters (space through tilde).

  • Exercise: StringsAndBinaries-3

    Try the following in iex:

     
    iex>​ [ ​'cat'​ | ​'dog'​ ]
     
    [​'cat'​,100,111,103]

    Why does iex print ’cat’ as a string, but ’dog’ as individual numbers?

  • Exercise: StringsAndBinaries-4

    (Hard) Write a function that takes a single-quoted string of the form number [+-*/] number and returns the result of the calculation. The individual numbers do not have leading plus or minus signs.

    calculate(’123 + 27’) # => 150

Get Programming Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.