×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Lisp - convert numbers to evens

Lisp - convert numbers to evens

Lisp - convert numbers to evens

(OP)
Hi,
Can anyone tell me how to convert odd numbers in to even numbers in LISP?
I have a lisp routine which returns both even and odd numbers (0,1,2,3 up to 9) and I need to return and function that will round the figure down to the nearest even number, e.g.: 1 to 0, 3 to 2 etc.

Can anyone help?
Thanks in advance for any help
Dan

RE: Lisp - convert numbers to evens

(* (fix (/ NUMBER 2)) 2)

"Whether you think that you can, or that you can't, you are usually right "
.. Henry Ford

RE: Lisp - convert numbers to evens

(OP)
HI borgunit,

I am getting an error:
; error: bad argument type: numberp:

I have been tring it as follows,

(XSTR (fix (/ XSTR 2)) 2)

I am tring to overwrite "XSTR" which is either odd or even, with a new "XSTR" value which is only even.
Can you tell me where I am going wrong.

RE: Lisp - convert numbers to evens

(setq XSTR (*(fix(/ XSTR 2)2))

"Whether you think that you can, or that you can't, you are usually right "
.. Henry Ford

RE: Lisp - convert numbers to evens

Oops, I did not look at your error closely. It looks like you are trying to do mathematical computation on a string and not a number. atof convert the string to a floating number.
Try this..

(setq XSTR (atof XSTR))
(setq XSTR (*(fix(/ XSTR 2))2))

"Whether you think that you can, or that you can't, you are usually right "
.. Henry Ford

RE: Lisp - convert numbers to evens

(OP)
hi borgunit,
It know works, it was a string!
Thanks for the help.
Dan

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources