For Programmers: Free Programming Magazines  


Home > Archive > Compilers > June 2006 > Natural "for" Loop, using Plural / Singular transformations ??









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Natural "for" Loop, using Plural / Singular transformations ??
olivier.chatelain@gmail.com

2006-05-26, 7:07 pm

Dear Compiler Cracks,

What about using Plural => Singular transformations to generate loop
variables from name of lists?


EXAMPLE:

FOR dependency IN dependencies DO
PRINT dependency.name
END

= depenendcies -generates-> dependency =

FORALL dependencies DO
PRINT dependency.name
END

The compiler would generate the "singular" loop variable "dependency"
from the List "dependencies" (Plural).

This would reduce the code size, improve those long, unreadable headers
and simply plain-editor refactoring.

Any comments?
Olivier

PS: This idea is ispired by "Ruby on Rails" ORM, using Plural for the
Database-Tables.
[OK, what's the plural of deer or sheep? Attempts to make programming
languages have a long history. Cobol was the first and I think the
most successful, and although it was very successful as a language,
giving us stuff like C structures, it was pretty much a failure as
English. -John]
Oliver Wong

2006-05-30, 7:11 pm

<olivier.chatelain@gmail.com> wrote in message
>
> EXAMPLE:
>
> FOR dependency IN dependencies DO
> PRINT dependency.name
> END
>
> = depenendcies -generates-> dependency =
>
> FORALL dependencies DO
> PRINT dependency.name
> END
>
> The compiler would generate the "singular" loop variable "dependency"
> from the List "dependencies" (Plural).
>
> This would reduce the code size, improve those long, unreadable headers
> and simply plain-editor refactoring.
>
> Any comments?
> Olivier
>
> [OK, what's the plural of deer or sheep?

[...]
> -John]


Or what's the plural/singular version of names that I just make up?

FORALL RXX9402EjjDD DO
PRINT /*What's the singular of "RXX9402EjjDD"?*/.name
END

- Oliver
Dimitri Maziuk

2006-05-30, 7:11 pm

olivier.chatelain@gmail.com sez:
> Dear Compiler Cracks,
>
> What about using Plural => Singular transformations to generate loop
> variables from name of lists?
>
>= depenendcies -generates-> dependency =
>
> FORALL dependencies DO
> PRINT dependency.name
> END


sub autumn
forall leaves do
leave.fall
end
endsub

Dima
--
All whitespace is equivalent except in certain situations
-- ANSI C standard committee

Dmitry A. Kazakov

2006-05-30, 7:11 pm

On 26 May 2006 12:51:40 -0400, olivier.chatelain@gmail.com wrote:

> What about using Plural => Singular transformations to generate loop
> variables from name of lists?
>
> EXAMPLE:
>
> FOR dependency IN dependencies DO
> PRINT dependency.name
> END
>
> = depenendcies -generates-> dependency =
>
> FORALL dependencies DO
> PRINT dependency.name
> END
>
> The compiler would generate the "singular" loop variable "dependency"
> from the List "dependencies" (Plural).


Hmm, what about

for Arrays do
for Arrays do
print Cov (Array.Element, Array.Element)
-- Would it print the covariance matrix?
end
end

The logical error is that the loop variable is not a property of the
iterated container. So you cannot derive its name from the container's name
alone. You could do it from the loop's name. For example:

Outer : for Arrays do
Inner : for Arrays do
print Cov (Inner.Item, Outer.Item)
-- This works
end
end

But how is it better than the construct we have started from?

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Tom Copeland

2006-05-30, 7:11 pm

On Fri, 2006-05-26 at 12:51 -0400, olivier.chatelain@gmail.com wrote:
> PS: This idea is ispired by "Ruby on Rails" ORM, using Plural for the
> Database-Tables.
> [OK, what's the plural of deer or sheep?


$ ruby -rubygems -e "require 'active_support' ; ['deer','sheep'].each {|
word| puts word.pluralize }"
deers
sheep

One out of two isn't bad :-)

