Re: converting a string to a list



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
.



Relevant Pages

  • Re: Compare Instr() and IndexOf() performance
    ... The largest file is 780 kb, the format of the file is fixed length record ... (17 characters), I am always searching this files on first 10 characters ... but the contents of this file changes every ... If you just calculate the maximum number of string comparisions that may be ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Emulating String.Format compile-time functionality
    ... System.FormatException: Input string was not in a correct format. ... but I think a compiler should be sticking to ... the language specification - and the language spec *certainly* ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How many bytes per Italian character?
    ... to format an ANSI string, and yes, there's a possibility that it isn't implemented on CE, ... you went from a discussion about the number of bytes in Italian characters to a ... Remote Registry Editor rather than in Windows CE. ...
    (microsoft.public.vc.mfc)
  • Re: String parsing question
    ... >My task is to convert items in the third format to the first format, ... >in the string, which may or may not have a trailing semicolon. ... While I could count semicolons easily with strchr, ... your characters really are alphanums, ...
    (comp.lang.c)
  • Re: printf behaviour with illegal or malformed format string
    ... checking by GCC, but we cannot rely on the string being sane in libc, we still need to do error checking. ... All it can do is verify that two arbitrary format strings expect the same arguments and the documentation states it doesn't even manage that: The fmtcheckfunction does not understand all of the conversions that printfdoes. ... then any format that actually consumes the same arg types as the default will consume the ones passed. ... the compiler can't really do ...
    (freebsd-arch)

Loading