; From: Dat Thuc Nguyen
; Newsgroups: comp.protocols.kermit.misc
; Subject: LISP-Like Operations in Kermit
; Date: Wed, 24 May 2000 23:18:01 EDT
; URL: http://www.smalltickle.com
; 
; SIMPLE MATH
;
; The following macros mimic LISP syntax for some basic math operations
; in C-Kermit.  They save typing and make code readable a`la LISP.
;
; Usage Examples:
;
; C-Kermit> = VAR1 0            ; define VAR1 and assign it the value 0
; C-Kermit> += VAR1 3           ; equivalent VAR1 += 3 in C
; C-Kermit> = VAR2 4            ; define VAR2 and assign it the value 4
; C-Kermit> -= VAR2 2           ; equivalent VAR2 -= 2 in C
; C-Kermit> *= VAR1 VAR2        ; equivalent VAR1 *= VAR2 in C
; C-Kermit> /= VAR1 2           ; equivalent VAR1 /= 2 in C
; C-Kermit> * VAR1 9            ; equivalent VAR1 * 9 in C
; C-Kermit> / VAR1 VAR2         ; equivalent VAR1 / VAR2 in C

def - {
        local \%t
        if numeric \%2 assign \%t \%2
        else assign \%t \m(\%2)
        eval \%t \m(\%1) - \%t
        echo \%t
}

def + {
        local \%t
        if numeric \%2 assign \%t \%2
        else assign \%t \m(\%2)
        eval \%t \m(\%1) + \%t
        echo \%t
}

def = {
        local \%t
        if numeric \%2 assign \%t \%2
        else assign \%t \m(\%2)
        _assign \%1 \%t
        echo \m(\%1)
}

def += {
        local \%t
        if numeric \%2 assign \%t \%2
        else assign \%t \m(\%2)
        _eval \%1 \m(\%1) + \%t
        echo \m(\%1)
}

def -= {
        local \%t
        if numeric \%2 assign \%t \%2
        else assign \%t \m(\%2)
        _eval \%1 \m(\%1) - \%t
        echo \m(\%1)
}

def *= {
        local \%t
        if numeric \%2 assign \%t \%2
        else assign \%t \m(\%2)
        _eval \%1 \m(\%1) * \%t
        echo \m(\%1)
}

def /= {
        local \%t
        if numeric \%2 assign \%t \%2
        else assign \%t \m(\%2)
        _eval \%1 \m(\%1) / \%t
        echo \m(\%1)
}

def * {
        local \%t
        if numeric \%2 assign \%t \%2
        else assign \%t \m(\%2)
        eval \%t \m(\%1) * \%t
        echo \%t
}

def / {
        local \%t
        if numeric \%2 assign \%t \%2
        else assign \%t \m(\%2)
        _eval \%1 \m(\%1) / \%t
        echo \%t
}

; End
