Sujet : Re: Command Languages Versus Programming Languages
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.miscDate : 02. Apr 2024, 17:33:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240402092331.115@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-04-02, Stefan Ram <
ram@zedat.fu-berlin.de> wrote:
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
n TXR Lisp:
(defun-match dif
((sum @left @right) ^(sum ,(dif left) ,(dif right)))
((@op . @args) (error "~s: unrecognized operator: ~s" 'dif op))
(x 1)
(@else 0))
diff is a built in, which we don't want to be redefining without
an exceptionally good reason, so I changed to dif.
If we compile 'dif we get unused variable warnings:
2> (compile 'dif)
** expr-1:1: warning: let*: variable args unused
** expr-1:1: warning: let*: variable else unused
#<vm fun: 0 param + 3 optional + variadic>
To suppress that, we use @nil instead of @args or @else; @nil is a
placeholder pattern that matches any object without binding a variable.
Otherwise we need more verbiage:
((@op . @args) (ignore args) (error ....))
...
(@else (ignore else) 0)
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca