Skip to content

Support for string interpolation #9

Description

@gridbox

I have a use case in which I have a list of fields names that I would like to interpolate into the ~m and ~M sigils.

Current functionality

iex(9)> ~m{#{Enum.join(["hello","world"], ",")}} = %{"hello" => "hello", "world" => "world"}
** (FunctionClauseError) no function clause matching in Kernel.=~/2
    (elixir) lib/kernel.ex:1580: Kernel.=~({:::, [line: 9], [{{:., [line: 9], [Kernel, :to_string]}, [line: 9], [{{:., [line: 9], [{:__aliases__, [counter: 0, line: 9], [:Enum]}, :join]}, [line: 9], [["hello", "world"], ","]}]}, {:binary, [line: 9], nil}]}, ~r/\A\s*[a-zA-Z_]\w*\s*\|/)
             lib/shorter_maps.ex:106: ShorterMaps.get_old_map/1
             lib/shorter_maps.ex:78: ShorterMaps.do_sigil_m/3
             expanding macro: ShorterMaps.sigil_m/2
             iex:9: (file)
iex(9)> ~M{#{Enum.join(["hello","world"], ",")}} = %{hello: "hello", world: "world"}        
** (SyntaxError) iex:9: unexpected token: }

Desired functionality

iex(9)> ~m{#{Enum.join(["hello","world"], ",")}} = %{"hello" => "hello", "world" => "world"}
%{"hello" => "hello", "world" => "world"}
iex(9)> ~M{#{Enum.join(["hello","world"], ",")}} = %{hello: "hello", world: "world"}        
%{hello: "hello", world: "world"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions