TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Tramber 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?
(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.
-
Not sure what you are asking but that didn't stop me from a quick concept offering --
(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.
:)
-
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]")
-
Means whatever you want it to, just don't say it aloud. :)
I'm not convinced I understand you but play with this --
(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.
-
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 *
-
Hi Bert,
It' not very "elegant" :
(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)
)
)
-
Re,
Another sismilar way.
(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)
)
)
)
-
Lately I just do mickey mouse lisp (and maybe in the past too).... anyway here is something, need more conditions.... HTH
;;(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))))
-
Appears to me what you need is a quick parser --
(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 --
(defun TextIsOk ( text )
(or
(wcmatch text "#[Xx]")
(vl-every '(lambda (x) (distof x 2)) (_CSV2List text))
)
)
Examples --
(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.
:)
-
I felt left out. Here is one I penned real quick.
(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)
)
)
)
)
)
)
)
Command: (isstrnums "hello")
nil
Command: (isstrnums "2.5")
T
Command: (isstrnums "2.5,50")
T
Command: (isstrnums "2.5,50x")
nil
-
demain si vous avez une chance, pour expliquer votre problème en plus détail, svp.
-
G5x_Rm0WQb_jQaJVPqtjSm0rP54o75W_8rBVRq4tPLsbEk
-
G5x_Rm0WQb_jQaJVPqtjSm0rP54o75W_8rBVRq4tPLsbEk
Oh no you dint'. No way you said that 'bout my Momma you ketchup swillin, tuque wearin, .......programmer.....guy.
-
Taking careful aim ... touch lower ... steady now ... PTUI!! Spitball hits Mav right betwixt the eyes!! Bwaaaaaa!!
:-P
-
G5x_Rm0WQb_jQaJVPqtjSm0rP54o75W_8rBVRq4tPLsbEk
:-D
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:
-
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 . . .
-
For those that don't get the irony bit ...
( FromBase64 (http://cadlabs.backpackit.com/assets/693/080/encoding.lsp.txt) "G5x_Rm0WQb_jQaJVPqtjSm0rP54o75W_8rBVRq4tPLsbEk" )
=> "Does anyone know what he's sayin'?"
< insert maniacal laughter here >
-
I thought that Irony means when someone iron their clothes..... :lol:
-
This one seems to work on every LE's tests, and some others :
"20.5.0,20.5,20.5" -> nil
"3xx" -> nil
(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
)
)
)
-
Hi everybody and thanks to everyone :kewl:
The MP code seems to be very efficient :
(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 ?
-
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!
:)
-
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:
-
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 :
(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.
-
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 ...
:)