Skip to content

How to expand quoted patterns? #32

@hyphenrf

Description

@hyphenrf

My specific encounter was implementing a ghetto switch-case #31 like so:

let( match = something
     cases = some* thing onething $match #last one is 'default'
     bodies = ( {echo this is something}
                {echo this is thing}
                {echo this is onething}
                {echo reached default} ))
for (case = $cases; body = $bodies) if {~ $match $case} $body

but this will echo reached default because 'some*' won't be expanded inside the tilde-match statement.
this is good behaviour of course, but my question is do we have an idiomatic way to override it?

AFAIK there's no expand primitive, and eval would try to run the pattern as a command.
Perhaps the only answer is eval '{~ $match '$case'}', but I wonder if there's something more general to expand quoted patterns without necessarily running a command on them under eval..

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