Author Topic: would you help me with wcmatch  (Read 5492 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:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: would you help me with wcmatch
« Reply #15 on: August 21, 2006, 10:05:13 PM »
Just trying to communicate a little better.... that's all

T o o   m u c h   i r o n y ,   h e a d   e x p l o d i n g   . . .
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: would you help me with wcmatch
« Reply #16 on: August 21, 2006, 10:41:39 PM »
For those that don't get the irony bit ...

( FromBase64 "G5x_Rm0WQb_jQaJVPqtjSm0rP54o75W_8rBVRq4tPLsbEk" )

=> "Does anyone know what he's sayin'?"

< insert maniacal laughter here >
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 #17 on: August 21, 2006, 10:51:56 PM »
I thought that Irony means when someone iron their clothes.....  :lol:

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: would you help me with wcmatch
« Reply #18 on: August 22, 2006, 01:50:19 AM »
This one seems to work on every LE's tests, and some others :
"20.5.0,20.5,20.5" -> nil
"3xx" -> nil

Code: [Select]
(cond
  ((and
     (setq n (vl-string-position 88 (strcase rValue2)))
     (= (+ n 1) (strlen rValue2))
     (numberp (read (substr rValue2 1 n)))
   )
  )
  (T
   (while (setq n (vl-string-position 44 rValue2))
     (setq lst    (cons (substr rValue2 1 n) lst)
   rValue2 (substr rValue2 (+ 2 n))
     )
   )
   (setq lst (cons rValue2 lst))
   (vl-every '(lambda (x)
(and (= (strlen x) (strlen (vl-princ-to-string (read x))))
     (numberp (read x))
)
      )
     lst
   )
  )
)
« Last Edit: August 22, 2006, 02:09:03 AM by gile »
Speaking English as a French Frog

Tramber

  • Guest
Re: would you help me with wcmatch
« Reply #19 on: August 22, 2006, 04:32:11 AM »
Hi everybody and thanks to everyone  :kewl:

The MP code seems to be very efficient :

Code: [Select]
    (defun _CSV2List ( csv / flag value result );;  quick/simple implementation, don't beat me up   ; Don't worry !
      (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)))
   
    (defun tst ( text ) (or(wcmatch text "*[Xx]")(vl-every '(lambda (x) (distof x 2)) (_CSV2List text))))

BUT there is still a problem remaining :
(tst "x3x") returns T instead of nil.
I tried to modify the wcmatch that is involved in that case in the tst function, but I didn't succeed. I'm still lost and tried (wcmatch "x3x" "[~0-9`,]*") with no success. Help !

NB : I understood and will use _CSV2List and it's great.
I understood most of your routines, guys, and they all are brilliant. But I'm back to my first problem : how to filter INTEGER+letter X ?
« Last Edit: August 22, 2006, 04:36:49 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 #20 on: August 22, 2006, 07:04:38 AM »
Hi Bert. Thank you for the kind words but --

(1) You should write a better version of CSV2LIST as it wasn't intended to be an industrial strength function, just a quick one off to illuminate one possible technique, not necessarilly the implementation, to a solution.

(2) You're killin' me. Why are you changing "#[Xx]" to "*[Xx]"?? That's not how I posted it but that's how you are using it and quoting it back.

The originally posted filter "#[Xx]" will allow a number and upper|lowercase version of "x", e.g.  "0x" thru "9x", and that's it --

    (wcmatch "1X" "#[Xx]") => T
    (wcmatch "2X" "#[Xx]") => T
    (wcmatch "3X" "#[Xx]") => T
    (wcmatch "9X" "#[Xx]") => T
    (wcmatch "9X9" "#[Xx]") => nil


If "0x" would be considered invalid you could use --

    (wcmatch text "[1-9][Xx]")

The filter you posted "*[Xx]" will allow anything (or nothing) prefixing upper|lowercase "x", everything from a simple "x" to "AllYourLispAreBelongToX" would pass such a filter.

    (wcmatch "X" "*[Xx]") => T
    (wcmatch "AllYourLispAreBelongToX" "*[Xx]") => T


Does this help? Am I completely missing your point? Do I need a coffee? Ok, I know the anwwer at least one of these: Medic!

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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: would you help me with wcmatch
« Reply #21 on: August 22, 2006, 07:25:01 AM »
Whlie I have your attention, is it possible you are trying to prompt in a way that is not ideal. I don't pretend to understand what you're trying to build here but from the little I can glean from all this would lean me towards branched prompting: Ask the user if the want absolute or scaled input, if the former allow a list of numbers, otherwise a single scale factor, but hey, I'm still not awake.

Abort|Ignore|Retry|Fail. :doa:
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 #22 on: August 22, 2006, 08:05:35 AM »
Well, the trouble is that I noticed * allowed me to input a "21x" (more than 10), not the #.

But, I've been back to school, reading the HLP (that doesn't explain very clearly wcmatch, overwise I wouldn't ask you all). No matter where we live we all have to read the documentation in English, and that the reason why I was lost, the story of the brackets and the ~ was not clear to me.

Then I got a brilliant idea based on your lesson and finally understood the consequences of my crime :

Code: [Select]
(defun tst ( text ) (or(wcmatch text "##[Xx]")(wcmatch text "#[Xx]")(vl-every '(lambda (x) (distof x 2)) (_CSV2List text))))
And all my trouble seem to be so far away....
...better than yesterday  ^-^

Thank you and sorry for that very messy conversation.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: would you help me with wcmatch
« Reply #23 on: August 22, 2006, 08:18:30 AM »
Sorry if I sounded grumpy Bert, just woke up prior to my fisrt post this am.

Just a quick note, you can separate wcmatch patterns with a comma --

(wcmatch text "#[Xx],##[Xx]")

or

(wcmatch text "[1-9][Xx],[1-9][0-9][Xx]")

etc.

Well off to work ...

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