
On 3/09/2013, at 10:44 PM, Rustom Mody wrote:
Whoops! my bad -- I was *thinking* 'pipes' but ended up *writing* 'IPC' :-)
So let me restate more explicitly what I intended -- pipes, FIFOs, sockets, etc. IOW read/write/send/recv calls and the mathematical model represented by the (non-firstclass) pair of C data structures in those functions:
(or count).
Yes, but none of these have anything to do with strings.
"string" has a precise meaning in C:
7.1.1#1
A string is a contiguous sequence of characters
terminated by and including the first null character. The
term multibyte string is sometimes used instead of emphasize
special processing given to multibyte characters contained
in the string or to avoid confusion with a wide string. A
pointer to a string is a pointer to its initial (lowest
addressed) character. The length of a string is the number
of characters preceding the null character and the value of
a string is the sequence of the values of the contained
characters, in order.
7.1.1#6
(same as #1 but string->wide string and character->wide character)
If you are going to claim Humpty-Dumpty's privilege,
we cannot have a meaningful discussion.
Let me propose a more general definition of "string" which is
consistent with the three kinds of string natively supported by
the C
As an aside: modern usage types the buf as void * . The version 7 unix manuals on which I grew up (and first edition of K&R), there was no void; buf would be just 'char *buf; '
Version 7 did have void but did not have void *. Since void * and char * are required to have identical representations, this is a distinction without a difference. The point of the change was simply that any object pointer type can be converted to or from void * **without a cast**; using void * here is just POSIX telling the C compiler not to do any serious type checking.
I realize this is a terminology issue:
My usage of terminology like string/file are evidently more aligned to http://en.wikipedia.org/wiki/Vienna_Development_Method#Collections:_Sets.2C_... file(chap 4): http://red.cs.nott.ac.uk/~rxq/files/SpecificationCaseStudies.pdf
No, your use of 'string' is *not* well aligned with VDM. "For example, the type definition String = seq of char defines a type String composed of all finite strings of characters." This is precisely the way I am using "string": a *completed* (hence *finite*) sequence of characters that can be traversed more than once and in more than one way (s(i) in VDM). pipes and FIFOs and sockets might or might not be finite. The output of the classic UNIX 'yes' command is not bounded, for example. The distinction between strings and streams is a very important one. I have seen a programming language standards committee try to demand that any "file" should be able to answer its length, apparently unaware that in UNIX /dev/tty is a "file" but has no definite "length" (and even the read()-returns-zero-at-EOF hack doesn't work; having received such a signal you can just keep on reading).
Contrariwise 'file' can mean http://en.wikipedia.org/wiki/Data_set_%28IBM_mainframe%29
I have been familiar with IBM data sets for enough years to prefer the spelling with the space it it. They aren't strings, but they are completed multi-traversable sequences of records. Records might or might not be strings. (I have seen that same programming language standards committee try to demand that any "file" should be positionable at an arbitrary byte, and this despite including members who habitually used VM/CMS and others who habitually used VMS.) So it is *true* that the UNIX innovation was to take "BYTE STREAM" as a lingua franca between programs, but it is *false* that it used strings.
So let me restate (actually I didn't state it earlier!) my point in this example:
When Intel introduced these instructions in 8008 (or whatever) decades ago, it seemed like a good idea to help programmers and reduce their burden by allowing them to do some minimal arithmetic on data without burdensome conversion-to-binary functions.
Conversion to binary is not burdensome, and is not the issue. The issue is getting the *flags* right for decimal arithmetic. Intel's 4004 was for calculators. Intel's 8008 was redesigned to be more useful for calculators. Intel's 8080 had actual hardware support for decimal arithmetic (the Auxiliary Carry flag). And the 8086 was intended to be compatible with the 8080 and 8085. Not binary compatible, but source to source assembler translation is supposed to be straightforward. The DAA instruction comes from the 8080.
4 decades on and (Intel's very own Gordon) Moore's law ensuring our machines and networks some 7 orders of magnitude larger, the cost-equations look different. printf and scanf are a basic given in any C library so optimizing them out does not optimize anything.
That's a pretty massive non-sequitur. I speeded up my Smalltalk->C compiler by a factor of 2 by eliminating printf(). The reason why printf() is slow has of course *nothing* to do with number conversion: it has to do with run-time parsing of formats.
On the other hand having instructions --that too 1-byte instructions -- that are almost never used is terribly inefficient:
"Terribly" inefficient? I doubt it. I doubt it very much indeed. (Where is Andy Glew when you need him?) One-byte instructions are not really any more precious than others.
- the extra transistors in the millions of CPUs that are never used
The whole 8080 was implemented in about 6000 transistors. The 8086 had about 29000. A quad-core Intel Core i7 has 731,000,000. "The extra transistors" required to support decimal arithmetic on a modern CPU are presumably about 1/100,000th of the total. _This_ is to worry about?
- the instructions that are used become fatter. Multiply by the GBs per installation multipled by millions of installations.
We have a wide range of techniques to deal with that. In any case, if your program is compiled for 64-bit execution, the decimal instructions aren't _there_ and _don't_ "fatten up" any other instructions.
you capture pithily in your 'Strings are wrong!' Put slightly more verbosely:
Strings (or byte-arrays if you prefer) are invariably what come into and go out of your program.
Nope. *Streams*. And like I said, PowerShell shows that from a practical programming point of view, it _could_ be objects.
Brings me to the OPs question:
I want to know if it is possible that I use strings without "".
If I type Prelude>foo bar which actually I mean Prelude>foo "bar" However I don't want to type ""s.
I have noticed if bar is predefined or it is a number, it can be used as arguments. But can other strings be used this way? Like in bash, we can use ping 127.0.0.1 where 127.0.0.1 is an argument.
If not, can foo be defined as a function so that it recognize arguments like bar as "bar"?
Its not clear what your use-case is.
Now we are in agreement. Alan Perlis, epigram 34: The string is a stark data structure and everywhere it is passed there is much duplication of process. It is a perfect vehicle for hiding information.