TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: XXL66 on April 08, 2018, 05:29:07 AM

Title: Alphabet character string only
Post by: XXL66 on April 08, 2018, 05:29:07 AM
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...
Title: Re: Alphabet character string only
Post by: Grrr1337 on April 08, 2018, 06:09:19 AM
If I remember correctly Roy wrote some functions 'FullyAlphabetic' / 'FullyNumeric'.. and so on, but I'm unable to find that thread.

Anyway:
Code: [Select]
; _$ (StrNump "abcdefg") -> nil
; _$ (StrNump "abcdef8g") -> T
(defun StrNump ( s )
  (if (/= s "")
    (or
      (wcmatch (substr s 1 1) "#")
      (StrNump (substr s 2))
    )
  )
)
Title: Re: Alphabet character string only
Post by: Dlanor on April 08, 2018, 06:10:27 AM
Depends on your Alphabet  :thinking:
Title: Re: Alphabet character string only
Post by: Lee Mac on April 08, 2018, 06:40:31 AM
Code: [Select]
(defun alpha-p ( s ) (wcmatch s "~*[~A-Za-z]*"))
Title: Re: Alphabet character string only
Post by: XXL66 on April 08, 2018, 07:36:20 AM
 8-)
Title: Re: Alphabet character string only
Post by: gile on April 08, 2018, 09:50:12 AM
Code - Auto/Visual Lisp: [Select]
  1. (defun AlphaOnly (s)
  2.     '(lambda (x) (< 64 x 91))
  3.     (vl-string->list (strcase s))
  4.   )
  5. )
  6.  
  7. (defun DigitOnly (s)
  8.     '(lambda (x) (< 64 x 91)))
  9.     (vl-string->list s)
  10.   )
  11. )
Title: Re: Alphabet character string only
Post by: Dlanor on April 08, 2018, 09:54:13 AM
Code: [Select]
(defun AlphabetOnly ($ /)
  (while (and (wcmatch (substr $ 1 1) "@") $)
    (setq $ (substr $ 2))       
  )
  (= $ "")
)

Code: [Select]

(defun alpha-p ( s ) (wcmatch s "~*[~A-Za-z]*"))


Neither account for a string with a space or spaces
Title: Re: Alphabet character string only
Post by: Lee Mac on April 08, 2018, 10:16:02 AM
Neither account for a string with a space or spaces

Where did the OP state the requirement to permit spaces?
Title: Re: Alphabet character string only
Post by: Dlanor on April 08, 2018, 11:27:42 AM
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.
Title: Re: Alphabet character string only
Post by: MP on April 08, 2018, 11:34:44 AM
Neither account for a string with a space or spaces

A space is not an alphabetic character.

i was merely pointing out that feeding in a string of only alphabet characters would return nil if there was a space

As they should.
Title: Re: Alphabet character string only
Post by: Dlanor on April 08, 2018, 11:41:04 AM
A space is not an alphabetic character.

I agree, but it denotes no alphabet character, otherwiseitwouldmakereadingtextstringsmoredifficult.
Title: Re: Alphabet character string only
Post by: MP on April 08, 2018, 11:45:03 AM
completelyirrelevant
Title: Re: Alphabet character string only
Post by: MP on April 08, 2018, 12:43:11 PM
Back on track, want to say that:

(defun alpha-p (s) (wcmatch s "~*[~A-Za-z]*"))

And it's obvious companions like:

(defun digits-p (s) (wcmatch s "~*[~0-9]*"))

Are very elegant solutions. Nicely done Lee.
Title: Re: Alphabet character string only
Post by: JohnK on April 09, 2018, 03:26:34 PM
I don't see how it cannot be relevant.

Yes, when building a parser/etc. typically you often only use [A-Za-z] (or [:alpha:] in posix terms) and parse out other language structures separately (that's they way I've always done my parsing) but that doesn't make the request irrelevant.

If you want spaces just add it to the regex list.
Code - Auto/Visual Lisp: [Select]
  1. (defun alpha-p(s) (wcmatch s "~*[~A-Za-z],[ ]*"))

Code: [Select]
Command: (defun alpha-p (s) (wcmatch s "~*[~A-Za-z],[ ]*"))
ALPHA-P

Command: (alpha-p "test")
T

Command: (alpha-p "123")
nil

Command: (alpha-p "this is a big long string")
T

Command: (alpha-p "this is a big long string with numbers 123")
nil
Title: Re: Alphabet character string only
Post by: MP on April 09, 2018, 03:44:35 PM
Why stop there, you might as well pen goofy flavours of listp, minusp, numberp etc. while you’re at it.
Title: Re: Alphabet character string only
Post by: roy_043 on April 09, 2018, 04:58:47 PM
@John:
You probably mean:
Code - Auto/Visual Lisp: [Select]
  1. (defun alpha-p (s) (wcmatch s "~*[~A-Za-z ]*"))
Title: Re: Alphabet character string only
Post by: JohnK on April 09, 2018, 05:13:28 PM
Why stop there, you might as well pen goofy flavours of listp, minusp, numberp etc. while you’re at it.
What (I'm confused)? ...No. But I don't see how the addition of spaces was all that big of a deal--as far as requests go--or that far out of possibilities -i.e. a user wanting to quickly check the string is of only alpha and spaces with a high level language (a language which doesn't treats strings as arrays).  I'm confused (that elevated quickly).

@John:
You probably mean:
Code - Auto/Visual Lisp: [Select]
  1. (defun alpha-p (s) (wcmatch s "~*[~A-Za-z ]*"))
Sure. That'll work.

EDIT: added a few words for clarity.
Title: Re: Alphabet character string only
Post by: MP on April 09, 2018, 05:58:54 PM
An isalpha predicate function that allows non alpha characters is illogical.
Title: Re: Alphabet character string only
Post by: JohnK on April 09, 2018, 06:05:33 PM
Wait, what!? Ha! If that's all, then much of the autolisp (and all programming lanuage) community is in trouble. I've seen whole solutions developed with functions named after vowels. I've seen countless functions names "foo" and "bar". ...change the name.
Title: Re: Alphabet character string only
Post by: VovKa on April 09, 2018, 07:14:42 PM
An isalpha predicate function that allows non alpha characters is illogical.
yep, and it returns nil for the Alpha itself :)
(alpha-p "α")
Title: Re: Alphabet character string only
Post by: MP on April 09, 2018, 09:16:46 PM
returns nil for the Alpha itself :)
(alpha-p "α")

 :uglystupid2: appropriate
Title: Re: Alphabet character string only
Post by: XXL66 on April 10, 2018, 05:40:04 AM
@John:
You probably mean:
Code - Auto/Visual Lisp: [Select]
  1. (defun alpha-p (s) (wcmatch s "~*[~A-Za-z ]*"))

Was that yours Roy? Very neat work!
Title: Re: Alphabet character string only
Post by: roy_043 on April 10, 2018, 06:50:19 AM
@John:
You probably mean:
Code - Auto/Visual Lisp: [Select]
  1. (defun alpha-p (s) (wcmatch s "~*[~A-Za-z ]*"))

Was that yours Roy? Very neat work!
I just added a space to Lee's suggestion in response to John's attempt (which does not work properly).
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 10, 2018, 07:44:47 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
Title: Re: Alphabet character string only
Post by: scottcd on April 10, 2018, 08:24:42 AM
(ascii "a") returns 97 in both Autocad 2018 and BricsCAD 18.2
Title: Re: Alphabet character string only
Post by: JohnK on April 10, 2018, 08:25:21 AM
@John:
You probably mean:
Code - Auto/Visual Lisp: [Select]
  1. (defun alpha-p (s) (wcmatch s "~*[~A-Za-z ]*"))

Was that yours Roy? Very neat work!
I just added a space to Lee's suggestion in response to John's attempt (which does not work properly).

Hey!? what do you mean my addition doesn't work properly. Does so. Does so! Well, at least it should (but I guess it depends on the regex guts autodesk used but it should). I only had AutoCAD 2016 installed (and before the other day, I didn't even know I had AutoCAD installed on this machine).
Code: [Select]
Command: (defun a (s) (wcmatch s "~*[~A-Za-z ]*"))
A

Command: (a "test")
T

Command: (a "a")
T

Command: (a ".")
nil

Command: (defun b (s) (wcmatch s "~*[~A-Za-z],[ ]*"))
B

Command: (b "test")
T

Command: (b "a")
T

Command: (b ".")
nil



