paste into the interp; string coercion
Ka-Ping Yee
ping@lfw.org
Mon, 19 Oct 1998 03:02:32 -0700 (PDT)
> >Was there any intention of being able to copy and paste
> >multi-line blocks of interactive sessions? It sure would be
> >neat if E knew enough to strip the leading prompt from each
> >line. (It is fairly annoying to have to cut and paste each
> >line individually in Python when i make a mistake, and of
> >course this is exacerbated by Python's indent sensitivity
> >which doesn't occur here.)
>
> Thank you, I now have my first satisfying answer for why I avoid
> indentation-significance.
Gee, i was kind of surprised to hear you say this. If i had
known that you didn't have a satisfying answer the Python-lover
in me might even have asked for indentation...
But i really thought the original strongest argument had to do
with entering arbitrary code on the command line. If you use
indentation for block structure and/or scoping, then there is
only a limited amount you can say on one line.
Do you think it's a good idea to make the E interpreter remove
leading "?"s and ">"s from lines of input?
> On int("4"), introspectively, I only find a surprisingly inarticulate
> "that's not coercion, that's parsing!". I may just be confused, I'll stew
> further.
Hmm. Well, it is a simple kind of parsing. But how else
are you going to get an int out of a string, except by
parsing? The strongest argument for me in favour of int("4")
producing 4 is that string(4) yields "4". (Similarly i think
many people would expect that float(string(3.14)) or
double(string(3.14)) produced 3.14 too.)
Guido resisted this in Python for a while (i believe with a
similar "but that's parsing" reply), but finally the
clamouring grew too loud and he relented in Python 1.5, in which
the built-in functions int() and float() now accept a string.
> On
>
> 'a' -> "a"
>
> how would you feel about
>
> 3 -> [3]
> ?
Actually, i think i would be okay with it -- if you first
properly extend the analogy:
char is the character type
string is a "sequence of characters" type
int is the integer type
intlist is a "sequence of integers" type
Now, does
intlist(3) -> [3]
seem more reasonable?
I guess my point is, sequence-ness is embedded in the
meaning of "string". So it's okay to get "a" from string('a').
That's a justification from a semantic standpoint. The style
justification is that "string('a')" looks like other coercers.
In any case, i imagine that string('c') probably won't be
used extremely often anyway, since most of the time you'll
probably be tacking characters onto strings with + or
something like that.
!ping