Author Topic: Alphabet character string only  (Read 12830 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Alphabet character string only
« Reply #30 on: April 10, 2018, 09:10:25 AM »
I believe Marc is slippin' in Unicode "\\U+03B1" or some variant.

If you want to see it full y fleshed out pass it to vl-string->list:

(vl-string->list "α") >> (92 85 43 48 51 66 49)

(mapcar 'chr (vl-string->list "α")) >> ("\\" "U" "+" "0" "3" "B" "1")

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: Alphabet character string only
« Reply #31 on: April 10, 2018, 09:19:07 AM »
It was actually Vovka who introduced that unicode character. Perhaps as a joke, perhaps to illuminate ASCII vs UNICODE differences. Strictly speaking it should fail an isalpha test as has been defined for decades (unless expressly coded for unicode). But so should a space. :roll:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Alphabet character string only
« Reply #32 on: April 10, 2018, 09:21:37 AM »
An isalpha predicate function that allows non alpha characters is illogical.
yep, and it returns nil for the Alpha itself :)
(alpha-p "α")
Excuse my ignorance, why?
Comando: (ascii "α") 92
Comando: (chr 92)   "\\"
Comando: (ascii "\\") 92

this is all about Unicode
and that's why functions like alpha-p have to be unique for every language/locale

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Alphabet character string only
« Reply #33 on: April 10, 2018, 09:48:14 AM »
...
this is all about Unicode
and that's why functions like alpha-p have to be unique for every language/locale
Maybe this was correct:
Depends on your Alphabet  :thinking:

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Alphabet character string only
« Reply #34 on: April 10, 2018, 10:21:15 AM »
That was cruel. My brain hasn't been the quickest lately so that made it even more tough.

I don't understand why you guys are so hung up on the whole "alphabet" and "a space" in this context (I agree with you a space isn't a alpha char but the op wanted a find a space and alpha chars; who knows what they are building). They probably didn't know the ascii chart; teach them how to add spaces to their parser and/or show them how to parse a string properly with proper methods (and don't use regex).

***
The process of recognizing what is in or a string itself is properly done with a lexer.
https://en.wikipedia.org/wiki/Lexical_analysis

The C Standard library has built in functions (shown below) which help us scan/lex/parse strings; The autolisp language does not have the amount of control over strings like a C language does (in C we treat the string like an array--a list in Autolisp terms-) but you can still mock one up if interested after reading up on the subject.

Code - C++: [Select]
  1. #include <ctype.h>
  2. isalpha()
  3. isspace()
  4. isalnum()
  5. ispunct()
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Alphabet character string only
« Reply #35 on: April 10, 2018, 11:17:12 AM »
I think this should do the trick or is there another/easier method available with VL-string functions?
Just a new start:
Code: [Select]
(defun foo (s)
  (and
    (/= "" s)
    (=     
      (vl-string-translate
        " !\"#$%&'()*+,-./123456789:;<=>?@[\\]^_`{|}~"
        "0000000000000000000000000000000000000000000"
        s
      )
      s
    )
    (not (distof s));Edit3
  )
 )
(foo "abc ") nil
(foo "abc" ) T
(foo "a"   ) nil
(foo "."   ) nil
(foo "1.2" ) nil
(foo "a.b" ) nil
(foo "a b" ) nil
(foo ""    ) nil
(foo "0"   ) nil

Edit: need a condition for (foo "0")...  :tickedoff:
Edti2: just to try a new way...
Edit3: sorry pasted wrong version.... need other improvements: (foo "a00000a")  > T

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Alphabet character string only
« Reply #36 on: April 10, 2018, 12:12:11 PM »
... the op wanted a find a space and alpha chars ...

How do you interpret that from the original post?

I think this should do the trick or is there another/easier method available with VL-string functions?

Code: [Select]
(defun AlphabetOnly ($ /)
  (while (and (wcmatch (substr $ 1 1) "@") $)
    (setq $ (substr $ 2))       
  )
  (= $ "")
)

Edit: should still check "" input...

