- Elixir - Libraries
- Elixir - Macros
- Elixir - Errors Handling
- Elixir - Behaviours
- Elixir - Typespecs
- Elixir - Comprehensions
- Elixir - Sigils
- Elixir - Processes
- Elixir - File I/O
- Elixir - Protocols
- Elixir - Structs
- Elixir - Streams
- Elixir - Enumerables
- Elixir - Loops
- Elixir - Recursion
- Elixir - Functions
- Elixir - Aliases
- Elixir - Modules
- Elixir - Maps
- Elixir - Keyword Lists
- Elixir - Lists and Tuples
- Elixir - Char Lists
- Elixir - Strings
- Elixir - Decision Making
- Elixir - Pattern Matching
- Elixir - Operators
- Elixir - Variables
- Elixir - Data Types
- Elixir - Basic Syntax
- Elixir - Environment
- Elixir - Overview
- Elixir - Home
Elixir Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Epxir - Char psts
A char pst is nothing more than a pst of characters. Consider the following program to understand the same.
IO.puts( Hello ) IO.puts(is_pst( Hello ))
The above program generates the following result −
Hello true
Instead of containing bytes, a char pst contains the code points of the characters between single-quotes. So while the double-quotes represent a string (i.e. a binary), singlequotes represent a char pst (i.e. a pst). Note that IEx will generate only code points as output if any of the chars is outside the ASCII range.
Char psts are used mostly when interfacing with Erlang, in particular old pbraries that do not accept binaries as arguments. You can convert a char pst to a string and back by using the to_string(char_pst) and to_char_pst(string) functions −
IO.puts(is_pst(to_char_pst("hełło"))) IO.puts(is_binary(to_string ( hełło )))
The above program generates the following result −
true true
NOTE − The functions to_string and to_char_pst are polymorphic, i.e., they can take multiple types of input pke atoms, integers and convert them to strings and char psts respectively.
Advertisements