Re: Pronouns in programming language?
28 Feb 2000 02:59:05 -0500

          From comp.compilers

Related articles
Pronouns in programming language? (John Fremlin) (2000-02-27)
Re: Pronouns in programming language? (Axel Schairer) (2000-02-28)
Re: Pronouns in programming language? (2000-02-28)
Re: Pronouns in programming language? (2000-02-28)
Re: Pronouns in programming language? (2000-02-28)
Re: Pronouns in programming language? (Lieven Marchand) (2000-02-28)
Re: Pronouns in programming language? (Hamish Atkinson) (2000-02-28)
Re: Pronouns in programming language? (2000-02-28)
Re: Pronouns in programming language? (H. Ellenberger) (2000-02-28)
Re: Pronouns in programming language? (2000-03-03)
[12 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
Date: 28 Feb 2000 02:59:05 -0500
Organization: - Before you buy.
References: 00-02-149
Keywords: syntax, design

    John Fremlin <> wrote:
> Has any programming language/compiler implemented pronoun like
> constructs?

Shell languages (like bash, tcsh, etc), have "!" notation to refer to
previously typed in commands. For example, "!!" is the previous
command, "!33" is command number 33 in the saved history of commands,
and "!?foo" is the most recent command containing the string "foo".
See the man page for more examples.

The (old traditional) unix "bc" command provides a calculator, where
"." refers to the previous result. I think of seen variants of that
facility in other math packages, such as Maple.

The "Perl" programming language has a default "scalar" variable, "$_"
which is used when none are specified (and a separate list version
"@_"). Many Perl expressions will refer to one of these two variables
unless explicitly overridden. Many looping constructs will use the
"$_" scalar variable as the index variable by default. Arguments to
procedures are passed in the "@_" list variable. Find a good Intro to
Perl book for more details.

My concern with your example is with the "modifiability" of programs
using your pronouns or elisions. When lines of code start getting
added between the line producing the value and the line consuming it,
the human reading the code can get more and more confused. Since you
use the word "pronoun", I get the feeling that you want the program to
be able to refer to the results of *particular* other parts of the
program by position or adjacency. And my complaint is that adjacency,
at least, can get arbitrarily fuzzy as code gets added.

The Shell "!" notation is geared towards referring to the text of
typed in commands.

The bc "." notation is geared towards a "current result", or perhaps
the top of a stack of results in a stack machine.

The Perl "_" variables are special "current result" variables,
modified implicitly by most commands. All the commands modify the
same implied variable. So one thing that needs to be understood in
order to read Perl programs is how and when these implied variables
get modified. It might sound complicated, but I haven't had any
confusion in practice.

Perl string pattern matching can be a different story. There you us
what are called "regular expressions" to match strings, possibly
saving pieces of the matched string. The pieces are stored in
numbered variables -- the first piece in "$1", the second in "$2", and
so forth. The problem is that if you execute another command that
modifies these variables, all the original values are lost. After
getting burned my this a couple times while "evolving" Perl programs,
I learned just to assign all the numbered variables to named variables
(for example, "$tag = $1 ; $value = $2 ;" etc.). And hence my
nervousness about adjacency rules a couple paragraphs back.

Perl's got the most interesting and useful notion of implied variables
that I know of, though I have not done a survey. The shell "!" notation
refers to the text of typed in commands rather than variables, so is
more an aid to typing in shell programs interactively than making the
programs more terse.

I hope you find my response useful.

-- Perry
> [I can think of some examples. Lisp LET (typically implemented as
> an anonymous procedure) permits you to assign names to expressions
> for very limited scopes. Cobol lets you elide comparison operands,
> ... -John]

I've also heard that some languages have experimented with permitting
n-ary comparisons (eg, "1 < x < 10" instead of "x > 1 && x < 10", but
they always conclude that its a mistake. Hard to understand code gets
produced, and I think there's a parsing problem, but I forget what.

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.