|
|
| Author |
Message |
< Erlyweb mailing list ~ bug: annoying double slash in function a/? when app root is |
| Guest |
Posted: Tue Aug 05, 2008 12:44 pm |
|
|
|
Guest
|
I have come to the conclusion that removing the trailing slash from
the app root is actually not a good idea. So please disregard what I
said earlier about removing it.
Although, my earlier comments about bugs arising in components with a
magic components with regard to its approot being set to "/" are still
valid. So if anyone has any sugestions, please reply.
I have serious doubts whether my suggested replacement for
get_app_root would be better.
Since the reversal would incur a memory O(M + N + (M - N))-penalty.
Yariv's would result in O(M-N) penalty... if I recall correctly how
the function works, my function is easier on the eyes though. Since I
don't know how the vm handles memory for stuff like this, a profiler
could be handy.
get_app_root (A) ->
ServerPath = yaws_arg:server_path(A)
, AppModData = yaws_arg:appmoddata(A)
, lists:reverse(lists:reverse(ServerPath) --
lists:reverse(AppModData)).
vs.
get_app_root(A) -
>
ServerPath =
yaws_arg:server_path(A),
L1 =
length(ServerPath),
L2 =
length(yaws_arg:appmoddata(A)),
if L2 > L1 ->
"/";
true ->
{First, _Rest} =
lists:split(
length(ServerPath) - length(yaws_arg:appmoddata(A)),
ServerPath),
First
end.
Since the resulting value of both functions is not likely to change
per app in run-time. This should be a constant.
On Aug 4, 12:42 am, Buggaboo <buggas...@gmail.com> wrote:
> Haha, the output should also be reversed .
>
> On Aug 4, 12:40 am, Buggaboo <buggas...@gmail.com> wrote:
>
> > Hi,
>
> > My get_app_root patch could be simplified if one doesn't use the
> > lists:split/? function.
>
> > Just do this:
>
> > get_app_root (A) ->
> > ServerPath = yaws_arg:server_path(A)
> > , AppModData = yaws_arg:appmoddata(A)
> > , ServerPath -- AppModData.
>
> > This has a major problem.
>
> > Suppose the approot contains the string "abcd". Suppose there's a
> > component also called "abcd".
>
> > "/abcdtest/abcd" -- "abcd". Guess which one gets removed. The intended
> > effect is to remove the 2nd instance of "abcd" from left to right.
>
> > One could reverse both appmoddata and server_path, then subtract the
> > reversed appmoddata from the server_path. That would solve the
> > abovementioned problem. I think it could be cheaper and easier than
> > the present solution provided by Yariv.
>
> > get_app_root (A) ->
> > ServerPath = yaws_arg:server_path(A)
> > , AppModData = yaws_arg:appmoddata(A)
> > , lists:reverse(ServerPath) -- lists:reverse(AppModData).
>
> > The cheapest solution would be to store this value somewhere
> > permanently... magically, like the magic model and magic controller.
> > Yariv what do you think?
>
> > For instance:
>
> > erlyweb_<project>:get_constant()... like app_root, app_name etc.
>
> > Compute constants only once.
>
> > Bye.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---
Post received from mailinglist |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|