Author Topic: would you help me with wcmatch  (Read 5491 times)

0 Members and 1 Guest are viewing this topic.

Tramber

  • Guest
would you help me with wcmatch
« on: August 21, 2006, 09:25:31 AM »
There's a battle in my brain between some neurons  :x

I'd like to filter  kind of division of a length :

20.5,20.5,20.5 that can also be written 3x (the length of the object is 61.5).

How to filter with wcmatch so that nothing else can be written?

Code: [Select]
(wcmatch rValue2 "[0-9]*,*x") allows me to enter "a1x" which is not correct
The problem is simple but I'm a little lost 'cause I forgot how to write this code.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: would you help me with wcmatch
« Reply #1 on: August 21, 2006, 10:59:20 AM »
Not sure what you are asking but that didn't stop me from a quick concept offering --

Code: [Select]
(defun Foo ( / pmt result )
    (initget 128)
    (setq pmt "Enter x,y,z lengths or multiplier, eg 3x: ")
    (cond
        (   (listp (setq result (getpoint pmt)))
            result
        )
        (   (and
                (eq 'str (type result))
                (wcmatch result "#[Xx]")
            )
            result
        )   
        ;;  etc
    )
)

(foo) [Enter]
Enter x,y,z lengths or multiplier, eg 3x: 1,2,3 [Enter]
=> (1 2 3)

(foo) [Enter]
Enter x,y,z lengths or multiplier, eg 3x: 3x [Enter]
=> "3x"

(foo) [Enter]
Enter x,y,z lengths or multiplier, eg 3x: fubar [Enter]
=> nil

You can build up complex wcmatch string to achieve the same but the route above may offer more flexibility.

Or not.

Use | Abuse | Ignore.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Tramber

  • Guest
Re: would you help me with wcmatch
« Reply #2 on: August 21, 2006, 11:21:15 AM »
Does FUBAR mean F... Up Beyond All Recognation (in such case, I would consider that I'm not so bad at your language) ?
 :evil:

Let me be more explicit ('cause my explanations were very bad indeed) :

I want to authorize 0 to 9 and "," and "." (then I got routines to test if the synthax is correct)
or
an integer suffixed by a X i.e. (wcmatch result "*[Xx]")
« Last Edit: August 21, 2006, 11:22:20 AM by Call me Bert' »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: would you help me with wcmatch
« Reply #3 on: August 21, 2006, 11:28:04 AM »
Means whatever you want it to, just don't say it aloud. :)

I'm not convinced I understand you but play with this --

Code: [Select]
(defun IsOk ( x )
    (or (numberp x)
        (if (eq 'str (type x))
            (or
                (distof x)
                (wcmatch x "#[Xx]")
            )   
        )
    )   
)

The (distof x) bit can be more ambitious (there's a post somewhere herein if you search for it). Sorry I gotta get back to work.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Tramber

  • Guest
Re: would you help me with wcmatch
« Reply #4 on: August 21, 2006, 11:56:19 AM »
Nop !

It doesn't work.
How to exclude anything which is not a number, a "," or a "." ?

The other option would be (wcmatch x "*[Xx]"), I replaced the # by a *

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: would you help me with wcmatch
« Reply #5 on: August 21, 2006, 12:08:19 PM »
Hi Bert,

It' not very "elegant" :
Code: [Select]
(cond
  ((wcmatch rValue2 "[0-9]x"))
  (T
   (while (setq n (vl-string-search "," rValue2))
     (setq lst    (cons (read (substr rValue2 1 n)) lst)
   rValue2 (substr rValue2 (+ 2 n))
     )
   )
   (cons (read rValue2) lst)
   (vl-every 'numberp lst)
  )
)
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: would you help me with wcmatch
« Reply #6 on: August 21, 2006, 04:24:16 PM »
Re,

Another sismilar way.

Code: [Select]
(cond
  ((wcmatch rValue2 "*[Xx]"))
  (T
   (vl-every
     '(lambda (x)
(member x '(44 46 48 49 50 51 52 53 54 55 56 57))
      )
     (vl-string->list rValue2)
   )
  )
)
Speaking English as a French Frog

LE

  • Guest
Re: would you help me with wcmatch
« Reply #7 on: August 21, 2006, 04:43:37 PM »
Lately I just do mickey mouse lisp (and maybe in the past too).... anyway here is something, need more conditions.... HTH

Code: [Select]
;;(tst "x3x")
;;(tst "3x")
;;(tst "20.5,20.5,20.5x")
;;(tst "20.5,20.5,20.5cvcvcvcvcv")
;;(tst "20.5,20.5,20.5")
;;(tst "3cccccc1x")
;;(tst "xxxxxxxxxx31x")
;;(tst "xsadsadsadsadsadsadsa31x")
;;(tst "31x")
(defun tst  (num)
  (if (not (wcmatch NUM "*[]`~`['!%^&()+={}|`\\:;\"<>/]*"))
    (cond
      ((wcmatch NUM "*x[0-9]*") nil)
      ((wcmatch NUM "[0-9]x") t)
      ((wcmatch NUM "[0-9]") t)
      ((wcmatch NUM "*[0-9]x") t)
      ((and (not (wcmatch NUM "*[a-z],*[A-Z]")) (wcmatch NUM "*[0-9]x")) t)
      ((and (wcmatch NUM "*[0-9]*")
    (wcmatch NUM "*[`,`.]*")

    (and (not (wcmatch NUM "*[a-z],*[A-Z]")) (not (wcmatch NUM "[a-z]*,[A-Z]*")))
   
    )
       t))))

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: would you help me with wcmatch
« Reply #8 on: August 21, 2006, 05:51:35 PM »
Appears to me what you need is a quick parser --

Code: [Select]
(defun _CSV2List ( csv / flag value result )
    ;;  quick/simple implementation, don't beat me up
    (foreach code (reverse (vl-string->list csv))           
        (if (eq 44 code)
            (setq result (cons value result) value nil)
            (setq value (cons code value))
        )
    )
    (mapcar
       '(lambda (x) (if x (vl-list->string x) ""))
        (cons value result)
    )   
)

Contrived use --

Code: [Select]
(defun TextIsOk ( text )
    (or
        (wcmatch text "#[Xx]")
        (vl-every '(lambda (x) (distof x 2)) (_CSV2List text))
    )   
)

Examples --

Code: [Select]
(TextIsOk "20.5,20.5,20.5") => T

(TextIsOk "3x") => T

(TextIsOk "ack") => nil

Obviously you'll have to pen additional logic to test for the correct number of fields etc. I'm going to let you do some of the work.

:)
« Last Edit: August 21, 2006, 06:08:15 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: would you help me with wcmatch
« Reply #9 on: August 21, 2006, 06:24:23 PM »
I felt left out.  Here is one I penned real quick.
Code: [Select]
(defun IsStrNums (String)

(not
 (vl-catch-all-error-p
  (vl-catch-all-apply
   '(lambda ()
    (foreach i (vl-string->list String)
     (if (not (vl-position i '(44 46 48 49 50 51 52 53 54 55 56 57)))
      (exit)
     )
    )
   )
  )
 )
)
)
Quote
Command: (isstrnums "hello")
nil

Command: (isstrnums "2.5")
T

Command: (isstrnums "2.5,50")
T

Command: (isstrnums "2.5,50x")
nil
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: would you help me with wcmatch
« Reply #10 on: August 21, 2006, 07:04:41 PM »
demain si vous avez une chance, pour expliquer votre problème en plus détail, svp.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: would you help me with wcmatch
« Reply #11 on: August 21, 2006, 08:33:27 PM »
G5x_Rm0WQb_jQaJVPqtjSm0rP54o75W_8rBVRq4tPLsbEk
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Maverick®

  • Seagull
  • Posts: 14778
Re: would you help me with wcmatch
« Reply #12 on: August 21, 2006, 09:12:22 PM »
G5x_Rm0WQb_jQaJVPqtjSm0rP54o75W_8rBVRq4tPLsbEk

Oh no you dint'.  No way you said that 'bout my Momma you ketchup swillin, tuque wearin, .......programmer.....guy. 

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: would you help me with wcmatch
« Reply #13 on: August 21, 2006, 09:36:23 PM »
Taking careful aim ... touch lower ... steady now ... PTUI!! Spitball hits Mav right betwixt the eyes!! Bwaaaaaa!!

 :-P
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

LE

  • Guest
Re: would you help me with wcmatch
« Reply #14 on: August 21, 2006, 10:03:17 PM »
G5x_Rm0WQb_jQaJVPqtjSm0rP54o75W_8rBVRq4tPLsbEk

 :-D

Quote
French = demain si vous avez une chance, pour expliquer votre problème en plus détail, svp.
tomorrow, if you have a chance explain your problem in more detail, please.

Just trying to communicate a little better.... that's all  :laugh: