From: Bjoern Petri
Subject: simple string compare
Date: 
Message-ID: <9525fc52191a505a634ab1392ef43ea1.44739@mygate.mailgate.org>
Hello,

i just have to learn this programming language 
and i don't know how to solve the following problem:

I got a function which returned the following 
"No connection established. Online 3d-2d process impossible." 

I now just want to compare this string (here calles it1) like this (is there
something like member for strings):

(unless (AND (string<= it1 "No connection established") (string>= it1 "No
connection established"))
   (setf result NIL))



and so i got the error: 
"No connection established....." cannot be coerced to a string. It is really
logical, but I don't know how
to solve this little problems. And if I search in the Internet I find
everything, but not this little problem.



Thanxx,
 Bjoern


.. and don't laugh over my problems (in LISP and English!) :)


-- 
Posted from  [213.69.137.215] 
via Mailgate.ORG Server - http://www.Mailgate.ORG

From: Kent M Pitman
Subject: Re: simple string compare
Date: 
Message-ID: <sfw8zc5c0wn.fsf@shell01.TheWorld.com>
"Bjoern Petri" <········@gmx.de> writes:

> Hello,
> 
> i just have to learn this programming language 
> and i don't know how to solve the following problem:
> 
> I got a function which returned the following 
> "No connection established. Online 3d-2d process impossible." 
> 
> I now just want to compare this string (here calles it1) like this (is there
> something like member for strings):
> 
> (unless (AND (string<= it1 "No connection established") (string>= it1 "No
> connection established"))
>    (setf result NIL))

Case-sensitive:

(unless (search "No connection established" it1)
  ...)

Case-insensitive:

(unless (search "No connection established" it1 :test #'char-equal)
  ...)

If you want to assure that the string is at the start:

Case-sensitive:

(unless (string= "No connection established" it1
	         :end2 (min 25 (length it1)))
  ...)


Case-insensitive:

(unless (string-equal "No connection established" it1
	              :end2 (min 25 (length it1)))
  ...)


[Side comment:

I actually think the right arg to :end2 should just be 25 and not the
call to MIN, but some implementations blow up if you give them an end2
that is longer than the length of the string.  I think this is
pointless since there is thus never any valid call to this that
doesn't do the MIN and I'd rather see implementations do it than
users.

]


If you don't like the wired constant 25, you can also do:

 (let ((failure-phrase "No connection established"))
   (unless (string-equal failure-phrase it1 
		         :end2 (min (length failure-phrase) (length it1)))
     ...))

though this computes (length failure-phrase) newly at runtime every time
unless the compiler is smart enough to realize it can constant fold the
call to length.  Another option is the more visually cryptic:

 (unless (string-equal #1="No connection established" it1 
                       :end2 (min (length #1#) (length it1)))
     ...)

I'd like to tell you that:

 (unless (string-equal #1="No connection established" it1 
                       :end2 (min #.(length #1#) (length it1)))
     ...)

would work but I think most CL readers don't like #n= and #n# being used
over a #. boundary.  You could instead do:

 (unless #.(let ((failure-phrase "No connection established"))
             `(string-equal ,failure-phrase it1
                            :end2 (min ,(length failure-phrase)
                                       (length it1))))
   ...)
 
and get nearly optimal control of the time that everything evaluates, but
a lot of people might say this was overkill.  I mention it only for 
completeness and to show the versatility of Lisp syntax.

]


> and so i got the error: 
> "No connection established....." cannot be coerced to a string.

Is it possible that you are getting back an error object and not a string?
If so, PRINC-TO-STRING would coerce it to a string.  However, you're USUALLY
better of handling error objects as themselves since they are object-oriented.
You can dispatch on its type (whether a general type like ERROR or some 
more specific implementation-specific type like you probably have).

> It is really logical, but I don't know how
> to solve this little problems. And if I search in the Internet I find
> everything, but not this little problem.

The internet (by which I assume you really mean "the web") is full of
facts but not composed truths, nor of their implications

> .. and don't laugh over my problems (in LISP and English!) :)

We try not to.
From: James A. Crippen
Subject: Re: simple string compare
Date: 
Message-ID: <m3wuzma3n1.fsf@kappa.unlambda.com>
Kent M Pitman <······@world.std.com> writes:

> [...]  You could instead do:
> 
>  (unless #.(let ((failure-phrase "No connection established"))
>              `(string-equal ,failure-phrase it1
>                             :end2 (min ,(length failure-phrase)
>                                        (length it1))))
>    ...)
>  
> and get nearly optimal control of the time that everything evaluates, but
> a lot of people might say this was overkill.  I mention it only for 
> completeness and to show the versatility of Lisp syntax.

Oh stop it.  Any more of that and you'll make him think Lisp is no
better than Perl for readability.  ;-)

On a side note, the very first thing I came to love about Lisp was the
fact that with a good keyboard I didn't need to shift at all when
writing Lisp code.  In my mind this is the mark of a very clean and
well-designed language -- that it's easy to type.

It's this very reason that I despise Perl.  It's not only hard to
read, it's hard to type.  The same thing written in Perl may be twenty
or thirty characters shorter than that written in Lisp, but I can
still type the Lisp expression faster.

'james

-- 
James A. Crippen <·····@unlambda.com> ,-./-.  Anchorage, Alaska,
Lambda Unlimited: Recursion 'R' Us   |  |/  | USA, 61.20939N, -149.767W
Y = \f.(\x.f(xx)) (\x.f(xx))         |  |\  | Earth, Sol System,
Y(F) = F(Y(F))                        \_,-_/  Milky Way.
From: Bjoern Petri
Subject: Re: simple string compare
Date: 
Message-ID: <32e76804eb1e7111b49a687aaa1c8ce3.44739@mygate.mailgate.org>
Thanxx for your help!
Now it's working!

Bjoern


-- 
Posted from  [213.69.137.215] 
via Mailgate.ORG Server - http://www.Mailgate.ORG
From: Daniel Barlow
Subject: Re: simple string compare
Date: 
Message-ID: <87itb5u01l.fsf@noetbook.telent.net>
·····@unlambda.com (James A. Crippen) writes:

> It's this very reason that I despise Perl.  It's not only hard to
> read, it's hard to type.  The same thing written in Perl may be twenty
> or thirty characters shorter than that written in Lisp, but I can
> still type the Lisp expression faster.

You do know about xmodmap, I take it?


-dan

-- 

  http://ww.telent.net/cliki/ - Link farm for free CL-on-Unix resources 
From: James A. Crippen
Subject: Re: simple string compare
Date: 
Message-ID: <m3k7vlp6dn.fsf@kappa.unlambda.com>
Daniel Barlow <···@telent.net> writes:

> ·····@unlambda.com (James A. Crippen) writes:
> 
> > It's this very reason that I despise Perl.  It's not only hard to
> > read, it's hard to type.  The same thing written in Perl may be twenty
> > or thirty characters shorter than that written in Lisp, but I can
> > still type the Lisp expression faster.
> 
> You do know about xmodmap, I take it?

It takes most people about ten to fifteen minutes before they figure
out how my keyboard bindings work.  And under Emacs they lose even
more.

So, yes, I do.

I make a habit of swapping () and [], and if I have a PC-104 keyboard
I set up the Super, Meta, Control, Space, Control, Meta, Super, Hyper
bindings as found on a Symbolics keyboard.  I also like to swap
Backspace and Caps Lock.

Even with extra bindings to make typing all the ·@#$%^&*{} stuff
easier in Perl, I can still type Lisp faster, almost as fast as I can
type text.

'james

-- 
James A. Crippen <·····@unlambda.com> ,-./-.  Anchorage, Alaska,
Lambda Unlimited: Recursion 'R' Us   |  |/  | USA, 61.20939N, -149.767W
Y = \f.(\x.f(xx)) (\x.f(xx))         |  |\  | Earth, Sol System,
Y(F) = F(Y(F))                        \_,-_/  Milky Way.
From: Thomas F. Burdick
Subject: Re: simple string compare
Date: 
Message-ID: <xcvofkx0yp1.fsf@conquest.OCF.Berkeley.EDU>
Daniel Barlow <···@telent.net> writes:

> ·····@unlambda.com (James A. Crippen) writes:
> 
> > It's this very reason that I despise Perl.  It's not only hard to
> > read, it's hard to type.  The same thing written in Perl may be twenty
> > or thirty characters shorter than that written in Lisp, but I can
> > still type the Lisp expression faster.
> 
> You do know about xmodmap, I take it?

It's almost like Perl was designed for the French AZERTY keyboard
(where you shift to get numbers, and the symbols are unshifted).

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: James A. Crippen
Subject: Re: simple string compare
Date: 
Message-ID: <m3k7vk2svx.fsf@kappa.unlambda.com>
···@conquest.OCF.Berkeley.EDU (Thomas F. Burdick) writes:

> Daniel Barlow <···@telent.net> writes:
> 
> > ·····@unlambda.com (James A. Crippen) writes:
> > 
> > > It's this very reason that I despise Perl.  It's not only hard to
> > > read, it's hard to type.  The same thing written in Perl may be twenty
> > > or thirty characters shorter than that written in Lisp, but I can
> > > still type the Lisp expression faster.
> > 
> > You do know about xmodmap, I take it?
> 
> It's almost like Perl was designed for the French AZERTY keyboard
> (where you shift to get numbers, and the symbols are unshifted).

Perl wasn't designed, it congealed.  Perl exponents like to use the
term 'evolved', but I think 'congealed' connotes more of a random
accretion of features with no discernable sense of coherency.

One would guess that the French AZERTY keyboard would certainly
encourage the adoption of Perl.  But AFAICT the French actually seem
more inclined toward more logically designed languages, like Lisp,
Python, Java, etc.  Any French care to comment?

'james

-- 
James A. Crippen <·····@unlambda.com> ,-./-.  Anchorage, Alaska,
Lambda Unlimited: Recursion 'R' Us   |  |/  | USA, 61.20939N, -149.767W
Y = \f.(\x.f(xx)) (\x.f(xx))         |  |\  | Earth, Sol System,
Y(F) = F(Y(F))                        \_,-_/  Milky Way.