Re: Symbols for range/iteration/slicing
- From: James Harris <james.harris.1@xxxxxxxxxxxxxx>
- Date: Thu, 22 Jan 2009 06:33:07 -0800 (PST)
On 20 Jan, 15:16, thomas.mer...@xxxxxx wrote:
On 20 Jan., 15:44, James Harris <james.harri...@xxxxxxxxxxxxxx> wrote:
for i in (a up to b, c down to d, e onward to f)
for i in (a :+ b, c :- d, e :| f)
for i in (a :+: b, c :-: d, e :|: f)
for i in (a :< b, c :> d, e :~ f)
for i in (a :<: b, c:>: d, e :~: f)
As I already said in a the other thread:
When you want to use 'in' also as an infix operator
it is not a good idea to reuse 'in' in the 'for'
loop as keyword. I would suggest the keyword 'range'
when 'in' is already used.
I would like to minimise the number of reserved words - i.e. those
words I take away from the programmer. For example, instead of "class"
I may use "objclass" (for object class) or similar so the word "class"
is still available for the programmer.
I know reusing words in different contexts complicates parsing
slightly. That makes my job slightly harder but is better for the
programmer who I see as a "customer" in this context.
Does (a up to b, c down to d, e onward to f) create
a set which could be used at a different place also
or is it just used in your for loop?
Conceptually, yes. It's up to the compiler whether it generates an
object or just advances an index when the construct is used for loop
control as long as the effect is the same.
What comes after the closing paren?
Do you want C like statements with or without brace,
or do you plan to require a brace always?
Statements with required brace have some advantages:
You can always add or remove satements in the loop
body without the need to add or remove braces all
the time.
My way forward here needs further explanation but in the context of
your question the construct could be considered
for i in set
...
end for
Your construct does not offer a step other than 1
or -1. I my programming practice the requirement for
other step values is more often than the requirement
for an 'onward' step.
It does allow for steps other than 1 or -1 but I didn't have a symbol
for that part when I posted!
Following Bartc's suggestion I would use another keyword.
for i in a upto b by c
Generating the increment or decrement for "towards" is a little more
complex. I'm not sure if it's better to make the programmer get the
sign right or to adjust it automatically.
Your use of special characters is rather uncommon
and needs getting used to. I also think that typing
text with many special characters is slower than
typing with normal keywords, because the special
characters are not so easy reachable as lower case
letters (they often require to press shift and are
not in the center of the keyboard).
I was motivated in part by Verilog's oft-used downward direction used
in declarations
reg[7:0]
which I cannot hope to keep as brief. My options are now
reg[7 :>: 0]
reg[7 downto 0]
Why do you want to use two keywords 'up to' instead
of just 'to' and 'downto' as in the Pascal and Ada
tradition.
The use of "to" is too vague in my opinion. I want to be explicit and
to support all three variants. Isn't that better from a language
engineering point of view?
upto
downto
towards
are clearer, I think.
James
.
- Follow-Ups:
- Re: Symbols for range/iteration/slicing
- From: AtariFan
- Re: Symbols for range/iteration/slicing
- From: thomas . mertes
- Re: Symbols for range/iteration/slicing
- References:
- Symbols for range/iteration/slicing
- From: James Harris
- Re: Symbols for range/iteration/slicing
- From: thomas . mertes
- Symbols for range/iteration/slicing
- Prev by Date: Re: Symbols for range/iteration/slicing
- Next by Date: Re: Syntax preference: symbols to use for iteration
- Previous by thread: Re: Symbols for range/iteration/slicing
- Next by thread: Re: Symbols for range/iteration/slicing
- Index(es):
Relevant Pages
|