> Attempts to make English-like programming languages have a long
> history. Cobol was the first and I think the most successful, and
> although it was very successful as a language, giving us stuff like
> C structures, it was pretty much a failure as English. -John]


Debating this feature is pretty much a permathread on the Ruby on Rails
mailing list...

Yours,

Tom
Karsten Nyblad

2006-06-03, 7:05 pm

olivier.chatelain@gmail.com wrote:
> Dear Compiler Cracks,
>
> What about using Plural => Singular transformations to generate loop
> variables from name of lists?
>
>
> EXAMPLE:
>
> FOR dependency IN dependencies DO
> PRINT dependency.name
> END
>
> = depenendcies -generates-> dependency =
>
> FORALL dependencies DO
> PRINT dependency.name
> END
> ...


When writing business applications for use in none English speaking
languages, it is common to let the identifiers be in the local
language, but few languages derive plural from singular the way it is
done in English.

Simply translating the local language words into English will not work
for two reasons: First many of the names in business applications
refer to local law and traditions. There may not be any good
translation into English. Secondly, take programmer whom native
language is not English.
People tend to learn the parts of foreign languages they need in
their daily live. While most of these programmers can read English
texts about computer science you cannot assume that their English
vocabulary is good enough when it comes to business issues and law.

Then you could have the language localized for each language, but
experience tells that people want to buy software from other
countries, and of course multi national companies want to use the same
code in all countries. The experience is that localizing languages is
a pain because code cannot easily be ported from one country to
another.

Karsten Nyblad


Tony Finch

2006-06-05, 7:11 pm

Karsten Nyblad <148f3wg02@ sneakemail.com> wrote:
>olivier.chatelain@gmail.com wrote:
>
>When writing business applications for use in none English speaking
>languages, it is common to let the identifiers be in the local
>language, but few languages derive plural from singular the way it is
>done in English.


One of the more amusing aspects of the Algol 68 VW grammar is the
somewhat formal structure of the names used to describe parts of the
language, which are almost but not quite English, and frequently
utterly bizarre because of the strange affixes. I wonder if this was a
result of the multi-lingual committee that defined the language.

For example, the affix -S usually means "one or more", so DECS is one or
more declarations; and -ETY usually means "can be empty", as in SHORTSETY
can be SHORTS or EMPTY. Frequently when the grammar uses SOID for what
we now call types, i.e. a SORT followed by a MOID, which is a MODE or
VOID. Obviously.

Nowadays it seems more popular to use punctuation for this sort of thing,
resulting in a more mathematical rather than linguistic flavour. For
example, the IETF's ABNF.

Tony.
--
f.a.n.finch <dot@dotat.at> http://dotat.at/
BISCAY FITZROY: EAST OR NORTHEAST 4 OR 5 INCREASING 6 OR 7 IN FITZROY. FAIR.
GOOD.
Peter Ludemann

2006-06-17, 7:05 pm

On 6/3/2006 3:52 PM, Karsten Nyblad wrote:
> olivier.chatelain@gmail.com wrote:

[snip]
[color=darkred]
> When writing business applications for use in none English speaking
> languages, it is common to let the identifiers be in the local
> language, but few languages derive plural from singular the way it is
> done in English.


And some languages don't have plural forms at all (Chinese, Japanese);
some have special dual forms (Lithuanian). Some don't have articles
(Russian), so idioms like "for theDependency in dependencies ..."
don't translate well. Some insist on conjugating the verb according to
the gender of the subject. Etc., etc.

In designing programming languages, it's useful to have at least a
passing acquaintance with a few other languages, preferably from another
language family than your native language. Here's a description of Perl,
as invented by a Latin-speaker:
http://www.csse.monash.edu.au/~dami.../Perligata.html
meo varo haec da. # my $var = @_;
meis varo haec da. # my ($var) = @_
meis varis haec da. # my @var = @_;

And, of course, there's the classic (still controversial):
http://en.wikipedia.org/wiki/Sapir-Whorf_hypothesis

- peter ludemann
Jonathan Thornburg

2006-06-17, 7:05 pm

