Groups | Search | Server Info | Login | Register


Groups > comp.unix.shell > #24899

Re: Command Languages Versus Programming Languages

From ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups comp.unix.shell, comp.unix.programmer, comp.lang.misc
Subject Re: Command Languages Versus Programming Languages
Date 2024-04-02 08:18 +0000
Organization Stefan Ram
Message-ID <LISP-20240402091729@ram.dialup.fu-berlin.de> (permalink)
References (9 earlier) <uudrfg$2cskm$1@dont-email.me> <87r0fp8lab.fsf@tudado.org> <uuehdj$2hshe$1@dont-email.me> <87wmpg7gpg.fsf@tudado.org> <LISP-20240402085115@ram.dialup.fu-berlin.de>

Cross-posted to 3 groups.

Show all headers | View raw


ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
>( SETQ DIFF
>  ( LAMBDA( X )
>    ( COND
>      ( ( ATOMP X )
>        ( COND
>          ( ( = X 'X )
>            1 )
>          ( T
>            0 )))
>      ( T
>        ( COND
>          ( ( =( CAR X )'SUM )
>            ( LIST 'SUM( DIFF( CADR X ))( DIFF( CADDR X )))))))))

  In Python:

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

  . An attempt at indentation:

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

  . In a multiple-returns style:

def diff( x ):
    if type( x )is str:
        if x == 'x':
            return 1
        else:
            return 0
    else:
        if x[ 0 ]== 'sum':
            return [ 'sum', diff( x[ 1 ]), diff( x[ 2 ])]

  .

Back to comp.unix.shell | Previous | Next | Find similar


csiph-web