On 5/11/06, Philip Ganchev <[EMAIL PROTECTED]> wrote:
On 5/10/06, Axel Liljencrantz <[EMAIL PROTECTED]> wrote:
> On 5/10/06, Philip Ganchev <[EMAIL PROTECTED]> wrote:
> >     foo(seq 1 2)
> >
[...] make the above behave instead as a concatenation of
> > the strings "foo" and "1 2", namely
> >
> >     foo1 2
> >
> > Then "foo1 foo2" can be achieved as

By the way, I think this is called "string multiplication".

> >     foo{"",(seq 1 2)}
> >
>
> Wouldn't that result in the elements foo' and 'foo1 2'.

Yes, it would - my bad.  You would need to write

    foo{(seq 1 2)|sed -r 's/\n/,/g; s/,$//'}

(This is one reason why it makes sense to use spaces as a separator
inside {}; you would just write "foo{seq 1 2)}".  In general, it makes
sense to use the same separators everywhere, so that the output of one
command can be fed as input to another.)

My reasoning is that when two strings are adjacent, people expect that
they will be concatenated, not multiplied.  And this should work the
same for strings written explicitly (as in "echo foo'1 2'"), as for
results of a command (as in "echo foo(seq 2)").

Moreover, multiplication is less commonly needed, and so should be
done explicitly using { }.  I think in the current scheme, there is no
way to concatenate explicitly.

Lastly, with this small change to the expansion semantics, there are
no corner cases like "foo[1 (seq 4 6)]" and no change is needed to the
"set" command.


My previous message was lacking in the examples-department. Some
situations where multiplication is nice and concatenation isn't:

# Loop over all users
for i in (cat /etc/passwd); ...; end

# Remove a sequence of files
rm img(seq 4 39).jpg

# Print information about select files
ll (find . -type ...)

> [...] I see many
> problems with the second suggestion:
>
> * Posix-incompatible

Sorry, how is it POSIX-incompatible?  Both Sh and Bash work

Bash uses a mix of concatenation and multiplication. I think that it
gets all non-trivial cases wrong, but at least some things are not
concatenated in bash:

for i in $(cat /etc/passwd); do echo $i lalala; done


> * Rarely what you want. Array separating on newline if often useful,
> at least in my experience.

Sorry, how does newline come into it?

I was unclear: Command substitution in fish uses newlines as the list
element separator. Bash uses IFS, I belive. Maybe fish should also use
IFS here for consistency?


I think the splicing example that started this discussion shows that
string concatenation is more often what you want than string
multiplication.  Where is string multiplicatio needed?

See above.


> At a glance, I agree that it would be nicer to make 'set foo[ 1 (seq 4
> 7)] a b c d' do what you'd expect, but firstly I don't see how that is
> possible without breaking something more fundamental,

Namely what?

See above.


> and secondly
> once you get used to the idea that array slicing piggybacks on regular
> parameter expansion - no special treatment - then it seems pretty
> intuitive. At least to me. It comes back to having a small
> multipurpose syntax.

Certainly, my proposal is in completely in line with that.  It is also
more consistent with user expectations, and easier to read, as string
multiplication would be explicit.

So our main disagreement is whether multiplicative behaviour is
desirable in parameter substitution or not. How would you rewrite some
of my above examples without multiplicate command substitution?

--
Axel


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to