scsh-users
[Top] [All Lists]

Re: idiomatic use of &&

To: scsh@zurich.ai.mit.edu, clements@ccs.neu.edu (John B. Clements)
Subject: Re: idiomatic use of &&
From: sperber@informatik.uni-tuebingen.de (Michael Sperber [Mr. Preprocessor])
Date: Thu, 12 Jun 2003 21:51:59 +0200
>>>>> "John" == John B Clements <clements@ccs.neu.edu> writes:

John> How do I change it so that any error halts the whole string?  
John> Here's my solution, but it seems like there must be a more
John> idiomatic way of doing this:

>> (define (propagate-error x) (if x #t (error 'sub-error)))
>> (&& (begin (propagate-error (&& (rm nonexistentfile) 
John>                                   (echo aaaa)))) 
John>       (echo bbb))
John> rm: nonexistentfile: No such file or directory

John> Error: sub-error
John> #f
>> 

John> This would seem like a common problem.  

I think your solution is OK; while I've never used && in a script of
mine, I find myself writing code similar to yours.

John> Also, it's a pain to abstract over &&, because it's a macro.

Yes.  The shell subsystem design is fucked.  It'll get completely
replaced in post-0.6 scsh.  In particular, there'll be a
compositional, value-level algebra for the things which are currently
process forms, so a lot of those macros will go away, and they'll
mostly be syntactic sugar over procedural equivalents.  (Which they
aren't now.)

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

<Prev in Thread] Current Thread [Next in Thread>