Excuse my ignorance, why?
Comando: (ascii "α") 92
Comando: (chr 92)   "\\"
Comando: (ascii "\\") 92

That's odd. If I'm not mistaken, Portuguese is your natural language and Portuguese uses cp850 or cp860 but only the extended char set in those differs from the std char set.
https://www.ascii-codes.com/cp860.html
Weird! If you figure that one out, let me know (you have peeked my interest).
Title: Re: Alphabet character string only
Post by: Lee Mac on April 10, 2018, 08:28:06 AM
Code - Auto/Visual Lisp: [Select]
  1. _$ (a "1a")
  2. nil
  3. _$ (b "1a")
  4. T
Title: Re: Alphabet character string only
Post by: JohnK on April 10, 2018, 08:38:14 AM
Code - Auto/Visual Lisp: [Select]
  1. _$ (a "1a")
  2. nil
  3. _$ (b "1a")
  4. T

Ah! Got it. Thanks, Lee Mack. I apologize, roy_043. I removed your name from my list.
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 10, 2018, 08:56:54 AM
Excuse my ignorance, why?
Comando: (ascii "α") 92
Comando: (chr 92)   "\\"
Comando: (ascii "\\") 92

That's odd. If I'm not mistaken, Portuguese is your natural language and Portuguese uses cp850 or cp860 but only the extended char set in those differs from the std char set.
https://www.ascii-codes.com/cp860.html
Weird! If you figure that one out, let me know (you have peeked my interest).
I have: Code page 850 (Latin-1 - Western European languages)
Comando: SYSCODEPAGE    = "ANSI_1252" (solo lettura)
Comando: DWGCODEPAGE  = "ANSI_1252" (solo lettura)
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 10, 2018, 08:57:52 AM
(ascii "a") returns 97 in both Autocad 2018 and BricsCAD 18.2
(ascii "α")
Title: Re: Alphabet character string only
Post by: MP 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")

Title: Re: Alphabet character string only
Post by: MP 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:
Title: Re: Alphabet character string only
Post by: VovKa 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
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi 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:
Title: Re: Alphabet character string only
Post by: JohnK 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()
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi 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
Title: Re: Alphabet character string only
Post by: MP 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.
Title: Re: Alphabet character string only
Post by: JohnK 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).
Title: Re: Alphabet character string only
Post by: MP on April 10, 2018, 01:12:30 PM
I'm not angry and the OP has no alpha spaces problem to solve.
Title: Re: Alphabet character string only
Post by: JohnK 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

Title: Re: Alphabet character string only
Post by: MP 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.
Title: Re: Alphabet character string only
Post by: kdub_nz 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 ...




Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi 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
Title: Re: Alphabet character string only
Post by: XXL66 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.
Title: Re: Alphabet character string only
Post by: Grrr1337 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
Title: Re: Alphabet character string only
Post by: JohnK on April 11, 2018, 03:31:54 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 ...

On the kdub track: Contextual rabbit-hole! ...A few years ago I had a lot of fun writing a few parsers, and compilers because underneath it all, it is just linguistics. It's so much fun--and difficult--trying to understand context even from simple-straight-forward languages like programming languages (where "punctuation" and "grammar" don't necessarily apply). For example, take a look at the current code you have in front of you and just try to map out how you'd determine simple things like what is a built-in function vs variable; a simple task at first because you can build a symbol table for built-in's and use declarations for recognizing variable names--and build a cross-reference list--but the whole operation gets more complicated when you get to actual assignments and calls. Not to mention confusing because you have to design, create and traverse symtabs and abstract syntax tree's about a thousand times a second before you get to any sort of "decision part".

