Re: converting a string to a list
- From: bjorn@xxxxxxx (Björn Lindberg)
- Date: Fri, 17 Jul 2009 10:23:36 +0200
ccc31807 <cartercc@xxxxxxxxx> writes:
On Jul 15, 11:38 am, bj...@xxxxxxx (Björn Lindberg) wrote:
The internal representation of data in your program is governed by
what kinds of operations you need to perform on that data, not on the
format of the input data, nor of the output.
Yes, and no. In one view, the internal representation of data is
simply bits of higher voltage or lower voltage, ones or zeros. If you
mean data structures, then obviously you might want to treat small
integers differently from instances of complex objects.
Ask yourself which one of these two views is most relevant to how you
write your program. Then ask yourself why you brought up the other
view at all.
Thus, if you need to do any form of structured
manipulations of the data, you convert it to a suitable format
first. As an example, a compiler might take strings as inputs, and
produce binary machine code as output, but it does not do all
computations internal computations on those two data types.
I agree with this, but one of the nice things about higher level
languages is that you can treat the compiler as a black box, without
regard to what the compiler might do internally. I input a string, the
box outputs a string; I input an s-expression, the box outputs an s-
expression. However the box treats the input internally is no concern
of mine, even though I might imagine that it treats it simply as bits
of either ones or zeros.
The comparison is between the compiler as a program and *your*
program. Regarding the compiler as a black box in this context does
not help understanding.
This advice is language independant, in that strings are unstructured
in any language.
I don't know what you mean by 'unstructured'.
In most languages, in particular in Common Lisp, the structure of a
string is a sequence of characters. Regardless of which specific
characters are in the string.
The following quote
delimited 'string' may or may not be structured, depending on your
POV:
"<html>
<head>
<title>Structure of Strings</title>
</head>
<body>
<h1>Strings: Structured or Unstructured?</h1>
</body>
</html>"
No, the structure of that string is a sequence of characters. Programs
exist to read in that string and turn it into a structured
representation, which might be a hierarchy of class instances, or
lists of lists of strings or atoms. This is the point.
Many times you can 'cheat', and use the Lisp reader. It is possible to
make it read case sensitively, and with reader macros make it read any
characters specially. If the input format is not at all Lisp though,
it may be simpler to do what you do in other languages, and read in
text character by character, or line by line.
Yes. Different tools for different problems. It helps for a learner to
relate what he is learning with his environment, which is what I'm
trying to do.
You mentioned that you deal with database output. Some SQL database
libraries for Common Lisp will return the result of a query as a list
of lists of the fields returned, and do data type conversion to basic
Lisp types:
(("John" "Doe" 28)
("Carter" "Ccc" 31807)
...)
Björn Lindberg
.
- Follow-Ups:
- Re: converting a string to a list
- From: Pascal J. Bourguignon
- Re: converting a string to a list
- References:
- converting a string to a list
- From: ccc31807
- Re: converting a string to a list
- From: fortunatus
- Re: converting a string to a list
- From: ccc31807
- Re: converting a string to a list
- From: Vassil Nikolov
- Re: converting a string to a list
- From: ccc31807
- Re: converting a string to a list
- From: Björn Lindberg
- Re: converting a string to a list
- From: ccc31807
- converting a string to a list
- Prev by Date: Re: collection of Erik Naggum's writings?
- Next by Date: Re: converting a string to a list
- Previous by thread: Re: converting a string to a list
- Next by thread: Re: converting a string to a list
- Index(es):
Relevant Pages
|
Loading