rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: set subtract
       [not found] <cks@hawkwind.utcs.toronto.edu>
@ 1992-11-04 12:45 ` malte
  1992-11-06 12:03 ` rc and signal handlers malte
  1 sibling, 0 replies; 6+ messages in thread
From: malte @ 1992-11-04 12:45 UTC (permalink / raw)
  To: rc

	
	 The problem with a set-subtract function is that it will loose quoting
	information if it's used as 'foo `{set-sub ....}', and you thus need to
	have it passed variable names to work on. But then you can't just use
	this on a command line; you have to build lists beforehand. About
	half the time I'd like to use this is on command lines, so I keep
	wishing for a better solution.
	
		- cks

Applause, applause!

I'd vote for making such a function built into rc to avoid meta character
trouble, the way the ~ operator does it.
A related builtin I always wanted to have:

	idx = `{ index list_of_patterns list_to_search_in }

This should return a list of indices of the search patterns in the second list.

	; echo `{ index a ( a b c a ) }
	1 4
	;

Malte



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rc and signal handlers
       [not found] <cks@hawkwind.utcs.toronto.edu>
  1992-11-04 12:45 ` set subtract malte
@ 1992-11-06 12:03 ` malte
  1 sibling, 0 replies; 6+ messages in thread
From: malte @ 1992-11-06 12:03 UTC (permalink / raw)
  To: rc

	
	| Also, the man-page is not too clear about signals:
	|  "Only signals that are being ignored are passed on to programs run by rc"
	| The should read "signals that are being caught", I guess.
	
	 The manpage is correct as written; caught signals are not passed on to
	children, and revert to default behavior. Only ignored signals are passed
	on to children.
	
	 If one thinks about how catching signals works, it becomes obvious that
	this has to be that way.
	
		- cks

This is perfectly true! But also ugly ! This way, one has to redefine signal
handlers for each backquote substitution. On BSD and System V children
inherit signal handlers when forking and one has to change them explicitly.
Could someone explain to me why rc does it automatically ? I'd rather prefer
a simple way to reset signal handlers, something like

	fn sigreset {
		for( sig in `{ whatis -s | cut -f2 '-d ' } )
			eval fn $sig
	}

About "return"ing from a signal handler: One really doesn't want to do that.
I just mentioned it to make it clear to beginners. What bothers me most is
that rc doesn't complain about a return when defining the function and that
everything is fine when invoking the function interactively. But, when the
signal is caught, you'll get "return outside of function".

Malte



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: set subtract
@ 1992-11-04 14:25 malte
  0 siblings, 0 replies; 6+ messages in thread
From: malte @ 1992-11-04 14:25 UTC (permalink / raw)
  To: rc


	Easy; the following just uses built-ins.  Note that it implements
	the example (first arg is a pattern, not a list of patterns); I don't
	believe the synopsis can be done.
	fn index { pat=() i=() result=() count=() {
	    pat=$1
	    shift || { echo 'Usage error' >[1=2] ; return 1 }
	    for (i) {
	        count=(a $count)
	        eval ~ $i $pat && result=($result $#count)
	    }
	    echo $result
	} }

Fine, this is similar to what I do now. Why a built in command ?
Imagine $pat has a value of '$something'. This will break it.

Malte



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: set subtract
@ 1992-11-04 14:12 rsalz
  0 siblings, 0 replies; 6+ messages in thread
From: rsalz @ 1992-11-04 14:12 UTC (permalink / raw)
  To: malte, rc

>A related builtin I always wanted to have:
>        idx = `{ index list_of_patterns list_to_search_in }
>This should return a list of indices of the search patterns in the second list.
>        ; echo `{ index a ( a b c a ) }
>        1 4
Easy; the following just uses built-ins.  Note that it implements
the example (first arg is a pattern, not a list of patterns); I don't
believe the synopsis can be done.
fn index { pat=() i=() result=() count=() {
    pat=$1
    shift || { echo 'Usage error' >[1=2] ; return 1 }
    for (i) {
        count=(a $count)
        eval ~ $i $pat && result=($result $#count)
    }
    echo $result
} }


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: set subtract
  1992-11-03 23:44 Byron Rakitzis
@ 1992-11-04  0:42 ` Chris Siebenmann
  0 siblings, 0 replies; 6+ messages in thread
From: Chris Siebenmann @ 1992-11-04  0:42 UTC (permalink / raw)
  To: rc

 The problem with a set-subtract function is that it will loose quoting
information if it's used as 'foo `{set-sub ....}', and you thus need to
have it passed variable names to work on. But then you can't just use
this on a command line; you have to build lists beforehand. About
half the time I'd like to use this is on command lines, so I keep
wishing for a better solution.

	- cks


^ permalink raw reply	[flat|nested] 6+ messages in thread

* set subtract
@ 1992-11-03 23:44 Byron Rakitzis
  1992-11-04  0:42 ` Chris Siebenmann
  0 siblings, 1 reply; 6+ messages in thread
From: Byron Rakitzis @ 1992-11-03 23:44 UTC (permalink / raw)
  To: rc

Given two lists a and b, it is possible to do set subtract
in rc with the ~ operator:

	for (i in $a)
		if (!~ $i $b)
			echo $i

So all that you need to do is write a function to build
these two lists based on the

	[a] - [b]

syntax suggested. Something like this:

	fn set-subtract {
		a=()
		while () {
			switch ($1) {
			case ()
				echo usage: $0 'foo - bar' >[1=2]
				return 1
			case -
				shift
				break
			case *
				a=($a $1)
				shift
			}
		}
		for (i in $a)
			if (!~ $i $*)
				echo $i
	}

(Btw, I would choose a shorter name than set-subtract. Sort of reminds
me of the regexp syntax that Nicklaus Wirth uses in his Oberon system.
I think it's straight BNF.  To say .* you have to write it as {~c}. Or
even worse, foo*bar becomes "fo"{"o"}"bar". Does he really use this
tool, or expect anyone else to? But I digress..)


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1992-11-06 12:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cks@hawkwind.utcs.toronto.edu>
1992-11-04 12:45 ` set subtract malte
1992-11-06 12:03 ` rc and signal handlers malte
1992-11-04 14:25 set subtract malte
  -- strict thread matches above, loose matches on Subject: below --
1992-11-04 14:12 rsalz
1992-11-03 23:44 Byron Rakitzis
1992-11-04  0:42 ` Chris Siebenmann

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).