You don't have "assignments" in an actual language (e.g. English) but you do have metaphors and similes. ...Ugh!
Title: Re: Alphabet character string only
Post by: JohnK on April 11, 2018, 06:04:02 PM
Now I find myself craving to work on this stuff again.
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 12, 2018, 04:48:53 AM
Just for fun:
Code: [Select]
...
_$ (DependsOnYourAlphabet "This is not my alphabet" (MyCyrillicAlphabet)) >> nil
_$ (DependsOnYourAlphabet "Това е моята азбука" (MyCyrillicAlphabet)) >> T
I'm not an expert so I do not make judgments about it, but I think it's better to exclude all non-alphabetic characters than to include numerical ones.
Note: " !\"#$%&()*+,/123456789:;<=>?@[\\]^_`{|}~" < need to add other not Alpha
Edit: It's still great work to include Unicode characters.    >>> not true...
Edit2: seem ok for Unicode.
This is the only word I found that is written with the accent in English (American): "Yaoundé"
Code: [Select]
(foo "Yaoundé") => T
(DependsOnYourAlphabet "Yaoundé" "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz -_.'") => nil
Title: Re: Alphabet character string only
Post by: Grrr1337 on April 12, 2018, 05:43:53 AM
It returned nil because you didn't included that character as a member of your alphabet,
I'm unable to test it in VLIDE, since it translates it to "e", but would this work:
Code: [Select]
(DependsOnYourAlphabet "Yaoundé" "éAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz -_.'")
Title: Re: Alphabet character string only
Post by: ronjonp on April 12, 2018, 10:13:36 AM
Did not read this whole thread, but this is what first came to my mind:
Code - Auto/Visual Lisp: [Select]
  1. (defun nonumbers (s) (vl-every '(lambda (x) (not (<= 47 x 56))) (vl-string->list s)))
  2. (setq l '("abc"       "a"         "Marc'Antonio"          "Marco-Antonio"         "MarcAntonio."
  3.           "a.b"       "."         "abc "      "1.2"       "a b"       ""          "0"
  4.           "0.0"       "a0.0"      "-1"        ".1"        "Yaoundé"
  5.          )
  6. )
  7. (mapcar '(lambda (x) (list x (nonumbers x))) l)
  8. ;;(("abc" T) ("a" T) ("Marc'Antonio" T) ("Marco-Antonio" T) ("MarcAntonio." T) ("a.b" T) ("." T) ("abc " T) ("1.2" nil) ("a b" T) ("" T) ("0" nil) ("0.0" nil) ("a0.0" nil) ("-1" nil) (".1" nil) ("Yaoundé" T))
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 12, 2018, 11:07:29 AM
Did not read this whole thread, but this is what first came to my mind:
Code - Auto/Visual Lisp: [Select]
  1. (defun nonumbers (s) (vl-every '(lambda (x) (not (<= 47 x 56))) (vl-string->list s)))
  2. (setq l   '("abc"         "a"     "Marc'Antonio"     "Marco-Antonio"     "MarcAntonio."
  3.      "a.b"         "."     "abc "      "1.2"     "a b"         ""     "0"
  4.      "0.0"         "a0.0"     "-1"         ".1"     "Yaoundé"
  5.     )
  6. )
  7. (mapcar '(lambda (x) (list x (nonumbers x))) l)
  8. ;;(("abc" T) ("a" T) ("Marc'Antonio" T) ("Marco-Antonio" T) ("MarcAntonio." T) ("a.b" T) ("." T) ("abc " T) ("1.2" nil) ("a b" T) ("" T) ("0" nil) ("0.0" nil) ("a0.0" nil) ("-1" nil) (".1" nil) ("Yaoundé" T))
Is similar:
Code: [Select]
;gile
(defun AlphaOnly (s)
  (vl-every
    '(lambda (x) (< 64 x 91))
    (vl-string->list (strcase s))
  )
)
("abc " T) ("a b" T) ("" T)
Null strings or spaces appear not to be allowed.  :)


Edit: the real question is not "nonumbers" but "isalpha" ...
Title: Re: Alphabet character string only
Post by: MP on April 12, 2018, 12:53:11 PM
Null strings or spaces appear not to be allowed.  :)

That was answered here (http://bit.ly/2JE2GPQ).
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 12, 2018, 01:00:11 PM
Null strings or spaces appear not to be allowed.  :)

That was answered here (http://bit.ly/2JE2GPQ).
:) :tickedoff: 8)
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 12, 2018, 01:14:37 PM
Just for fun:
Code: [Select]
(defun DependsOnYourAlphabet ( Str MyAlphabet )
  (
    (lambda ( f s a )
      (if (/= s "")
        (f s a)
      )
    )
    (lambda ( s a )
      (or (= s "")
        (and
          (vl-string-search (substr s 1 1) a)
          (f (substr s 2) a)
        )
      )
    )
    Str MyAlphabet
  )
); defun DependsOnYourAlphabet
...
_$ (DependsOnYourAlphabet "Това е моята азбука" (MyCyrillicAlphabet)) >> T
Comando: (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")
0

Comando: (substr "Това е моята азбука" 1 1)
"\\"
Title: Re: Alphabet character string only
Post by: Grrr1337 on April 12, 2018, 03:20:42 PM
Comando: (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")
0

Comando: (substr "Това е моята азбука" 1 1)
"\\"

Everythings fine on my end:

Code: [Select]
_$  (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")
2
_$ (substr "Това е моята азбука" 1 1)
"Т"

Maybe you have the same issue as I'm having with the Spanish alphabet - VLIDE doesn't recognise these characters.


Null strings or spaces appear not to be allowed.  :)

That was answered here (http://bit.ly/2JE2GPQ).

I'm wondering how this doesn't have billions (https://www.youtube.com/watch?v=u_aLESDql1U) previews, Michael. :)
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 12, 2018, 03:30:39 PM
Comando: (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")
0

Comando: (substr "Това е моята азбука" 1 1)
"\\"

Everythings fine on my end:

Code: [Select]
_$  (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")
2
_$ (substr "Това е моята азбука" 1 1)
"Т"

Maybe you have the same issue as I'm having with the Spanish alphabet - VLIDE doesn't recognise these characters.
Ok, thanks for test.  :)
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 12, 2018, 05:05:36 PM
@Grrr1337: Sorry if I repeat the question, do you think it's better to exclude numeric or symbolic characters rather than to include alphabetic characters?
Code: [Select]
; by Grrrr1337 (modified see: < not)
; (setq NotAlpha " !\"#$%&()*+,/0123456789:;<=>?@[\\]^_`{|}~")
; (String_AlphaP "Yaoundé" NotAlpha)
(defun String_AlphaP ( Str NotAlpha )
  (
    (lambda ( f s a )
      (if (/= s "")
        (f s a)
      )
    )
    (lambda ( s a )
      (or (= s "")
        (and
          (not (vl-string-search (substr s 1 1) a)); < not
          (f (substr s 2) a)
        )
      )
    )
    Str NotAlpha
  )
)
:-)
Title: Re: Alphabet character string only
Post by: VovKa on April 12, 2018, 05:23:04 PM
Maybe you have the same issue as I'm having with the Spanish alphabet - VLIDE doesn't recognise these characters.
VLIDE (unlike Autocad Text Window) does not support Unicode, so it recognizes only those characters that belong to your local code page.
for you (and me) it's cyrillic windows-1251 and "Това е моята азбука" is OK because all characters fit into our 8-bit code page
Title: Re: Alphabet character string only
Post by: MP on April 12, 2018, 05:24:34 PM
:) :tickedoff: 8)

uh huh

I'm wondering how this doesn't have billions (http://www.youtube.com/watch?v=u_aLESDql1U) previews, Michael. :)

lol
Title: Re: Alphabet character string only
Post by: Marc'Antonio Alessi on April 13, 2018, 02:36:01 AM
:) :tickedoff: 8)

uh huh
Sorry if I do not comment but I would not misunderstand the "Canadian" irony... it happens that in a different language the same thing has a different meaning.
What I have just written, in fact, can be interpreted in various ways... (Google translation).
Grazie per il tempo che dedichi a questo newsgroup.  :-)

Since I'm here I made another variant:
Code: [Select]
; (setq NotAlpha " !\"#$%&()*+,/0123456789:;<=>?@[\\]^_`{|}~")
; (ALE_String_AlphaP "Yaoundé" NotAlpha)
;
(defun ALE_String_AlphaP (s n / f)
  (defun f (s n)
    (cond
      ( (= s "") )
      ( (and (not (vl-string-search (substr s 1 1) n)) (f (substr s 2) n)) )
    )
  )
  (cond ( (= s "") nil )  ( (f s n) ))
)
;variante con IF
(defun ALE_String_AlphaP (s n / f)
  (defun f (s n)
    (if (/= s "")
      (and
        (not (vl-string-search (substr s 1 1) n))
        (f (substr s 2) n)
      )
      T
    )
  )
  (and (/= s "") (f s n))
)
Title: Re: Alphabet character string only
Post by: MP on April 13, 2018, 01:38:55 PM
Sorry if I do not comment but ...

Trovo anche alcuni post su questo thread che confondono. L'unica cosa che possiamo fare a volte è ridere. Sii bene amico mio, è tutto roba piccola alla fine. Saluti.
Title: Re: Alphabet character string only
Post by: JohnK on April 18, 2018, 01:51:36 PM
I took a little time at lunch--for a few days--and built a "pretty good" (read: *meh*) Autolisp representation of how you'd build a simplistic lexer/parser/thing in a lower level language like C. A lot of the AutoLisp code doesn't make much sense because there isn't really a direct translation for the techniques (especially the AST; because we don't have classes and structures in AutoLisp) and I had to restructure some of the prescribed methods but at least you can see the general idea.
 
