Sujet : Re: Command Languages Versus Programming Languages
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.miscDate : 03. Apr 2024, 02:23:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uui7hf$3gona$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
On 2 Apr 2024 08:26:14 GMT, Stefan Ram wrote:
ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
>
def diff( x ):
return 1 if x == 'x' else 0 if type( x )is str else[ 'sum', diff( x[
1 ]), diff( x[ 2 ])]
if x[ 0 ]== 'sum' else None
Oops! That was one long line starting with "return";
it was wrapped by the newsreader, but is not correct Python anymore
when wrapped this way.
It’s bloody horrible Python even when wrapped correctly. I think Python’s
version of the conditional expression is a complete abortion.
How about this, to at least get things the same way round as in the more
usual C-style conditional expression:
def diff(x) :
return \
[
lambda :
[
lambda :
[
lambda : None,
lambda : ['sum', diff(x[1]), diff(x[2])],
][x[0] == 'sum'](),
lambda : 0,
][isinstance(x, str)](),
lambda : 1,
][x == 'x']()
#end diff