I am learning some dynamic languages such as python and CL using the
free version of CMUCL and python2.2
In terms of finding needed functions, I find, so far, that
python is easier for me to locate things.
For example, I wanted to find the corresponding function
int atoi(char * str)
In Python, I looked into the book: "Python, essential reference" by
David Beasley, and quickly found the string.atoi()
But in CMUCL, I looked into the online HyperSpec and could not find
the needed function. Using (apropos 'string) also did not help.
Is there a (CMU)CL book that is similar to David Beasley's Python reference?
Thanks,
HP
From: Kenny Tilton
Subject: Re: CL Counterpart of David Beasley's Python reference
Date:
Message-ID: <3C295296.98067BAB@nyc.rr.com>
HP wrote:
>
> I am learning some dynamic languages such as python and CL using the
> free version of CMUCL and python2.2
>
> In terms of finding needed functions, I find, so far, that
> python is easier for me to locate things.
>
no, with Python it is easier for you to locate C functions aped by
Python.
> For example, I wanted to find the corresponding function
> int atoi(char * str)
> In Python, I looked into the book: "Python, essential reference" by
> David Beasley, and quickly found the string.atoi()
again, that is not a sign of better documentation, that shows Python
copied C.
> But in CMUCL, I looked into the online HyperSpec and could not find
> the needed function. Using (apropos 'string) also did not help.
>
> Is there a (CMU)CL book that is similar to David Beasley's Python reference?
to beat a dead horse: no CL doc can change the fact that Lisp pre-dates
C and would not copy C anyway. Hell, C does not even /have/ a string
datatype.
Anyway, kudos for trying apropos. I had the exact same problem early on,
though I was looking for string-to-number, not atoi. I think it was bad
luck you stumbled onto a rare case where a generic read-from-string
(Lisp's atoi) does not turn up in the kind of search done by folks
accustomed to strongly static-typed languages. Most often apropos will
do the trick.
kenny
clinisys
Kenny Tilton wrote:
> Anyway, kudos for trying apropos. I had the exact same problem early on,
> though I was looking for string-to-number, not atoi. I think it was bad
> luck you stumbled onto a rare case where a generic read-from-string
> (Lisp's atoi) does not turn up in the kind of search done by folks
> accustomed to strongly static-typed languages. Most often apropos will
> do the trick.
PARSE-INTEGER is better suited for that purpose than READ-FROM-STRING.
ciao,
Jochen
--
http://www.dataheaven.de
In article <···························@posting.google.com>, HP wrote:
>I am learning some dynamic languages such as python and CL using the
>free version of CMUCL and python2.2
>
>In terms of finding needed functions, I find, so far, that
>python is easier for me to locate things.
>
>For example, I wanted to find the corresponding function
> int atoi(char * str)
You won't find such a thing in Lisp; the C function atoi() invokes
undefined behavior if the result of the conversion cannot be represented
in the type int.
What you are looking for is the function parse-integer.
>In Python, I looked into the book: "Python, essential reference" by
You did that in Python? ;)
>David Beasley, and quickly found the string.atoi()
You were only able to find this quickly because it happens to have
the same name as the C function you already know, and because it's
in a string package, which perhaps happens to coincide with your
expectation about where it should be.
In the HyperSpec, parse-integer is described the Numbers chapter
rather than the Strings chapter.
Thank you for those who replied to my query.
Yes, I have the mind-set of a C/C++ user when I
start to explore cmucl and python.
I agree that python inherits a lot of C stuff under
its surface. That explains why I was able to get some
quick and dirty (small) tasks done using python.
Though I am only a beginner in CL, I like certain aspects
of expressiveness in the context of abstraction in CL.
(e.g. I still could not find ways to manipulate the symbol
itself in python...
hm, perhaps, I am just a beginner in python.)
Thank you again. I will come back with more questions.
(and I will get a copy of P. Graham's ANSI CL book.)
HP
HP wrote:
>Yes, I have the mind-set of a C/C++ user when I
>start to explore cmucl and python.
>I agree that python inherits a lot of C stuff under
>its surface. That explains why I was able to get some
>quick and dirty (small) tasks done using python.
>
>Though I am only a beginner in CL, I like certain aspects
>of expressiveness in the context of abstraction in CL.
>(e.g. I still could not find ways to manipulate the symbol
> itself in python...
> hm, perhaps, I am just a beginner in python.)
So one should really write an clib based index onto the CL counterparts.
Yes, I am serious.
--
Reini Urban
http://tv.mur.at/film/
From: Duane Rettig
Subject: Re: CL Counterpart of David Beasley's Python reference
Date:
Message-ID: <4adw5zxjg.fsf@beta.franz.com>
··@rentec.com (HP) writes:
> I am learning some dynamic languages such as python and CL using the
> free version of CMUCL and python2.2
>
> In terms of finding needed functions, I find, so far, that
> python is easier for me to locate things.
>
> For example, I wanted to find the corresponding function
> int atoi(char * str)
> In Python, I looked into the book: "Python, essential reference" by
> David Beasley, and quickly found the string.atoi()
> But in CMUCL, I looked into the online HyperSpec and could not find
> the needed function. Using (apropos 'string) also did not help.
If you're really looking for atoi functionality, then you should use
it (though the name really makes no sense - I never understood why
they chose the 'a' in atoi, which makes it a misnomer when the C
library is ported to EBCDIC machines, or to machines with any
other character encodings). The foreign-function interface
defined by your lisp makes these C library functions available
trivially - here it is in Allegro CL:
CL-USER(2): (ff:def-foreign-call atoi ((str (* :char))))
Warning: A runtime with-native-string call is being generated for
argument `STR' to the foreign-function `ATOI'. The
with-native-string macro can be used for explicit string
conversions around the foreign calls. This warning is
suppressed when :STRINGS-CONVERT is specified in the
def-foreign-call.
ATOI
CL-USER(3): #x70000000
1879048192
CL-USER(4): (format t "~x" 1879048192)
70000000
NIL
CL-USER(5):
However, beware that atoi is buggy on some operating systems (I'm
working with Linux here), and latches values that barely overflow to
that of a useless number, instead of wrapping to a value from which the
magnitude can be extracted:
CL-USER(5): (atoi "1879048192")
1879048192
CL-USER(6): #x90000000
2415919104
CL-USER(7): (atoi "2415919104")
2147483647
CL-USER(8): (format t "~x" 2147483647)
7fffffff
NIL
CL-USER(9):
On Solaris, for example, the value returned is -1879048192,
which is wrapped around due to the two's complement, and from
which the #x90000000 can be reconstructed.
Personally, I much prefer solving Common Lisp problems within
Common Lisp:
CL-USER(9): (parse-integer "2415919104")
2415919104
10
CL-USER(10):
No fuss, no bother. And the name seems a little more mnemonic to me.
--
Duane Rettig Franz Inc. http://www.franz.com/ (www)
1995 University Ave Suite 275 Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253 ·····@Franz.COM (internet)
On 25 Dec 2001 20:02:09 -0800, ··@rentec.com (HP) wrote:
> Is there a (CMU)CL book that is similar to David Beasley's Python reference?
You may have a look at the EncyCMUCLopedia mentioned in my signature. Note
that the URL in square brackets is currently inactive.
Paolo
--
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://web.mclink.it/amoroso/ency/README
[http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/]