I maintain that writing isalpha, isdigit type functions that return true for characters that are not alphabetic or digits respectively is illogical and just plain bad practice.

It's also contrary to standards that have been in place for decades which incidentally this snip:

#include <ctype.h>
isalpha()
isspace()
isalnum()
ispunct()

Unintentionally underscores.

When solving problem one should learn how to define and use standard functions and practices -- and those who espouse to be teachers should guide students accordingly.

To wit, any C (and derivative languages) programmer who would posture themselves as an expert and then would abuse or override the core libraries so that isalpha returned a true state if passed a space would be swiftly taken to task by the programming community. Why it's acceptable in this thread baffles me.

... much of the autolisp community is in trouble.

You may have a point.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Alphabet character string only
« Reply #37 on: April 10, 2018, 12:59:16 PM »
I seriously don't understand why you are so angry but I have a feeling were having different discussions or what the thoughts/needs the op has.

I didn't glean the space criteria from the main post just saw a comment like: "what about spaces" and people jumping down their back(s). I chime in with a 12 second fix and say that a custom search isn't `bad' (only to get lambasted and roped into this "discussion"). I honestly don't care one way or another; I seriously doubt this function will be used throughout the world in thousands of programs or will become the default isalpha function for the autolisp community. Programmers write custom search functions all the time.

No you got it, that snip perfectly underscores the point(s). And, no I would not alter the std lib for isalpha.

I am absolutely no expert in anything!

Yes, teach them. All I see so-far is "isalpha should not include spaces." and nothing helping them solve the "alpha chars and spaces problem". show them how to do what they want. I would be happy to teach in C lang terms; I just took "a while" trying to build something in autolisp and I had a very hard time (what I have, though, is a big cluster-eff). I can keep working at an autolisp lesson but it will take me a very long time and whatever I offer will be no good (I'll post what I have and you can certainly make fun of me for it if you want).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Alphabet character string only
« Reply #38 on: April 10, 2018, 01:12:30 PM »
I'm not angry and the OP has no alpha spaces problem to solve.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Alphabet character string only
« Reply #39 on: April 10, 2018, 01:50:43 PM »
I'm not angry and the OP has no alpha spaces problem to solve.
*facepalm* (re-scans thread) ...I think I understand, now, where I got tossed off track.


Where did the OP state the requirement to permit spaces?

He didn't, i was merely pointing out that feeding in a string of only alphabet characters would return nil if there was a space, whereas Grr1337's wouldn't.

When you analyze string structures, you often disregard whitespace entirely (whitespace is unimportant for the most part; humans need spaces, a parser just chunks up bits of a string at a time looking for patterns). I did post a mini-parser written in C++ at one time and I fond the post for you to check out, Dlanor. You may not be able to read a C language but the code should be readable enough to glean the standard method for parsing -i.e. tokens, parser, AST, and driver. I have a binary search tree in that code but you can ignore that part.

http://www.theswamp.org/index.php?topic=50378.msg555203#msg555203

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Alphabet character string only
« Reply #40 on: April 10, 2018, 02:14:20 PM »
Thanks for taking the time to rescan the thread and reassess what transpired. Ill acknowledge I was sarcastic in post 15 which was not really helpful and I apologise accordingly. Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: Alphabet character string only
« Reply #41 on: April 10, 2018, 11:51:37 PM »
Thinking off topic :

Just thinking about alphabetic punctuation ... just 'cause ...

The hyphen is interesting ; could be considered ( or used as ) a minus sign and exponent.
We would need to build in some interesting test cases for hyphenated characters.

Ditto Full-Stop and the decimal marker.

... and that's without the usage of special characters in some languages ...




Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Alphabet character string only
« Reply #42 on: April 11, 2018, 05:57:07 AM »
Code: [Select]
(defun foo (s)
  (and
    (/= "" s)
    (not (vl-string-position (ascii "0") s))
    (=     
      (vl-string-translate
        " !\"#$%&()*+,/123456789:;<=>?@[\\]^_`{|}~"
        "0000000000000000000000000000000000000000"
        s
      )
      s
    )
  )
)
Code: [Select]
(foo "abc" )T
(foo "a"   )T
(foo "Marc'Antonio")T
(foo "Marco-Antonio")T
(foo "MarcAntonio.")T
(foo "a.b" )T
(foo "."   )T
(foo "abc ")nil
(foo "1.2" )nil
(foo "a b" )nil
(foo ""    )nil
(foo "0"   )nil
(foo "0.0" )nil
(foo "a0.0")nil
(foo "-1"  )nil
(foo ".1"  )nil

XXL66

  • Newt
  • Posts: 99
Re: Alphabet character string only
« Reply #43 on: April 11, 2018, 06:07:32 AM »
The suggested solution from LM is excellent for my purpose (a-z A-Z). Thank you LM!
Spaces already have been dealt with, the input string is a substring from a string delimited with spaces.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Alphabet character string only
« Reply #44 on: April 11, 2018, 06:33:47 AM »
Just for fun:
Code - Auto/Visual Lisp: [Select]
  1. (defun DependsOnYourAlphabet ( Str MyAlphabet )
  2.   (
  3.     (lambda ( f s a )
  4.       (if (/= s "")
  5.         (f s a)
  6.       )
  7.     )
  8.     (lambda ( s a )
  9.       (or (= s "")
  10.         (and
  11.           (vl-string-search (substr s 1 1) a)
  12.           (f (substr s 2) a)
  13.         )
  14.       )
  15.     )
  16.     Str MyAlphabet
  17.   )
  18. ); defun DependsOnYourAlphabet

Code - Auto/Visual Lisp: [Select]
  1. (setq L '( "abc" "a" "Marc'Antonio" "Marco-Antonio" "MarcAntonio." "a.b" "." "abc " "1.2" "a b" "" "0" "0.0" "a0.0" "-1"  ".1"))
  2.  
  3. _$ (mapcar '(lambda (x) (list x '>> (DependsOnYourAlphabet x "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz -_.'"))) L)
  4. (
  5.   ("abc" >> T)
  6.   ("a" >> T)
  7.   ("Marc'Antonio" >> T)
  8.   ("Marco-Antonio" >> T)
  9.   ("MarcAntonio." >> T)
  10.   ("a.b" >> T)
  11.   ("." >> T)
  12.   ("abc " >> T)
  13.   ("1.2" >> nil)
  14.   ("a b" >> T)
  15.   ("" >> nil)
  16.   ("0" >> nil)
  17.   ("0.0" >> nil)
  18.   ("a0.0" >> nil)
  19.   ("-1" >> nil)
  20.   (".1" >> nil)
  21. )
  22. _$ (mapcar '(lambda (x) (list x '>> (DependsOnYourAlphabet x "1234567890 -,.'"))) L)
  23. (
  24.   ("abc" >> nil)
  25.   ("a" >> nil)
  26.   ("Marc'Antonio" >> nil)
  27.   ("Marco-Antonio" >> nil)
  28.   ("MarcAntonio." >> nil)
  29.   ("a.b" >> nil)
  30.   ("." >> T)
  31.   ("abc " >> nil)
  32.   ("1.2" >> T)
  33.   ("a b" >> nil)
  34.   ("" >> nil)
  35.   ("0" >> T)
  36.   ("0.0" >> T)
  37.   ("a0.0" >> nil)
  38.   ("-1" >> T)
  39.   (".1" >> T)
  40. )

Code: [Select]
(defun MyCyrillicAlphabet ( / s x )
  (setq s "")
  (setq x 256)
  (while (<= 192 (setq x (1- x)) 255)
    (setq s (strcat (chr x) s))
  )
  (strcat s " ")
)

_$ (DependsOnYourAlphabet "This is not my alphabet" (MyCyrillicAlphabet)) >> nil
_$ (DependsOnYourAlphabet "Това е моята азбука" (MyCyrillicAlphabet)) >> T
« Last Edit: April 11, 2018, 06:54:38 AM by Grrr1337 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg