This discussion reminded me of some experimenting I did about 5 years
ago when I was trying to learn something about Python and Ruby. The
suggested syntactic sugar - variable = ['First','Second','Third'] - is
how one defines a "list" in Python and is called an "array literal" in
Ruby. I played with different ways to do something like this with
ooRexx using what was available, i.e. without enhancing the language.
The best approach that I found involved 1) defining a one-character
named class, 2) defining a "[]" class method on that class, and 3)
having that method return the arguments as an array. So if the class
was named V (for vector), the example would read: variable =
.V['First','Second','Third']. You get the shortened syntax for creating
the array at the "cost" of entering two additional characters, the dot
and the class name (V). I played with different class names (one might
want A for array for example) including using special characters (like
?. !, and _) since they are less likely to "clash" with other
user-written class names. I even found that . (dot) is a valid class
name! So ..[1,2] would work but it just looks too strange! The
implementation is only three lines of code:
::class v
::method "[]" class
return arg(1,A)
I also found that once you had a shortened syntax for specifying an
array, writing an Of method for the Map Collection classes is very easy
(and very worthwhile!).
Having said all that, I fully support the use of commas inside
parentheses as the preferred way to implement a shortened syntax for
specifying an array.
On 9/18/2014 9:57 AM, Sahananda (Jon) Wolfers wrote:
Hi Rick,
I entirely understand your concerns about the square brackets.
I don't know whether this is the time to spend our gold. I'm
interested to hear what others say.
I like the assignment to map-collections
A further thought. I have also seen other languages parsing an array
into variables thus:
[var1,var2,var3] = .array~of(value1, value2, value3)
but I think that is rather un-rexxish and certainly not just syntactic
sugar and imho is included in the other languages because of their
poverty of decent collections.
just my 2p worth
Jon
On 18 September 2014 14:24, Rick McGuire <[email protected]
<mailto:[email protected]>> wrote:
I confess that I've been wanting a shortcut for creating arrays
for a long time and have even considered submitting this feature
request myself. This is not something difficult to implement, but
my resistance to doing this has more to do with the fact that it
introduces new syntax.
Using square brackets for purposes other than message invocations
has always been one of those "back pocket" syntax elements that
have been held in reserve until a use that was good enough to say
"yes, this is really what I want to use this for.". Other uses
for brackets I've considered in the past have been multi-line
literals and creating variable references. This has always been a
balancing act. You don't want to use this on something trivial,
but at the same time, you don't want to be so resistant to using
it that you have effectively removed from being a possibility.
Curly braces have been in this category for a VERY long time. We
need to consider if "syntactic" sugar is important enough use for
this syntactic concept.
Admittedly, array objects are very important in ooRexx. They pop
up in lots of situations as return values and also as arguments to
both instructions and methods. Are they important enough that they
get the special syntax rather than some other object type? That
needs to be considered. There are a few obvious places where this
might make a lot of sense. Jon shows the obvious assignment case,
but this would be fairly useful for things like DO OVER
do name over ["Mike", "Jon", "David"]
looks nicer than
do name over .array~of("Mike", "Jon", "David")
and feels a bit more natural and integrate.
Being able to create arrays without a lot of extra syntax would
make something like OF methods for map collections workable. For
example,
locs = .directory~of(["Rick", "USA"], ["Mike", "UK"])
where you are using the array syntax to create index/value pairs
for insertion into the directory.
Anyway, I've laid out the issues as I see them. I think this is
something that needs a bit of discussion before a decision is made
because of the syntax issues. The 5.0 release I've been working
on would be a good place to introduce this concept.
Rick
Rick
---------- Forwarded message ----------
From: *Jon Wolfers* <[email protected]
<mailto:[email protected]>>
Date: Thu, Sep 18, 2014 at 5:08 AM
Subject: [oorexx:feature-requests] #613 Syntactic sugar for array
creation
To: Ticket 613 <[email protected]
<mailto:[email protected]>>
---
** [feature-requests:#613] Syntactic sugar for array creation**
**Status:** unread
**Milestone:** None
**Created:** Thu Sep 18, 2014 09:08 AM UTC by Jon Wolfers
**Last Updated:** Thu Sep 18, 2014 09:08 AM UTC
**Owner:** nobody
Just an idea.
How about a bit of syntactic sugar such that
~~~~~~~~~~
variable = ['First','Second','Third']
~~~~~~~~~~
is equivalent to
~~~~~~~~~~
variable = .array~of('First','Second','Third')
~~~~~~~~~~
It could also be allowed for cases like
~~~~~~~~~~
do variable over ['First','Second','Third']
...
end
~~~~~~~~~~
I have seen this in other languages and think it is quite neat
Jon
---
Sent from sourceforge.net <http://sourceforge.net> because you
indicated interest in
<https://sourceforge.net/p/oorexx/feature-requests/613/>
To unsubscribe from further messages, please visit
<https://sourceforge.net/auth/subscriptions/>
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Oorexx-devel mailing list
[email protected]
<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/oorexx-devel
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel
--
Gil Barmwater
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel