Name: Anonymous 2010-11-05 16:50
if(foo == 0)
foo = 44;
else
foo = 0;How do I change that into a single line that does the trick using arithmetic?
if(foo == 0)
foo = 44;
else
foo = 0;foo = foo == a ? b : c;==foo and 44
(module toggle-example ()
(import chicken scheme)
(use extras miscmacros srfi-69)
(define (toggle left right)
(lambda (x)
(select x
((left) right)
((right) left)
(else (error "toggle" left right x)))))
(define s (toggle 44 0))
(define x 44)
(printf "x before: ~a~n" x)
(modify! x s)
(printf "x after: ~a~n" x)
(define v (vector 0 1 2 3))
(printf "v before: ~a~n" v)
(modify! (vector-ref v 0) s)
(printf "v after: ~a~n" v)
(define l (list 0 1))
(printf "l before: ~a~n" l)
(modify! (car l) s)
(printf "l after: ~a~n" l)
(define h (alist->hash-table '((key . 0))))
(printf "h before: ~a~n" (hash-table->alist h))
(modify! (hash-table-ref h 'key) s)
(printf "h after: ~a~n" (hash-table->alist h))
)