Posted to tcl by mookie at Sun Dec 07 14:12:18 GMT 2025view raw

  1. -module(teddyshop).
  2. -export([get_teddy_bear/2]).
  3. -export([store_teddy_bear/1]).
  4.  
  5. -define(default_bear_colour, "blue").
  6. -define(default_bear_name, "mookie").
  7.  
  8. get_teddy_bear(BearColour, BearName) ->
  9. io:format("You've selected ~s, a ~s coloured bear~n", [BearName, BearColour]).
  10.  
  11. store_teddy_bear(Base32Data) when is_list(Base32Data) ->
  12. % nab our data in to binary
  13. Base32_RawBin = list_to_binary(Base32Data),
  14. % encode our data to base16
  15. Base16_Data = binary:encode_hex(Base32_RawBin),
  16. % represent our data as a list
  17. Base16 = binary_to_list(Base16_Data),
  18. % display our string
  19. io:format("String Returned: ~s~n", [Base16]);
  20.  
  21. store_teddy_bear(Base32Data) when is_binary(Base32Data) ->
  22. % Base32Data is already a binary, we can skip the conversion
  23. Base16_Data = binary:encode_hex(Base32Data),
  24. Base16 = binary_to_list(Base16_Data),
  25. io:format("String Returned: ~s~n", [Base16]).
  26. %% factory_store_teddybear (Base16).
  27.  
  28. 22> teddyshop:store_teddy_bear("mookie").
  29. String Returned: 6D6F6F6B6965
  30. ok
  31.  

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week