Also, this code/post wasn't necessarily to demonstrate anything "profound", it was merely for my own uses (I used it to sort of dip my toes back into lisp pool). It was frustrating for me because I kept typing things like COND incorrect and I had to force myself to think before I started typing each line.

I hope someone gets a good laugh from this code I worked so hard on these last few days during my lunch breaks.

Code - Auto/Visual Lisp: [Select]
  1. ;;---------
  2. ;; MISC SUPPORT FUNCTIONS
  3. ;;---------
  4. (defun list-push (sym lst) (set lst (cons sym (eval lst))) )
  5.  
  6. ;;---------
  7. ;; LEXER
  8. ;;---------
  9. (defun token ( nu / isalpha isdigit ispunct )
  10.     (defun isdigit ( nu )
  11.       (and (>= nu 48) (<= nu 57)))
  12.     (defun isalpha ( nu )
  13.       (or (and (>= nu 65) (<= nu 90))
  14.           (and (>= nu 97) (<= nu 122))))
  15.     (defun ispunct ( nu )
  16.       (or (and (>= nu 33) (<= nu 47))
  17.           (and (>= nu 58) (<= nu 64))
  18.           (and (>= nu 91) (<= nu 96))))
  19.     ;; Tokens
  20.   (cond
  21.     ((isalpha nu) -1)
  22.     ((ispunct nu) -2)
  23.     ((isdigit nu) -3)
  24.     )
  25.  )
  26.  
  27. ;;---------
  28. ;; AST (Abstract Syntax Tree)
  29. ;;
  30. ;; This isn't really a good representation of an AST
  31. ;; (just uses simple lists) but it will work.
  32. ;;---------
  33. (defun StringExpr-AST ( n )
  34.   ;; this function only creates a list
  35.   (list-push (chr n) 'StringExprAST) )
  36.  
  37. (defun PunctExpr-AST ( n )
  38.   ;; this function only creates a list
  39.   (list-push (chr n) 'PunctExprAST) )
  40.  
  41. (defun HandleString ( n )
  42.   ;; This function only calls the function to create
  43.   ;; a list but this is where you'd access the SearchTree
  44.   (StringExpr-AST n))
  45.  
  46. (defun HandlePunct ( n )
  47.   ;; This function only calls the function to create
  48.   ;; a list but this is where you'd access the SearchTree
  49.   (PunctExpr-AST n))
  50.  
  51. ;;---------
  52. ;; PARSER
  53. ;;---------
  54. (defun parser (aString / al-string-to-ascii-list)
  55.     (defun al-string-to-ascii-list (str / alst cntr)
  56.       (if (= cntr '()) (setq cntr 1))
  57.       (while (<= cntr (strlen str))
  58.              (setq alst (cons (ascii (substr str cntr 1)) alst)
  59.                    cntr (1+ cntr)))
  60.       (reverse alst) )
  61.   (mapcar
  62.     (function
  63.       (lambda (n)
  64.         (cond
  65.           ((= (token n) -1) (HandleString n))
  66.           ((= (token n) -2) (HandlePunct n))
  67.           ;; ...
  68.           )
  69.         )
  70.       )
  71.  
  72.     (al-string-to-ascii-list aString)) )
  73.  
  74. ;;---------
  75. ;; MAIN DRIVER
  76. ;;---------
  77. ( (lambda nil
  78.     ;; A very dumb driver; only gets one string
  79.     (parser (getstring "> "))
  80.     (princ "Strings: \t")
  81.     (mapcar 'princ StringExprAST)
  82.     (princ "\nPunct: \t")
  83.     (mapcar 'princ PunctExprAST)
  84.     (setq StringExprAST nil
  85.           PunctExprAST nil)) )