From: Rüdiger Sonderfeld
Subject: two questions about strings
Date: 
Message-ID: <ahuso6$rhm$03$1@news.t-online.com>
hi,
I'm new to common lisp and I have some problems with strings.

1) How can I get the size of a string?

Something like

>(strlen "hiho")
 4

2) How can I get the code to a char?

Something like

>(code #\a)
 1

or what you can do in C(++) with a simple convertation from a char to an 
integer

int code=(int)'a';

From: Thomas F. Burdick
Subject: Re: two questions about strings
Date: 
Message-ID: <xcv8z3xuect.fsf@apocalypse.OCF.Berkeley.EDU>
R�diger Sonderfeld <·············@gmx.net> writes:

> 2) How can I get the code to a char?
> 
> Something like
> 
> >(code #\a)
>  1

CHAR-CODE takes a character and returns a number.
CODE-CHAR does the inverse.

You might also be interested in CHAR=, CHAR<, CHAR>, etc., depending
on why you want this.  Be sure to check:

  <http://www.xanalys.com/software_tools/reference/HyperSpec/Body/13_af.htm>

to learn about the guarantees of character ordering, if you have any
interest at all in portability.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Rüdiger Sonderfeld
Subject: Re: two questions about strings
Date: 
Message-ID: <ahv31f$kvv$07$1@news.t-online.com>
Thomas F. Burdick wrote:
> You might also be interested in CHAR=, CHAR<, CHAR>, etc., depending
> on why you want this.  Be sure to check:

I wrote this function

(defun isupper(x)
  (if (and (char>= x #\A) (char<= x #\Z)) 
    t (return-from isupper))
  nil)

but it always returns nil :(

(isupper #\A)
 NIL
(isupper #\a)
 NIL

(defun isupper (x)
  (if (and (>= (char-code x) (char-code #\A)) (<= (char-code x) (char-code 
#\Z))) 
      t (return-from isupper))) 
  nil)

(isupper #\A)
 T
(isupper #\a)
 NIL

this function works. 

What's wrong?
From: Thomas F. Burdick
Subject: Re: two questions about strings
Date: 
Message-ID: <xcv4rekvomp.fsf@apocalypse.OCF.Berkeley.EDU>
R�diger Sonderfeld <·············@gmx.net> writes:

> Thomas F. Burdick wrote:
> > You might also be interested in CHAR=, CHAR<, CHAR>, etc., depending
> > on why you want this.  Be sure to check:
> 
> I wrote this function
> 
> (defun isupper(x)
>   (if (and (char>= x #\A) (char<= x #\Z)) 
>     t (return-from isupper))
>   nil)
> 
> but it always returns nil :(

Of course, it does exactly what you told it to:

  (defun isupper (x)
    (if (and ...)
        t
        (return-from isupper)
    nil))

If the condition is true, the value of the IF form is T, which is then
discarded, and NIL is returned.  If the condition is not true, then
you explicitly return NIL.

What you want is something like:

  (defun isupper (x)
    (if (and ...)
        t
        nil))

Although, if you read the link in my previous message, you'll see that
this isn't guaranteed to work.  Besides, it's already built in:
UPPER-CASE-P.

> (defun isupper (x)
>   (if (and (>= (char-code x) (char-code #\A)) (<= (char-code x) (char-code 
> #\Z))) 
>       t (return-from isupper))) 
>   nil)

Dear lord, please use Emacs to format your code for you (M-q).  This
is the Lisp equivalent of the C:

  if (foo)
    bar(f);
  else
    bar(f);
    baz(f);

That function should be indented as:

  ;; one form
  (defun isupper (x)
    (if (and (>= (char-code x) (char-code #\A))
             (<= (char-code x) (char-code #\Z)))
        t
        (return-from isupper)))
  ;; end of defun, followed by another form
  nil
  ;; stray close paren
  )

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Nils Goesche
Subject: Re: two questions about strings
Date: 
Message-ID: <87wurgq241.fsf@darkstar.cartan>
R�diger Sonderfeld <·············@gmx.net> writes:

> Thomas F. Burdick wrote:
> > You might also be interested in CHAR=, CHAR<, CHAR>, etc., depending
> > on why you want this.  Be sure to check:
> 
> I wrote this function
> 
> (defun isupper(x)
>   (if (and (char>= x #\A) (char<= x #\Z)) 
>     t (return-from isupper))
>   nil)
> 
> but it always returns nil :(

That's because you told it to :-)

(defun isupper(x)
  (if (and (char>= x #\A) (char<= x #\Z)) 
      (return-from isupper t))
    nil)

would work, as would

(defun isupper (x)
  (if (and (char>= x #\A) (char<= x #\Z))
      t
    nil))

or simply

(defun isupper (char)
  (char<= #\A char #\Z))

> (isupper #\A)
>  NIL
> (isupper #\a)
>  NIL
> 
> (defun isupper (x)
>   (if (and (>= (char-code x) (char-code #\A)) (<= (char-code x) (char-code 
> #\Z))) 
>       t (return-from isupper))) 
>   nil)
> 
> (isupper #\A)
>  T
> (isupper #\a)
>  NIL
> 
> this function works. 
> 
> What's wrong?

Your RETURN-FROM form really is in the else clause of your IF form.

Regards,
-- 
Nils Goesche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xC66D6E6F
From: Nils Goesche
Subject: Re: two questions about strings
Date: 
Message-ID: <87sn24q1y4.fsf@darkstar.cartan>
Nils Goesche <···@cartan.de> writes:

> R�diger Sonderfeld <·············@gmx.net> writes:
> 
> > Thomas F. Burdick wrote:
> > > You might also be interested in CHAR=, CHAR<, CHAR>, etc., depending
> > > on why you want this.  Be sure to check:
> > 
> > I wrote this function
> > 
> > (defun isupper(x)
> >   (if (and (char>= x #\A) (char<= x #\Z)) 
> >     t (return-from isupper))
> >   nil)
> > 
> > but it always returns nil :(
> 
> That's because you told it to :-)
> 
> (defun isupper (x)
>   (if (and (char>= x #\A) (char<= x #\Z)) 
>       (return-from isupper t))
>     nil)
> 
> would work,

but only by accident; I meant

(defun isupper (x)
  (if (and (char>= x #\A) (char<= x #\Z)) 
      (return-from isupper t)
    nil))

Another reason to write Lisp code in Emacs' lisp-mode...

Regards,
-- 
Nils Goesche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xC66D6E6F
From: Vijay L
Subject: Re: two questions about strings
Date: 
Message-ID: <1eaf81aa.0207271939.6f6a048f@posting.google.com>
Nils Goesche <···@cartan.de> wrote in message news:<··············@darkstar.cartan>...
> Nils Goesche <···@cartan.de> writes:
> 
> > R�diger Sonderfeld <·············@gmx.net> writes:
> > 
> > > Thomas F. Burdick wrote:
> > > > You might also be interested in CHAR=, CHAR<, CHAR>, etc., depending
> > > > on why you want this.  Be sure to check:
> > > 
> > > I wrote this function
> > > 
> > > (defun isupper(x)
> > >   (if (and (char>= x #\A) (char<= x #\Z)) 
> > >     t (return-from isupper))
> > >   nil)
> > > 
> > > but it always returns nil :(
> > 
> > That's because you told it to :-)
> > 
> > (defun isupper (x)
> >   (if (and (char>= x #\A) (char<= x #\Z)) 
> >       (return-from isupper t))
> >     nil)
> > 
> > would work,
> 
> but only by accident; I meant
> 
> (defun isupper (x)
>   (if (and (char>= x #\A) (char<= x #\Z)) 
>       (return-from isupper t)
>     nil))

why do you even use RETURN-FROM in function? the IF is the last (and
only) form in the function.

Thanks,
Vijay
From: Rainer Joswig
Subject: Re: two questions about strings
Date: 
Message-ID: <joswig-D8F296.11232928072002@news.fu-berlin.de>
In article <····························@posting.google.com>,
 ······@lycos.com (Vijay L) wrote:

> Nils Goesche <···@cartan.de> wrote in message news:<··············@darkstar.cartan>...
> > Nils Goesche <···@cartan.de> writes:
> > 
> > > R�diger Sonderfeld <·············@gmx.net> writes:
> > > 
> > > > Thomas F. Burdick wrote:
> > > > > You might also be interested in CHAR=, CHAR<, CHAR>, etc., depending
> > > > > on why you want this.  Be sure to check:
> > > > 
> > > > I wrote this function
> > > > 
> > > > (defun isupper(x)
> > > >   (if (and (char>= x #\A) (char<= x #\Z)) 
> > > >     t (return-from isupper))
> > > >   nil)
> > > > 
> > > > but it always returns nil :(
> > > 
> > > That's because you told it to :-)
> > > 
> > > (defun isupper (x)
> > >   (if (and (char>= x #\A) (char<= x #\Z)) 
> > >       (return-from isupper t))
> > >     nil)
> > > 
> > > would work,
> > 
> > but only by accident; I meant
> > 
> > (defun isupper (x)
> >   (if (and (char>= x #\A) (char<= x #\Z)) 
> >       (return-from isupper t)
> >     nil))
> 
> why do you even use RETURN-FROM in function? the IF is the last (and
> only) form in the function.
> 
> Thanks,
> Vijay

Get rid of the IF...

(defun isupper (x)
  (char<= #\A x #\Z))
From: Nils Goesche
Subject: Re: two questions about strings
Date: 
Message-ID: <87y9bwdk6y.fsf@darkstar.cartan>
······@lycos.com (Vijay L) writes:

> Nils Goesche <···@cartan.de> wrote in message news:<··············@darkstar.cartan>...
> > (defun isupper (x)
> >   (if (and (char>= x #\A) (char<= x #\Z)) 
> >       (return-from isupper t)
> >     nil))
> 
> why do you even use RETURN-FROM in function? the IF is the last (and
> only) form in the function.

Because the OP used RETURN-FROM incorrectly.  My last suggestion
in my first follow-up was

(defun isupper (char)
  (char<= #\A char #\Z))

Regards,
-- 
Nils Goesche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xC66D6E6F
From: Erik Naggum
Subject: Re: two questions about strings
Date: 
Message-ID: <3236870273259433@naggum.net>
* Nils Goesche
| (defun isupper (char)
|   (char<= #\A char #\Z))

  Despite all the good intentions and efforts to help this lost newbie, I think
  it is a mistake to try to help people who ask such questions.  (This reply is
  not directed specifically towards Nils.)

  Defining your own because the standard function does not have the same name
  as in C is wrong.  We already have upper-case-p, lower-case-p, alpha-char-p,
  etc, in Common Lisp.  Reinventing wheels to look more like C will do nobody
  any good.  Even asking for strlen and isupper is extremely counterproductive.

  People who ask for help in Common Lisp but refuse to relinquish their past
  language remind that I want to learn French, but only to hear it and read it.
  The utter helplessness of most French-speakers' attempt to produce English is
  so grating on my ears that I not only would like to be relieved of listening
  to it, speaking their language to them would probably be just as atrocious
  (almost like pronouncing "fromage" like "fromidge").

  The original poster has no problem with strings, he has a problem with his
  willingness to learn Common Lisp.  Much could be said about this affliction
  of the mind that causes people to assume that what they do not understand
  does not matter, that they have reached such a level of omniscience that they
  no longer need to observe and listen and learn.  Having learned enough, some
  people evidently stop learning altogether.  What they learned first is the
  standard for everything that comes later.  That the probably only _truly_
  random element in anyone's life is the order in which they experience things,
  seems not even to be underststandable -- they somehow believe that the order
  they run into them is universalizable and important, that first impressions
  really tell you everything you need to know about something.  I have seen
  people who have the mental capacity only for the transition from "have not
  experienced" to "have experienced", and who are unable to make a distinction
  between their observations and their conclusions, such that they are unable
  to change their conclusions about what they observed.  They walk around like
  they had CD-Rs for brains.

  What is the length of a string?  C's string representation has no room for an
  allocated length vs an active length.  C's string representation has no
  concept of substrings.  C's strings cannot contain all possible characters.
  C's strlen is actually (position 0 <string> :key #'char-code) and is O(n).
  
  Forget "strlen".  For our immediate purposes, there is no "strlen".  "strlen"
  does not _exist_.

  Common Lisp has vectors with fill-points, and strings are vectors which are
  sequences and arrays.  Numerous functions that in other languages only work
  on strings, work on sequences in Commo Lisp.  Functions like search, match,
  find, position, etc, are much more general than string functions in other
  languages.  A string with a fill-pointer has a total and an active length.
  Most sequence functions accept bounding indices, start and end indices that
  make it possible to use substrings without modifying the target strings.
  Common Lisp even has displaced arrays if you really need a substring without
  copying the string contents.  Common Lisp has string-streams to read from and
  write to strings in memory.  Common Lisp has real charcters, not just small
  integers.  Common Lisp's characters are not bytes, so when Unicode came
  along, there was no need to make extensive library and language changes.
  Common Lisp supports base and extended characters and hence base-string in
  addition to the general string.

  Common Lisp is a big-city language.  Spit out the hayseed, pronounce "shit"
  with one syllable and "shotgun" with two.  You're not in Kansas, anymore.  C
  is the language of the poor farmer village where the allocation of every seed
  and livestock matters, where taxes are low and public service non-existent.
  Appreciating the value of a large language is evidently hard for many people,
  just like many people find themselves miserable in the big city and go to
  great lengths to create a small village for themselves in the city where
  everything is like it used to be where they came from.  Common Lisp can
  accomodate people who want to program in any old language and re-create what
  they are used to, but if they want to get the most ouf ot it, the only way to
  do it is to adapt to the language and accept that somebody else may be better
  than you are at designing languages.

-- 
Erik Naggum, Oslo, Norway   *****   One manslaughter is another man's laughter.

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Nils Goesche
Subject: Re: two questions about strings
Date: 
Message-ID: <lkit2zlgoz.fsf@pc022.bln.elmeg.de>
Erik Naggum <····@naggum.net> writes:

> * Nils Goesche
> | (defun isupper (char)
> |   (char<= #\A char #\Z))
> 
>   Despite all the good intentions and efforts to help this lost
>   newbie, I think it is a mistake to try to help people who ask such
>   questions.  (This reply is not directed specifically towards
>   Nils.)
> 
>   Defining your own because the standard function does not have the
>   same name as in C is wrong.  We already have upper-case-p,
>   lower-case-p, alpha-char-p, etc, in Common Lisp.  Reinventing
>   wheels to look more like C will do nobody any good.  Even asking
>   for strlen and isupper is extremely counterproductive.

I understand what you're saying and actually agree with you, as far as
newbies are concerned.  That's precisely why I so strongly oppose
using the word ``pointer'' when explaining anything about Lisp.  If
you tell a newbie ``When you pass a cons cell to a function, what
really gets passed is a pointer to the cell, not the cell itself'' or
some such, you are only encouraging him to continue to think in C
terms like pointers and memory locations, instead of Lisp terms like
bindings and objects with identity.  The result will be yet another
one who thinks Lisp is call-by-reference.  So, when a newbie asks a
question thereby revealing that he is still thinking in wrong terms,
it is not right to tell him how to achieve whatever stupid thing he is
trying to do, but one should rather set him straight about his terms
and desires.

However, in this case, the OP wasn't even able to use IF and
RETURN-FROM correctly, something he should be capable of doing, had he
only read the first few pages of an introductory Lisp text.  My
conclusion was that he hasn't even started learning Lisp yet but is
still only playing around with it, so I wouldn't even call him a
newbie :-)  Often when we encounter something new, we want to play
around with it immediately.  Of course, we could start learning how to
use it properly right away, but playing around with something new is a
natural human desire, I think.  Sometimes I give in, sometimes not.
When I buy something new like a DVD player, I sometimes read the
manual right away, or first play around with it and read the manual
then.  Sometimes, when I learn a new programming language, I read its
definition right away, as I did with SML or Java, for instance, and
sometimes I first play around with it, as I did with Lisp or OCaml.

As long as you are only playing around with something, you don't want
to hear long explanations about your misconceptions because listening
and thinking much would mean that you've stopped playing and have
started learning.  Some people think this ``playing phase'' should be
omitted altogether because all it does is forming bad habits.  Well,
maybe.  But it's also fun :-) And it might make somebody curious
enough that he really starts learning.  How dangerous it is depends
strongly on whether he is willing to give up old beliefs and
misconceptions, then.  When we see that somebody isn't willing to drop
his old beliefs, we should scold him until he does, but only after he
has actually started learning, I think.

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9
From: Rüdiger Sonderfeld
Subject: Re: two questions about strings
Date: 
Message-ID: <ai308k$kq3$06$2@news.t-online.com>
Nils Goesche wrote:
> However, in this case, the OP wasn't even able to use IF and
> RETURN-FROM correctly, something he should be capable of doing, had he
> only read the first few pages of an introductory Lisp text.  

I read a tutorial.

> My conclusion was that he hasn't even started learning Lisp yet but is
> still only playing around with it, so I wouldn't even call him a
> newbie :-)

I want to test Common Lisp. If Common Lisp is what I need I will learn it 
really.

> As long as you are only playing around with something, you don't want
> to hear long explanations about your misconceptions because listening
> and thinking much would mean that you've stopped playing and have
> started learning.  

I want to hear long explanations because so I can see if Common Lisp is 
what I want.
From: Nicolas Neuss
Subject: Re: two questions about strings
Date: 
Message-ID: <877kjeooch.fsf@ortler.iwr.uni-heidelberg.de>
R�diger Sonderfeld <·············@gmx.net> writes:

> > As long as you are only playing around with something, you don't want
> > to hear long explanations about your misconceptions because listening
> > and thinking much would mean that you've stopped playing and have
> > started learning.  
> 
> I want to hear long explanations because so I can see if Common Lisp is 
> what I want.

This is unfair to us who are not so newby as you are.  You obviously
want us to write an own tutorial for you who are too idle to find and
understand one.  I consider this as a form of trolling.  Please study

http://www.alu.org

and especially

http://www.psychologie.uni-trier.de:8000/projects/ELM/elmart.html

before you write in that impertinent way here.

Nicolas.

P.S.: By the way, there are several CL compilers written in CL.
From: Ruediger Sonderfeld
Subject: Re: two questions about strings
Date: 
Message-ID: <ai34m7$ilf$04$1@news.t-online.com>
Nicolas Neuss wrote:

> R�diger Sonderfeld <·············@gmx.net> writes:
> This is unfair to us who are not so newby as you are.  You obviously
> want us to write an own tutorial for you who are too idle to find and
> understand one.  

I don't want you to write a tutorial for me! I only said that i want to 
hear long explanations because you wrote that I don't wont to hear them.

> I consider this as a form of trolling. 
[...]
> before you write in that impertinent way here.

I didn't knew that asking a question about to simple Common Lisp functions 
and a code problem (okay it was a easy problem) is impertinence.
From: Nicolas Neuss
Subject: Re: two questions about strings
Date: 
Message-ID: <871y9mokx6.fsf@ortler.iwr.uni-heidelberg.de>
Ruediger Sonderfeld <·············@gmx.net> writes:

> Nicolas Neuss wrote:
> 
> > R�diger Sonderfeld <·············@gmx.net> writes:
> > This is unfair to us who are not so newby as you are.  You obviously
> > want us to write an own tutorial for you who are too idle to find and
> > understand one.  
> 
> I don't want you to write a tutorial for me! I only said that i want to 
> hear long explanations because you wrote that I don't wont to hear them.
> 
> > I consider this as a form of trolling. 
> [...]
> > before you write in that impertinent way here.
> 
> I didn't knew that asking a question about to simple Common Lisp functions 
> and a code problem (okay it was a easy problem) is impertinence.

It is also not far from impertinence to cite only what fits to ones
response.  The sentence to which I objected and which I find
impertinent is:

R�diger Sonderfeld <·············@gmx.net> writes:

> I want to hear long explanations because so I can see if Common Lisp is 
> what I want.

Again, and the last time: we all have other jobs to do than writing
you your own tutorial.

Nicolas.
From: Immanuel Litzroth
Subject: Re: two questions about strings
Date: 
Message-ID: <m28z3uoig2.fsf@enfocus.be>
>>>>> "Nicolas" == Nicolas Neuss <·············@iwr.uni-heidelberg.de> writes:
    Nicolas> Again, and the last time: we all have other jobs to do
    Nicolas> than writing you your own tutorial.

Why not get on with it it then, or did you feel morally obliged to
vent your displeasure?
Immanuel
From: Coby Beck
Subject: Re: two questions about strings
Date: 
Message-ID: <fzg19.682$sI2.427520@news20.bellglobal.com>
"Nicolas Neuss" <·············@iwr.uni-heidelberg.de> wrote in message
···················@ortler.iwr.uni-heidelberg.de...
> Ruediger Sonderfeld <·············@gmx.net> writes:
> It is also not far from impertinence to cite only what fits to ones
> response.  The sentence to which I objected and which I find
> impertinent is:
>
> R�diger Sonderfeld <·············@gmx.net> writes:
>
> > I want to hear long explanations because so I can see if Common Lisp is
> > what I want.
>
> Again, and the last time: we all have other jobs to do than writing
> you your own tutorial.
>

Usenet posting is a volunteer endeavour, we all know that.  Some will give
short answers, some long ones and the answers are for onlookers as much as
the OP.  There is no harm in asking anything, silence is the only
appropriate response to a question you think is too much work to answer.
This guy is new here and is not being a jerk about anything, let's give him
a break.

There is an opportunity for benefit for lots of us when people come and ask
elementary questions.  The intermediate people or even other newbies who
just learned something can make suggestions.  Lurkers will have their
questions answered for free.  More advanced people who have answered the
same question N times before can skip over it all unless a correction or
more subtle point comes up and then the fur flies and we all learn
something!

We need a bit more "live and let live" here in c.l.l and we'll all enjoy it
more.

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Nicolas Neuss
Subject: Re: two questions about strings
Date: 
Message-ID: <87y9bsmjj2.fsf@ortler.iwr.uni-heidelberg.de>
"Coby Beck" <·····@mercury.bc.ca> writes:

> Usenet posting is a volunteer endeavour, we all know that.  Some will give
> short answers, some long ones and the answers are for onlookers as much as
> the OP.  There is no harm in asking anything, silence is the only
> appropriate response to a question you think is too much work to answer.
> This guy is new here and is not being a jerk about anything, let's give him
> a break.
> 
> There is an opportunity for benefit for lots of us when people come and ask
> elementary questions.  The intermediate people or even other newbies who
> just learned something can make suggestions.  Lurkers will have their
> questions answered for free.  More advanced people who have answered the
> same question N times before can skip over it all unless a correction or
> more subtle point comes up and then the fur flies and we all learn
> something!
> 
> We need a bit more "live and let live" here in c.l.l and we'll all enjoy it
> more.

OK. Admitted.  I was only frightened to see another quarrel "Erik
against German newbie":-)

Nicolas.
From: Nicolas Neuss
Subject: Re: two questions about strings
Date: 
Message-ID: <87eldhmysa.fsf@ortler.iwr.uni-heidelberg.de>
I wrote:

> "Coby Beck" <·····@mercury.bc.ca> writes:
> 
> > [criticism deleted]
> 
> OK. Admitted.  I was only frightened to see another quarrel "Erik
> against German newbie":-)
> 
> Nicolas.

I reread my message and think that it needs some clarification.  With
"OK. Admitted." I mean that I should not have posted in this thread.
And to be clear for the rest: *In my opinion* the fault for past
battles between Erik and some newbies lies for the major part with the
newbies.  I do not want imply that Erik was attacking them without
reason.  Only a slight bump for him was intended which I hope he can
bear.

Nicolas.

P.S.: What I learned from burning my fingers in this thread:

Rule 1: Do not do parallel news and mail conversation with some
person.

Rule 2: Remember that other persons may read a thread in a different
chronological order.

Rule 3: Do not post when you are in a hurry.

Rule 4: Do not assume too much context, especially when you are
posting with gaps of 1-2 days.

----------------------------------------------------------------
* end-of-thread * (at least for me)
From: Coby Beck
Subject: Re: two questions about strings
Date: 
Message-ID: <q9g19.674$sI2.422991@news20.bellglobal.com>
"Ruediger Sonderfeld" <·············@gmx.net> wrote in message
····················@news.t-online.com...
> Nicolas Neuss wrote:
>
> > R�diger Sonderfeld <·············@gmx.net> writes:
> > This is unfair to us who are not so newby as you are.  You obviously
> > want us to write an own tutorial for you who are too idle to find and
> > understand one.
>
> I don't want you to write a tutorial for me! I only said that i want to
> hear long explanations because you wrote that I don't wont to hear them.
>
> > I consider this as a form of trolling.
> [...]
> > before you write in that impertinent way here.
>
> I didn't knew that asking a question about to simple Common Lisp functions
> and a code problem (okay it was a easy problem) is impertinence.

I don't think you've been impertinent.  There will always be people reacting
badly, it may be their fault or yours, but can usually still be a
constructive learning experience.  It never pays to dwell on it though, just
move on (as should anyone who sees some "impertinence" in what you asked,
real or not)

Welcome to Common Lisp and to comp.lang.lisp

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: JB
Subject: Re: two questions about strings
Date: 
Message-ID: <3d46f1d1_6@news.newsgroups.com>
Ruediger Sonderfeld wrote:

> Nicolas Neuss wrote:
> 
>> R�diger Sonderfeld <·············@gmx.net> writes:
>> This is unfair to us who are not so newby as you are. 
>> You obviously want us to write an own tutorial for you
>> who are too idle to find and understand one.
> 
> I don't want you to write a tutorial for me! I only said
> that i want to hear long explanations because you wrote
> that I don't wont to hear them.
> 
>> I consider this as a form of trolling.
> [...]
>> before you write in that impertinent way here.
> 
> I didn't knew that asking a question about to simple
> Common Lisp functions and a code problem (okay it was a
> easy problem) is impertinence.

You are not alone. Many people have had the same experience: 
They came to c.l.l and wanted to find out about CL. Then 
they experienced the very same warm welcome you already 
know.
Just do not care! Carry on playing with CL and ask 
questions. Simply disregard the malicious responses. This 
news group is extremely knowledgable (well, it used to 
be..) and you can learn a lot here.

You were not impertinent. Maybe it was a bit inpolite when 
you wrote, that you *wanted* to have long explanations 
instead of another word, but it is all right.
C is an extremely good and successful language, maybe second 
only to BASIC. But CL is different and even if you decide 
against CL in the end, you may learn a lot by playing with 
it.

-- 
Janos Blazi


-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
   http://www.newsfeed.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
From: Immanuel Litzroth
Subject: Re: two questions about strings
Date: 
Message-ID: <m2vg6yq5do.fsf@enfocus.be>
>>>>> "Erik" == Erik Naggum <····@naggum.net> writes:

    Erik> * Nils Goesche | (defun isupper (char) | (char<= #\A char
    Erik> #\Z))

    Erik>   Despite all the good intentions and efforts to help this
    Erik> lost newbie, I think it is a mistake to try to help people
    Erik> who ask such questions.  (This reply is not directed
    Erik> specifically towards Nils.)

        
    Erik>   Defining your own because the standard function does not
    Erik> have the same name as in C is wrong.  We already have
    Erik> upper-case-p, lower-case-p, alpha-char-p, etc, in Common
    Erik> Lisp.  Reinventing wheels to look more like C will do nobody
    Erik> any good.  Even asking for strlen and isupper is extremely
    Erik> counterproductive.

Where did you pick up the idea that anyone is defining functions
"because the standard function does not have the same name as in C"? 
Another reason could be: let's take a function whose semantics I
know, try to implement it in lisp and see what the differences there
are. 
Immanuel
From: Rüdiger Sonderfeld
Subject: Re: two questions about strings
Date: 
Message-ID: <ai31gb$mbh$06$1@news.t-online.com>
Immanuel Litzroth wrote:
> Where did you pick up the idea that anyone is defining functions
> "because the standard function does not have the same name as in C"?
> Another reason could be: let's take a function whose semantics I
> know, try to implement it in lisp and see what the differences there
> are.

you are right!
From: Rüdiger Sonderfeld
Subject: Re: two questions about strings
Date: 
Message-ID: <ai301g$kq3$06$1@news.t-online.com>
Erik Naggum wrote:
>   Despite all the good intentions and efforts to help this lost newbie, I
>   think
>   it is a mistake to try to help people who ask such questions.  (This
>   reply is not directed specifically towards Nils.)
> 
>   Defining your own because the standard function does not have the same
>   name
>   as in C is wrong.  

I don't want to write my own upper-case-p function because they use 
different names in C! I only want to test the language. My first poor 
steps. And the string part in the tutorial I read is very short (I read the 
LISP-tutorial.txt that I found in the clisp release documentation).

So I thought it is no problem to ask here and I asked for the C functions 
because I hoped that everybody will understand me!

>   Reinventing wheels to look more like C will do nobody
>   any good.  

you are right. But I only want to test the language (play with it a little 
bit) and so I wrote some uninteressting functions! I didn't want to write a 
big program looking like C!

>   People who ask for help in Common Lisp but refuse to relinquish their
>   past language

I don't want to relinquish my past language! I want to learn lisp for 
additional use!

And I thought it isn't a problem to use the name of the C functions so that 
it is easier to understand what I mean!
 
>   The original poster has no problem with strings, he has a problem with
>   his
>   willingness to learn Common Lisp.  

No! I read a tutorial! And I only want to play with Common Lisp because I 
want to know if common lisp is the language I need.

>   Much could be said about this
>   affliction of the mind that causes people to assume that what they do
>   not understand does not matter, that they have reached such a level of
>   omniscience that they
>   no longer need to observe and listen and learn.  Having learned enough,
>   some
>   people evidently stop learning altogether.  What they learned first is
>   the
>   standard for everything that comes later.  That the probably only
>   _truly_ random element in anyone's life is the order in which they
>   experience things, seems not even to be underststandable -- they somehow
>   believe that the order they run into them is universalizable and
>   important, that first impressions
>   really tell you everything you need to know about something.  I have
>   seen people who have the mental capacity only for the transition from
>   "have not experienced" to "have experienced", and who are unable to make
>   a distinction between their observations and their conclusions, such
>   that they are unable
>   to change their conclusions about what they observed.  They walk around
>   like they had CD-Rs for brains.

I don't think I have learned enough!

>   What is the length of a string?  C's string representation has no room
>   for an allocated length vs an active length.
>  C's string representation has no
>   concept of substrings.  C's strings cannot contain all possible
>   characters. C's strlen is actually (position 0 <string> :key
>   #'char-code) and is O(n).
>   
>   Forget "strlen".  For our immediate purposes, there is no "strlen". 
>   "strlen" does not _exist_.
> 
>   Common Lisp has vectors with fill-points, and strings are vectors which
>   are
>   sequences and arrays.  Numerous functions that in other languages only
>   work
>   on strings, work on sequences in Commo Lisp.  Functions like search,
>   match, find, position, etc, are much more general than string functions
>   in other
>   languages.  A string with a fill-pointer has a total and an active
>   length. Most sequence functions accept bounding indices, start and end
>   indices that make it possible to use substrings without modifying the
>   target strings. Common Lisp even has displaced arrays if you really need
>   a substring without
>   copying the string contents.  Common Lisp has string-streams to read
>   from and
>   write to strings in memory.  Common Lisp has real charcters, not just
>   small
>   integers.  Common Lisp's characters are not bytes, so when Unicode came
>   along, there was no need to make extensive library and language changes.
>   Common Lisp supports base and extended characters and hence base-string
>   in addition to the general string.
> 
>   Common Lisp is a big-city language.  Spit out the hayseed, pronounce
>   "shit"
>   with one syllable and "shotgun" with two.  You're not in Kansas,
>   anymore.  C is the language of the poor farmer village where the
>   allocation of every seed and livestock matters, where taxes are low and
>   public service non-existent. Appreciating the value of a large language
>   is evidently hard for many people, just like many people find themselves
>   miserable in the big city and go to great lengths to create a small
>   village for themselves in the city where
>   everything is like it used to be where they came from.  Common Lisp can
>   accomodate people who want to program in any old language and re-create
>   what they are used to, but if they want to get the most ouf ot it, the
>   only way to do it is to adapt to the language and accept that somebody
>   else may be better than you are at designing languages.

Oh C is so bad that you're OS and Common Lisp Interpreter is written in it.
From: Daniel Barlow
Subject: Re: two questions about strings
Date: 
Message-ID: <87d6t6q03m.fsf@noetbook.telent.net>
R�diger Sonderfeld <·············@gmx.net> writes:

> Oh C is so bad that you're OS and Common Lisp Interpreter is written in it.

Speak for yourself, but most of _my_ Common Lisp compiler (note:
`compiler', `not interpreter') is written in Common Lisp.   And the OS
is written in a variety of languages including C, Python, Perl and
several other Lisp and Lisp-like languages (rep, elisp, guile etc).


-dan

-- 

  http://ww.telent.net/cliki/ - Link farm for free CL-on-Unix resources 
From: Nils Goesche
Subject: Re: two questions about strings
Date: 
Message-ID: <lkeldmllvt.fsf@pc022.bln.elmeg.de>
R�diger Sonderfeld <·············@gmx.net> writes:

> Erik Naggum wrote:

> >   Defining your own because the standard function does not have
> >   the same name as in C is wrong.

> I don't want to write my own upper-case-p function because they use
> different names in C! I only want to test the language. My first
> poor steps. And the string part in the tutorial I read is very short
> (I read the LISP-tutorial.txt that I found in the clisp release
> documentation).

Nicolas gave you a URL of another one.

> So I thought it is no problem to ask here and I asked for the C
> functions because I hoped that everybody will understand me!
> 
> >   Reinventing wheels to look more like C will do nobody any good.
> 
> you are right. But I only want to test the language (play with it a
> little bit) and so I wrote some uninteressting functions! I didn't
> want to write a big program looking like C!
> 
> >   People who ask for help in Common Lisp but refuse to relinquish
> >   their past language
> 
> I don't want to relinquish my past language! I want to learn lisp
> for additional use!

Please make up your mind: Sometimes you say you want to learn it,
sometimes you say you only want to play around with it, then you say
you want to ``test'' it in order to find out if it is what you need.
Well, at least I can assure you that you won't find out that without
actually learning it.  Tutorials tell you how to play around with it,
they won't teach you much, if anything.  That's what they're for, I
think.  If you want to start learning, tutorials aren't good enough
anymore; get a book.  Which one is right for you is hard to say; maybe
Paul Graham's ANSI Common Lisp, or Stephen Slade's Object-Oriented
Common Lisp, or, if you find those too hard, try

  http://www-2.cs.cmu.edu/~dst/LispBook/

And find the HyperSpec to accompany them.

> And I thought it isn't a problem to use the name of the C functions
> so that it is easier to understand what I mean!

The point is another one, namely that in order to learn Lisp, you have
to stop thinking in C terms.  Learn Lisp in its own terms.  There are
people who try to map any new thing they learn about Lisp onto
something they already know from C, like ``Ah, in C, I would do that
in such-and-such way''.  That way doesn't work here, you won't learn a
thing as long as you try to do that.  /That's/ what Erik was concerned
about, and rightly so.

> >   The original poster has no problem with strings, he has a
> >   problem with his willingness to learn Common Lisp.
> 
> No! I read a tutorial! And I only want to play with Common Lisp
> because I want to know if common lisp is the language I need.

See above.

> >   I have seen people who have the mental capacity only for the
> >   transition from "have not experienced" to "have experienced",
> >   and who are unable to make a distinction between their
> >   observations and their conclusions, such that they are unable to
> >   change their conclusions about what they observed.  They walk
> >   around like they had CD-Rs for brains.
> 
> I don't think I have learned enough!

That's nice to hear.  So start learning and stop being so defensive :-)

> >   Common Lisp is a big-city language.  Spit out the hayseed,
> >   pronounce "shit" with one syllable and "shotgun" with two.
> >   You're not in Kansas, anymore.  C is the language of the poor
> >   farmer village where the allocation of every seed and livestock
> >   matters, where taxes are low and public service
> >   non-existent. Appreciating the value of a large language is
> >   evidently hard for many people, just like many people find
> >   themselves miserable in the big city and go to great lengths to
> >   create a small village for themselves in the city where
> >   everything is like it used to be where they came from.  Common
> >   Lisp can accomodate people who want to program in any old
> >   language and re-create what they are used to, but if they want
> >   to get the most ouf ot it, the only way to do it is to adapt to
> >   the language and accept that somebody else may be better than
> >   you are at designing languages.
> 
> Oh C is so bad that you're OS and Common Lisp Interpreter is written
> in it.

Erik Naggum is not exactly known as a CLISP user.  Most Common Lisp
systems compile into native machine code, and are not properly
described as ``Interpreters''.  And yes, C and C++ /are/ bad, that's
why many of us have come here.  Why don't you start learning and find
out for yourself? :-)

You'd better listen to him, rather than being sarcastic, and get on
with it.

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9
From: Ruediger Sonderfeld
Subject: Re: two questions about strings
Date: 
Message-ID: <ai3gab$udq$05$1@news.t-online.com>
Nils Goesche wrote:
> Nicolas gave you a URL of another one.

I found another interessting link and I start to read this online-book

http://www-2.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/cltl2.html
> Please make up your mind: Sometimes you say you want to learn it,
> sometimes you say you only want to play around with it, then you say
> you want to ``test'' it in order to find out if it is what you need.
> Well, at least I can assure you that you won't find out that without
> actually learning it.  Tutorials tell you how to play around with it,
> they won't teach you much, if anything.  That's what they're for, I
> think.  If you want to start learning, tutorials aren't good enough
> anymore; get a book.  Which one is right for you is hard to say; maybe
> Paul Graham's ANSI Common Lisp, or Stephen Slade's Object-Oriented
> Common Lisp, or, if you find those too hard, try
> 
>   http://www-2.cs.cmu.edu/~dst/LispBook/
> 
> And find the HyperSpec to accompany them.

I think I will learn Common Lisp from now on.

>> And I thought it isn't a problem to use the name of the C functions
>> so that it is easier to understand what I mean!
> 
> The point is another one, namely that in order to learn Lisp, you have
> to stop thinking in C terms.  Learn Lisp in its own terms.  There are
> people who try to map any new thing they learn about Lisp onto
> something they already know from C, like ``Ah, in C, I would do that
> in such-and-such way''.  That way doesn't work here, you won't learn a
> thing as long as you try to do that.  /That's/ what Erik was concerned
> about, and rightly so.

okay he is right

>> Oh C is so bad that you're OS and Common Lisp Interpreter is written
>> in it.
> 
> Erik Naggum is not exactly known as a CLISP user.  Most Common Lisp
> systems compile into native machine code, and are not properly
> described as ``Interpreters''.  And yes, C and C++ /are/ bad, that's
> why many of us have come here.  Why don't you start learning and find
> out for yourself? :-)

I only know clisp and clisp is mostly written in C. I thought that is
common to other implementations.

And I don't think you can compare C(++) and Common Lisp.
But we shouldn't discuss this!
 
> You'd better listen to him, rather than being sarcastic, and get on
> with it.

okay, you are right. I'm sorry. I think he's right that it is important to 
forget C(++) and other languages I know.
From: Nils Goesche
Subject: Re: two questions about strings
Date: 
Message-ID: <lkadoalflb.fsf@pc022.bln.elmeg.de>
Ruediger Sonderfeld <·············@gmx.net> writes:

> Nils Goesche wrote:
> > Nicolas gave you a URL of another one.
> 
> I found another interessting link and I start to read this online-book
> 
> [Link to CLTL2]

There are two problems with that book.  It's first edition was the
defining description of Common Lisp, committee approved, sometime in
1984, long before the ANSI standard was adopted (1994), like K&R1 in a
way.  It's second edition, however, appeared in 1990, when people were
still working on the ANSI standard.  It is not clear exactly which
language it describes, it is somewhere inbetween CLTL1 and ANSI Common
Lisp.  Moreover, it is not aimed at Lisp newbies, but looks more like
a quasi-standard.  If you want the language definition, you should get
the HyperSpec, which has exactly the same content as the ANSI
Standard:

 http://www.xanalys.com/software_tools/reference/HyperSpec/

Unlike K&R, neither CLTL nor the HyperSpec are very good introductions
to Lisp newbies.  Get the HyperSpec to look things up, and a textbook
to actually learn Lisp.  I've already recommended some.

> I only know clisp and clisp is mostly written in C. I thought that
> is common to other implementations.

Nope.

> And I don't think you can compare C(++) and Common Lisp.

How could you possibly know? :-)

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9
From: Paul D. Lathrop
Subject: Re: two questions about strings
Date: 
Message-ID: <Xns925AB0AD4515Epdlathrocharterminet@216.168.3.40>
Ruediger Sonderfeld <·············@gmx.net> wrote in
····················@news.t-online.com: 
> okay, you are right. I'm sorry. I think he's right that 
> it is important to forget C(++) and other languages I 
know.

More precisely, it is important to learn each language on 
it's own footing, and not try to map it onto another 
language you know. Don't *forget* the other languages, 
that would make the time you spent learning them into a 
waste. Rather, set them aside while you learn Lisp. Then 
you will be able to decide what language is the best tool 
for your needs. I think you will find that Common Lisp 
offers a superior set of tools. But you will only discover 
this if you learn to program Lisp, not C-in-Lisp. 

I do admit *my* first instinct when I learned my second 
programming language was to try to map it in the same way 
Erik spoke out against. However, I was fortunate enough to 
have been taught Lisp as my first programming language, so 
I was quickly broken of that habit. Lisp is unique. Try to 
familiarize yourself with that uniqueness instead of 
robbing yourself of it. 

Regards,
Paul D. Lathrop
From: Paolo Amoroso
Subject: Re: two questions about strings
Date: 
Message-ID: <=KhGPZ8hS3OzQzQhnwtNBalBfW55@4ax.com>
On Mon, 29 Jul 2002 12:55:08 +0200, R�diger Sonderfeld
<·············@gmx.net> wrote:

> I don't want to relinquish my past language! I want to learn lisp for 
> additional use!

"A language that doesn't affect the way you think about programming, is not
worth knowing." - Alan Perlis


> Oh C is so bad that you're OS and Common Lisp Interpreter is written in it.

For the record, there are both--excellent--operating systems and Lisp
development environments written in Lisp.


Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://www.paoloamoroso.it/ency/README
From: Peter Lewerin
Subject: Re: two questions about strings
Date: 
Message-ID: <3D470CF5.1060700@swipnet.se>
> I don't want to write my own upper-case-p function because they use 
> different names in C! I only want to test the language.


Well, if it works for you...  To me, it seems like a strange way to test 
or try out a new language.  When I do that, I usually implement a couple 
of language-independent specifications for simple applications, and do 
my best to use the conventions and idioms of the language in question.

After all, what I'd like to see is the new language in action, not the 
new language in old-language drag.

Just 0.02 Euro...
From: Kaz Kylheku
Subject: Re: two questions about strings
Date: 
Message-ID: <ahvnsc$j8o$1@luna.vcn.bc.ca>
In article <···············@news.t-online.com>, R�diger Sonderfeld wrote:
> Thomas F. Burdick wrote:
>> You might also be interested in CHAR=, CHAR<, CHAR>, etc., depending
>> on why you want this.  Be sure to check:
> 
> I wrote this function
> 
> (defun isupper(x)
>   (if (and (char>= x #\A) (char<= x #\Z)) 

You are assuming that the characters A through Z have consecutive
values, which happens to be true in ASCII and character systems derived from
it, like ISO-8859-<N> and UNICODE.

In any case, Lisp already has this predicate function, it is
called upper-case-p. You should study the HyperSpec to discover
what functions are available in Common Lisp.

>     t (return-from isupper))
>   nil)
> 
> but it always returns nil :(

That's because you told it to. The last form in the function is nil,
which is what is evaluated after the if form, unless the return-from
is evaluated, which also returns nil.

> (isupper #\A)
>  NIL
> (isupper #\a)
>  NIL
> 
> (defun isupper (x)
>   (if (and (>= (char-code x) (char-code #\A)) (<= (char-code x) (char-code 
> #\Z))) 
>       t (return-from isupper))) 

Here you have bad syntax, the function actually ends here.

>   nil)

And this is superfluous.
From: Nils Goesche
Subject: Re: two questions about strings
Date: 
Message-ID: <871y9pq7cv.fsf@darkstar.cartan>
R�diger Sonderfeld <·············@gmx.net> writes:

> 1) How can I get the size of a string?
> 
> Something like
> 
> >(strlen "hiho")
>  4

(length "hiho")

> 2) How can I get the code to a char?
> 
> Something like
> 
> >(code #\a)
>  1

(char-code #\a)

Regards,
-- 
Nils Goesche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xC66D6E6F
From: Rüdiger Sonderfeld
Subject: Re: two questions about strings
Date: 
Message-ID: <ahut97$6hq$06$1@news.t-online.com>
R�diger Sonderfeld wrote:
> 1) How can I get the size of a string?

Ups :)

(length "hiho")

is what I needed