Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructuring ambiguity after & #2

Open
mva opened this issue Jan 2, 2011 · 1 comment
Open

Destructuring ambiguity after & #2

mva opened this issue Jan 2, 2011 · 1 comment

Comments

@mva
Copy link

mva commented Jan 2, 2011

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?

@cgrand
Copy link
Owner

cgrand commented Feb 15, 2011

Good catch! I'll have to rework this. Originally & was meant to support nesting apps. So I may make ["foo" &] not match "foo".

Actually ["foo" &] and ["foo" & etc] does different things (the second form is not considered nesting) so I may decide that ["foo" & etc] can also match "/foo". However it's not very regular.

I'll have to ponder this and how this relate with the ring disussion on context/path handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants