Skip to content

Destructuring ambiguity after & #2

Open
@mva

Description

I'm relying on "&" destructuring to hierarchically decompose my
URI namespace. At the end of the URI, the "&" can match both "no
further path segment" as well as "exactly one empty path
segment", and the two cannot be distinguished afterwards.

First a non-"&" example:

(use 'net.cgrand.moustache)  ;; [net.cgrand/moustache "1.0.0-SNAPSHOT"]

(def my-app
     (app
      ["foo"] (fn [_] "foo")
      ["foo" ""] (fn [_] "foo/")))

(my-app {:uri "/foo"}) ; ["foo"]
==> "foo"
(my-app {:uri "/foo/"}) ; ["foo" ""]
==> "foo/"

And then the "foo" prefix factored out:

(def my-app
     (app ["foo" &]
          (app [] (fn [_] "foo")
               [""] (fn [_] "foo/"))))

(my-app {:uri "/foo"}) ; ["foo"]
==> "foo"
(my-app {:uri "/foo/"}) ; ["foo" ""]
==> "foo"  ;; <--- my problem

Here, the two different URIs are no longer distinguishable by
app's destructuring mechanism.

I'm not sure what I would expect app to do different here. When
I wrote this code I thought I could represent the "no path"
situation with [] -- which might be a bogus idea. Another option
is to have ["foo" &] not match "/foo" at all, which would resolve
the ambiguity afterwards.

What is your take on this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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