From: ·······@cad.strath.ac.uk
Subject: Is there macro to display absolute constant?
Date:
Message-ID: <8v1407$k07$1@nnrp1.deja.com>
Hello,
I wrote a code for y = |1 - x| which contains absolute constant as below.
(if (< (setf y (- 1 x)) 0)
(setf y (- 0 y)) y)
It seems works.... but there maybe a built-in macro for an absolute constant?
Is there the macro for this purpose in common Lisp?
Thanks,
Sungwoo
Sent via Deja.com http://www.deja.com/
Before you buy.
From: Kent M Pitman
Subject: Re: Is there macro to display absolute constant?
Date:
Message-ID: <sfwhf57reqc.fsf@world.std.com>
·······@cad.strath.ac.uk writes:
> I wrote a code for y = |1 - x| which contains absolute constant as below.
>
> (if (< (setf y (- 1 x)) 0)
> (setf y (- 0 y)) y)
>
> It seems works.... but there maybe a built-in macro for an absolute constant?
> Is there the macro for this purpose in common Lisp?
I don't know what an absolute constant is, but I don't see why
(setq y (abs (- 1 x)))
doesn't do what you want. ABS is not a macro, it's a function.
But it's the right way to express absolute value.
From: ·······@cad.strath.ac.uk
Subject: Re: Is there macro to display absolute constant?
Date:
Message-ID: <8v19ns$p8k$1@nnrp1.deja.com>
In article <···············@world.std.com>,
Kent M Pitman <······@world.std.com> wrote:
> ·······@cad.strath.ac.uk writes:
>
> > I wrote a code for y = |1 - x| which contains absolute constant as below.
> >
> > (if (< (setf y (- 1 x)) 0)
> > (setf y (- 0 y)) y)
> >
> > It seems works.... but there maybe a built-in macro for an absolute constant?
> > Is there the macro for this purpose in common Lisp?
>
> I don't know what an absolute constant is, but I don't see why
>
> (setq y (abs (- 1 x)))
>
> doesn't do what you want. ABS is not a macro, it's a function.
> But it's the right way to express absolute value.
>
That is what I wanted. Thanks alot. =)
Sungwoo
Sent via Deja.com http://www.deja.com/
Before you buy.
From: Hannah Schroeter
Subject: Re: Is there macro to display absolute constant?
Date:
Message-ID: <8v17ea$vsb$1@c3po.schlund.de>
Hello!
In article <············@nnrp1.deja.com>, <·······@cad.strath.ac.uk> wrote:
>Hello,
>I wrote a code for y = |1 - x| which contains absolute constant as below.
>(if (< (setf y (- 1 x)) 0)
> (setf y (- 0 y)) y)
>It seems works.... but there maybe a built-in macro for an absolute constant?
>Is there the macro for this purpose in common Lisp?
>Thanks,
>Sungwoo
How about abs?
(setf y (abs (- 1 x)))
and if that were not in the standard, you had better written it
yourself instead of producing such not-so-easy to understand
special case code:
(defun abs (x) (if (< x 0) (- x) x))
Kind regards,
Hannah.
······@schlund.de (Hannah Schroeter) writes:
> (defun abs (x) (if (< x 0) (- x) x))
What about (abs #c(0 1))?
Too complex ? ;-)
- Wolfhard
From: Hannah Schroeter
Subject: Re: Is there macro to display absolute constant?
Date:
Message-ID: <8vjj6v$f20$1@c3po.schlund.de>
Hello!
In article <··············@buss-14250.user.cis.dfn.de>,
Wolfhard Bu� <·····@gmx.net> wrote:
>······@schlund.de (Hannah Schroeter) writes:
>> (defun abs (x) (if (< x 0) (- x) x))
>What about (abs #c(0 1))?
>Too complex ? ;-)
Seems so.
Perhaps better:
(defun poor-womans-abs (x)
(format *debug-io* "(POOR-WOMANS-ABS ~S) called, better use the real thing~%"
x)
(if (< x 0) (- x) x))
Kind regards :-)
Hannah.
From: Robert Monfera
Subject: Re: Is there macro to display absolute constant?
Date:
Message-ID: <3A1491D4.899064DF@fisec.com>
Hannah Schroeter wrote:
> if that were not in the standard, you had better written it
> yourself instead of producing such not-so-easy to understand
> special case code:
>
> (defun abs (x) (if (< x 0) (- x) x))
Or even
(defun abs2 (x) (* x (signum x)))
Robertr
From: John Clonts
Subject: Re: Is there macro to display absolute constant?
Date:
Message-ID: <3A142D10.320E@my-deja.com>
·······@cad.strath.ac.uk wrote:
>
> Hello,
>
> I wrote a code for y = |1 - x| which contains absolute constant as below.
>
> (if (< (setf y (- 1 x)) 0)
> (setf y (- 0 y)) y)
>
> It seems works.... but there maybe a built-in macro for an absolute constant?
> Is there the macro for this purpose in common Lisp?
I think what you want is abs
(setf y (abs (- 1 x)))
Cheers,
John