symbol

symbol(x...) -> Symbol

Create a Symbol by concatenating the string representations of the arguments together.

Examples

  1. Create a symbol from a single string:

    julia> symbol("my_symbol")
    :my_symbol

    This example creates a symbol with the name "my_symbol".

  2. 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.

  3. Use variables as arguments to create a symbol:
    julia> name = "foo";
    julia> num = 42;
    julia> symbol(name, "_", num)
    :foo_42

    It uses variables name and num 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.

*Required Field
Details

Checking you are not a robot: