* Re: list operators
@ 1993-09-16 10:11 malte
0 siblings, 0 replies; 11+ messages in thread
From: malte @ 1993-09-16 10:11 UTC (permalink / raw)
To: rc
Thanks to all of you for your quick answers! But let my summarize and
the take the discussion a little further:
1) It is too late to introduce changes
It's not really a change since it doesn't change the semantics of existing,
valid scripts.
2) The syntax is bad
Yes !! Maybe its an alt.tasteless candidate.
3) A semantic improvement
I should have thought of that! Of course,
; x = ( 1 2 3 4 ) echo $x( -1 -3 )
2 4
is much better.
4) Why not use a function
Thanks to all who disclosed their solutions, but I already had some. I think,
there's more then one point of view to it:
Experienced rc users certainly don't have problems to write a function doing
the work, to put it in some kind of library and to reuse it on other occasions.
But the notion of "omit it if you can write a function" doesn't help novices
and - be honest to yourself - isn't it boring that you always have to source
some other file to include a function in your script ( . /some/file || exit )?
So it's speed and beauty vs usability. I'm still convinced my suggestions
enhance both.
Malte
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: list operators
@ 1993-09-17 17:32 Stefan Dalibor
0 siblings, 0 replies; 11+ messages in thread
From: Stefan Dalibor @ 1993-09-17 17:32 UTC (permalink / raw)
To: rc
Hi,
as it seems to be list-op wishing-time, here are my favourites:
1. Cartesian products of lists; it can of course be done with
functions (and I can live with that in scripts, though I don't like
it), but I use this *very* often as globbing construct and having
to type the rc equivalent of e.g.
what {{$O/bin,~/bin}/{sun*,m88k,ptx},src/{zrc,xvt}}/{zrc,rc,sysconf,xvt}
interactively can be extremely tedious.
IMHO it seems also a bit inconsequent to implement cartesian
products only for the case of 1 x n elements; I'd vote for
implementing the general n x m case which includes the former.
2. Assignment to list elements, e.g. `path(5)=/local/bin'. I think
there should be no need to use a function for such an atomic
operation.
Both items can be justified by (and will of course be rejected for) the
same reasons as the earlier proposals; I posted them yet because much
to my surprise, the absence of these constructs (and not the usual
like job-control, user-name-expansion, completion, builtins etc.) was
the reason that one of the few colleagues I was able to interest in rc
dropped it finally and keeps on using tcsh... so I think this can at
least be filed as a curiosity.
Bye,
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: list operators
@ 1993-09-15 21:04 Tom Culliton x2278
0 siblings, 0 replies; 11+ messages in thread
From: Tom Culliton x2278 @ 1993-09-15 21:04 UTC (permalink / raw)
To: culliton, mycroft; +Cc: malte, rc
>> ; x = ( 1 2 3 4 5 )
>> ; y = $x(-3) # all members except 3
>
>Having that be `all members except the 3rd one' would be okay. Having
>it be `all members except the one that matches the string `3'' would
>be gross. The latter requires a different syntax.
Agreed, that was my intention, to exclude the 3rd element.
; x=(a b c d e)
; echo $x(-1 -5)
b c d
It's probably/hopefully just academic anyways. We really shouldn't be
making changes like this to rc at this point in the game.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: list operators
@ 1993-09-15 20:47 Brynjulv Hauksson
0 siblings, 0 replies; 11+ messages in thread
From: Brynjulv Hauksson @ 1993-09-15 20:47 UTC (permalink / raw)
To: rc
When I started using rc I thought it lacked some list operators,
and eventually placed these definitions in my `.rcrc':
# vshift var [num] -- shift $var num (default 1) places
fn vshift {v = $1 n = $2 {* = $$v && shift $n && $v = $*}}
# vrev var -- reverse the list in $var
fn vrev {v = $1 d = () {* = $$v && for(i in $*){d = ($i $d)} && $v = $d}}
# vchop var [num] -- remove last num (default 1) elems of $var
fn vchop {v = $1 {vrev $v && vshift $v $2 && vrev $v}}
There are probably faster, more elegant and/or more robust ways of
doing it. I haven't worried much about it, since it turned out
that I almost never use these functions anyway :-)
- brynjulv
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: list operators
@ 1993-09-15 19:38 Tom Culliton x2278
1993-09-15 20:08 ` Charles Hannum
0 siblings, 1 reply; 11+ messages in thread
From: Tom Culliton x2278 @ 1993-09-15 19:38 UTC (permalink / raw)
To: malte, rc
I'm not much worried about these proposals because I just can't imagine
Byron incorporating them into the mainstream rc, but also just couldn't
resist making some comment on the second one.
> and dropping one element from a list:
>
> * = ( 1 2 3 4 )
> ; echo $*(-3)
> 3
> ; echo $*
> 1 2 4
>
> Malte
The proposed syntax is a REALLY BAD IDEA. Now something like:
; x = ( 1 2 3 4 5 )
; y = $x(-3) # all members except 3
; echo $x
1 2 3 4 5
; echo $y
1 2 4 5
might be reasonable, but having a reference to the list modify it (without
assignment) is really disgustingly bad taste.
Tom
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: list operators
@ 1993-09-15 19:01 rsalz
0 siblings, 0 replies; 11+ messages in thread
From: rsalz @ 1993-09-15 19:01 UTC (permalink / raw)
To: rc-owner, rc
; * = ( 4 5 6 7 )
; echo $*
4 5 6 7
; shift -3
; echo $*
4
# rshift varname count
fn rshift { i=() save=() tmp=() {
count=`{ expr $#$1 - $2 }
~ $count -* && { echo cannot rshift >[1=2]; return 1 }
save=$1
*=( $$1 )
for (i) {
tmp=( $tmp $i )
~ $#tmp $count && break
}
$save=( $tmp )
} }
rn rshift-test {
foo=(1 2 3 4 5 6)
echo foo before is $foo
rshift foo 2
echo foo after is $foo
echo
echo foo before is $foo
rshift foo 12 || echo rshift failed.
echo foo after is $foo
}
foo before is 1 2 3 4 5 6
foo after is 1 2 3 4
foo before is 1 2 3 4
cannot rshift
rshift failed.
foo after is 1 2 3 4
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: list operators
@ 1993-09-15 18:29 Byron Rakitzis
0 siblings, 0 replies; 11+ messages in thread
From: Byron Rakitzis @ 1993-09-15 18:29 UTC (permalink / raw)
To: malte, rc
>What I really do miss in rc is orthogonality in list operators.
> There's a left shift "shift [n]", but no right shift.
Hm. I think you could make the same argument about lisp. There
is no way to shift right, other than by applying rev, cdr, rev.
What is wrong with defining a function in rc to do this for
you?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: list operators
@ 1993-09-15 18:28 malte
0 siblings, 0 replies; 11+ messages in thread
From: malte @ 1993-09-15 18:28 UTC (permalink / raw)
To: rc
Sorry, but what I mean is
(left) shift
; * = ( 1 2 )
; echo $*
1 2
; shift
; echo $*
2
; shift
; echo $*
; shift
cannot shift
right shift
; * = ( 4 5 6 7 )
; echo $*
4 5 6 7
; shift -3
; echo $*
4
and dropping one element from a list:
* = ( 1 2 3 4 )
; echo $*(-3)
3
; echo $*
1 2 4
Malte
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: list operators
@ 1993-09-15 18:07 rsalz
0 siblings, 0 replies; 11+ messages in thread
From: rsalz @ 1993-09-15 18:07 UTC (permalink / raw)
To: rc-owner, rc
Err, what's wrong with
foo=('' $foo)
to implement right shift?
^ permalink raw reply [flat|nested] 11+ messages in thread
* list operators
@ 1993-09-15 17:55 malte
0 siblings, 0 replies; 11+ messages in thread
From: malte @ 1993-09-15 17:55 UTC (permalink / raw)
To: rc
Just because there's some life sign on this list again:
What I really do miss in rc is orthogonality in list operators.
There's a left shift "shift [n]", but no right shift.
I'd like to propose negative shift values to implement this.
There's a simple way to pick some element from a list, but not
to drop one. Maybe we could use negative numbers for that too, e.g.
droppping the fifth element from a list reads "$x(-5)". Then, the
solution to the annoying problem of dropping the last element from
a list is "last = $x(-$#x)"
What do you think of this?
Will it break scripts ( besides already broken ones )?
Malte
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~1993-09-17 17:33 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-09-16 10:11 list operators malte
-- strict thread matches above, loose matches on Subject: below --
1993-09-17 17:32 Stefan Dalibor
1993-09-15 21:04 Tom Culliton x2278
1993-09-15 20:47 Brynjulv Hauksson
1993-09-15 19:38 Tom Culliton x2278
1993-09-15 20:08 ` Charles Hannum
1993-09-15 19:01 rsalz
1993-09-15 18:29 Byron Rakitzis
1993-09-15 18:28 malte
1993-09-15 18:07 rsalz
1993-09-15 17:55 malte
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).