Jump to content

Check number in a list (singular or plural )


Recommended Posts

Posted

Hello .

 

How could I check the return number in a list ( singular or plural) ?

 

(setq Nums '(1 2 3 4 5 6))
(setq List1 (nth 0 Nums))

 

Thanks

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • Michaels

    9

  • pBe

    6

  • dbroada

    2

  • MSasu

    2

Popular Days

Top Posters In This Topic

Posted (edited)
Hello .

 

How could I check the return number in a list ( singular or plural) ?

 

 

Thanks

 

has this been asked before ?

 

use REM

 

http://www.cadtutor.net/forum/showthread.php?58679-how-CAD-knows-a-number-is-singular-or-plural

 

You can though parse the list to remove Odd/Even

 

(defun OddEven (OE lst)
  (setq New_list                   
                (vl-remove-if-not '(lambda (i) (= (rem i 2) oe)) lst))
         )

 

1 for odd

0 for even

 

(oddeven 1 nums)

(1 3 5)

(oddeven 0 nums)

(2 4 6)

Edited by pBe
Posted

Thank you pBe .

 

But that's not what I meant buddy .

 

I mean how to know if the return number is singular or plural ?

 

1 is singular . but how to check by lisp ?

4 is plural . how to get sure of that ?

 

Many thanks .

Posted

so i see...

 

(post updated).. you are pertaining to ODD/EVEN?

Posted

The return of your sub-routine would give numbers in a list which is not what I looking for .:(

 

I would like to get sure if a number is singular which is hold by argument .

 

Thanks

Posted

This is an issue that was discussed few hours ago - did you checked the link that pBe suggested?

 

Regards,

Mircea

Posted
This is an issue that was discussed few hours ago - did you checked the link that pBe suggested?

 

Regards,

Mircea

 

I have seen that link before, and it does not meet my needs . :)

 

Many thanks .

Posted

of course it does..

 

like this

 
(defun c:Test ()
  (setq Nums '(1 2 3 4 5 6))
  (foreach n nums
          (if (= (rem n 2) 1)
                  (print (strcat (itoa n )" is Odd"));<--put your code here if its Odd
    (print (strcat (itoa n) " is Even"));<--put your code here if its Even
                 )
         )
 (princ)
 )

 

You need to supply the argument yourself as we dont know what exactly you want done with the result

Posted

Am I still not clear . :o

 

(setq num (getint "\n Number :")) ;;; Enter 3

 

so now the argument (num) is equal to 3 . so how to know the number which is held

by the argument is singular or plural ?

Posted

If you don't mean odd by "singular", respectively even by "plural", you should provide more information regarding your request. Thank you.

 

Regards,

Mircea

Posted

singular = 1

Plural = every number but 1 perhaps?

Posted
singular = 1

Plural = every number but 1 perhaps?

I'm glad I'm not the only one who reads it that way.
Posted
Am I still not clear . :o

 

(setq num (getint "\n Number :")) ;;; Enter 3

 

so now the argument (num) is equal to 3 . so how to know the number which is held

by the argument is singular or plural ?

 

 

 
(defun c:test ()
(setq num (getint "\n Number: "))
(if (= (rem num 2) 1)
  (princ "\nYou Entered Odd number:")
(princ "\nYou Entered Even number:")
 )(princ)
)

 

??????????

 

(defun c:test ()
(setq num (getint "\n Number: "))
(if (> num 1)
  (princ "\nYou Entered a higher number than 1")
(princ "\nYou Entered Number 1")
 )(princ)
)

 

??????????

 

(defun c:test ()
(setq num (getint "\n Number: "))
(if (< num 9)
  (princ "\nYou Entered Singular")
(princ "\nYou Entered Plural")
 )(princ)
)

 

???????????

 

Enough!! Enough!!! :lol:

Posted

Fantastic pBe .

 

That's it . Appreciated a lot buddy.

Posted
Fantastic pBe .

 

That's it . Appreciated a lot buddy.

 

for which one? :unsure:

 

:)

Posted
for which one? :unsure:

 

:)

 

All of them are perfect buddy .:lol:

Posted

and we are none the wiser to what a plural number is

Posted
and we are none the wiser to what a plural number is

 

I am sorry , I should have written "even" instead of "plural" which made the confusion .:oops:

 

I appologize .

Posted
I am sorry , I should have written "even" instead of "plural" which made the confusion .:oops:

 

I appologize .

 

No worries.. we had fun :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...