You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Derek Baum (JIRA)" <ji...@apache.org> on 2009/08/18 09:35:14 UTC

[jira] Created: (FELIX-1493) [gogo] automatic expansion of $args in Closure stops direct access to $args list

[gogo] automatic expansion of $args in Closure stops direct access to $args list
--------------------------------------------------------------------------------

                 Key: FELIX-1493
                 URL: https://issues.apache.org/jira/browse/FELIX-1493
             Project: Felix
          Issue Type: Bug
          Components: Gogo
            Reporter: Derek Baum


individual arguments to Closures can be accessed as $0, $1, $2
all arguments can be accessed as the List $args.

> x = { echo hello $args }
> x a b

used to produce:
hello [a b]

because the $args List was passed directly as a single argument to echo.

This is not desirable in most cases, so the parser was changed to expand $args in Closures by expanding the $args List,
thus producing:

hello a b

Unfortunately, this also broke the ability for a closure to access the $args list directly:

% loop = { each $args { echo arg is $it }}
% loop a b
IllegalArgumentException: Cannot coerce each[1, 2, 3, org.apache.felix.gogo.runtime.shell.Closure@b1deea] to any of [(CommandSession, Collection, Function)]

A simple fix would be to introduce an alternative Closure variable name e.g. argv that is NOT expanded, but remains as a list:

% loop = { each $argv { echo arg is $it }}
% loop a b
arg is a
arg is b








-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (FELIX-1493) [gogo] automatic expansion of $args in Closure stops direct access to $args list

Posted by "Derek Baum (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-1493?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Derek Baum reassigned FELIX-1493:
---------------------------------

    Assignee: Derek Baum

> [gogo] automatic expansion of $args in Closure stops direct access to $args list
> --------------------------------------------------------------------------------
>
>                 Key: FELIX-1493
>                 URL: https://issues.apache.org/jira/browse/FELIX-1493
>             Project: Felix
>          Issue Type: Bug
>          Components: Gogo
>            Reporter: Derek Baum
>            Assignee: Derek Baum
>
> individual arguments to Closures can be accessed as $0, $1, $2
> all arguments can be accessed as the List $args.
> > x = { echo hello $args }
> > x a b
> used to produce:
> hello [a b]
> because the $args List was passed directly as a single argument to echo.
> This is not desirable in most cases, so the parser was changed to expand $args in Closures by expanding the $args List,
> thus producing:
> hello a b
> Unfortunately, this also broke the ability for a closure to access the $args list directly:
> % loop = { each $args { echo arg is $it }}
> % loop a b
> IllegalArgumentException: Cannot coerce each[1, 2, 3, org.apache.felix.gogo.runtime.shell.Closure@b1deea] to any of [(CommandSession, Collection, Function)]
> A simple fix would be to introduce an alternative Closure variable name e.g. argv that is NOT expanded, but remains as a list:
> % loop = { each $argv { echo arg is $it }}
> % loop a b
> arg is a
> arg is b

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (FELIX-1493) [gogo] automatic expansion of $args in Closure stops direct access to $args list

Posted by "Derek Baum (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-1493?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Derek Baum resolved FELIX-1493.
-------------------------------

    Resolution: Fixed

I have added $argv which is always a non-null List and is not expanded specially like $args.

for example

x = {
   shift = ($argv remove 0)
   echo arg1=$shift rest=$args
}

% x 1 2 3
arg1=1 rest=2 3

> [gogo] automatic expansion of $args in Closure stops direct access to $args list
> --------------------------------------------------------------------------------
>
>                 Key: FELIX-1493
>                 URL: https://issues.apache.org/jira/browse/FELIX-1493
>             Project: Felix
>          Issue Type: Bug
>          Components: Gogo
>            Reporter: Derek Baum
>            Assignee: Derek Baum
>
> individual arguments to Closures can be accessed as $0, $1, $2
> all arguments can be accessed as the List $args.
> > x = { echo hello $args }
> > x a b
> used to produce:
> hello [a b]
> because the $args List was passed directly as a single argument to echo.
> This is not desirable in most cases, so the parser was changed to expand $args in Closures by expanding the $args List,
> thus producing:
> hello a b
> Unfortunately, this also broke the ability for a closure to access the $args list directly:
> % loop = { each $args { echo arg is $it }}
> % loop a b
> IllegalArgumentException: Cannot coerce each[1, 2, 3, org.apache.felix.gogo.runtime.shell.Closure@b1deea] to any of [(CommandSession, Collection, Function)]
> A simple fix would be to introduce an alternative Closure variable name e.g. argv that is NOT expanded, but remains as a list:
> % loop = { each $argv { echo arg is $it }}
> % loop a b
> arg is a
> arg is b

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (FELIX-1493) [gogo] automatic expansion of $args in Closure stops direct access to $args list

Posted by "Derek Baum (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-1493?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Derek Baum updated FELIX-1493:
------------------------------

    Fix Version/s: gogo-0.6.0

> [gogo] automatic expansion of $args in Closure stops direct access to $args list
> --------------------------------------------------------------------------------
>
>                 Key: FELIX-1493
>                 URL: https://issues.apache.org/jira/browse/FELIX-1493
>             Project: Felix
>          Issue Type: Bug
>          Components: Gogo
>            Reporter: Derek Baum
>            Assignee: Derek Baum
>             Fix For: gogo-0.6.0
>
>
> individual arguments to Closures can be accessed as $0, $1, $2
> all arguments can be accessed as the List $args.
> > x = { echo hello $args }
> > x a b
> used to produce:
> hello [a b]
> because the $args List was passed directly as a single argument to echo.
> This is not desirable in most cases, so the parser was changed to expand $args in Closures by expanding the $args List,
> thus producing:
> hello a b
> Unfortunately, this also broke the ability for a closure to access the $args list directly:
> % loop = { each $args { echo arg is $it }}
> % loop a b
> IllegalArgumentException: Cannot coerce each[1, 2, 3, org.apache.felix.gogo.runtime.shell.Closure@b1deea] to any of [(CommandSession, Collection, Function)]
> A simple fix would be to introduce an alternative Closure variable name e.g. argv that is NOT expanded, but remains as a list:
> % loop = { each $argv { echo arg is $it }}
> % loop a b
> arg is a
> arg is b

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.