Peter Ludemann <p_ludemann@yahoo.com> wrote:
> In designing programming languages, it's useful to have at least a
> passing acquaintance with a few other languages, preferably from another
> language family than your native language. Here's a description of Perl,
> as invented by a Latin-speaker:
> http://www.csse.monash.edu.au/~dami.../Perligata.html
> meo varo haec da. # my $var = @_;
> meis varo haec da. # my ($var) = @_
> meis varis haec da. # my @var = @_;
>
> And, of course, there's the classic (still controversial):
> http://en.wikipedia.org/wiki/Sapir-Whorf_hypothesis


Consider the following basic-computer-science-algorithms exercise:
Given two lists (1-D arrays) of numbers, suggest a
"reasonably efficient" algorithm to find all numbers
which are common to both lists.
There are two obvious algorithms which are faster than O(N^2):
(A) build a hash table of the entries in one list, then walk the
other list checking the hash table for duplicates
(B) sort both lists, then walk the sorted lists looking for duplicates

I have read (but alas cannot find a reference) that most programmers
(who have a reasonable knowledge of basic algorithms) suggest (A) as
the obvious answer to this exercise, whereas programmers who know the
APL programming language
[which has sorting as a primitive, but not hash tables]
are more likely to suggest (B).

ciao,

--
-- "Jonathan Thornburg -- remove -animal to reply" <jthorn@aei.mpg-zebra.de>
Max-Planck-Institut fuer Gravitationsphysik (Albert-Einstein-Institut),
Golm, Germany, "Old Europe" http://www.aei.mpg.de/~jthorn/home.html
Hans Aberg

2006-06-17, 7:05 pm

Peter Ludemann <p_ludemann@yahoo.com> wrote:

> In designing programming languages, it's useful to have at least a
> passing acquaintance with a few other languages, preferably from
> another language family than your native language.


One language good to know, is the language of mathematics. There is no
significant difference whether the math is written in English, French,
German, or Swedish that I know of, though there are some_traditional
schools, despite the fact that math notation evolved as
simplifications of worded expressions.

> And, of course, there's the classic (still controversial):
> http://en.wikipedia.org/wiki/Sapir-Whorf_hypothesis


In math, it is important to note the interplay between notions
(semantics) and notation (syntax). Complicated logical structures
requires_efficient notation. Foremost, it is important to focus on the
semantics; then build up a syntax suitable for expressing that
semantics efficiently. I see no difference in math or computer
language design in that.

--
Hans Aberg
glen herrmannsfeldt

2006-06-17, 7:05 pm

Jonathan Thornburg wrote:

(snip)

> Consider the following basic-computer-science-algorithms exercise:
> Given two lists (1-D arrays) of numbers, suggest a
> "reasonably efficient" algorithm to find all numbers
> which are common to both lists.


(snip of hash table and sort solutions)

The last time I needed to do this, I needed to find the non-duplicates
between two lists that each had a fair number of duplicates.

Using the unix sort -u command on each list sorts each list while
removing duplicates. (As an external sort, it should remove duplicates
for each sort group before writing them to disk. I don't know if it
does that, though.)

With two sorted lists with duplicates removed, sort -m (merge)
and uniq (with the appropriate option) can detect duplicate or
non-duplicate values.

For very large lists, the sort can be done as an external sort,
where hash tables are usually not external.

-- glen

Gene Wirchenko

2006-06-27, 7:05 pm

Peter Ludemann <p_ludemann@yahoo.com> wrote:

>On 6/3/2006 3:52 PM, Karsten Nyblad wrote:


[snip]

>
>And some languages don't have plural forms at all (Chinese, Japanese);


Chinese does have plurals. In Putonghua, "men" is the plural
particle. However, if there plurality has already been established,
say by stating that there are two of the object, then "men" is not
used.

[snip]

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Gene Wirchenko

2006-06-27, 7:05 pm

olivier.chatelain@gmail.com wrote:

>What about using Plural => Singular transformations to generate loop
>variables from name of lists?


The transformation is not well-defined. For example, the
singular of "axes" is either "axis" or "axe" (or "ax").

[snip]

Sincerely,

Gene Wirchenko
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com