symbol
symbol(x...) -> Symbol
Create a Symbol
by concatenating the string representations of the arguments together.
Examples
-
Create a symbol from a single string:
julia> symbol("my_symbol") :my_symbol
This example creates a symbol with the name "my_symbol".
-
Concatenate multiple strings to create a symbol:
julia> symbol("hello", "_", "world") :hello_world
It concatenates the strings "hello", "_", and "world" to form the symbol
:hello_world
. - Use variables as arguments to create a symbol:
julia> name = "foo"; julia> num = 42; julia> symbol(name, "_", num) :foo_42
It uses variables
name
andnum
to create the symbol:foo_42
.
Common mistake example:
julia> symbol("my symbol")
ERROR: MethodError: no method matching symbol(::String)
In this example, the string "my symbol" contains a space, which is not allowed in symbol names. Symbols should consist of valid identifier characters without spaces or special characters.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.