Named result variables
Ville Misaki
ville at misaki.fi
Mon Nov 2 12:55:43 UTC 2015
How about making the variable declaration optional? Or rather, the
interpreter auto-generating the declaration with type inference the first
time a previously-undeclared variable is assigned to.
E.g. from the earlier example:
set1 = setOf(1, 2, 3);
the variable set1 would have the implied type of Set<Integer>.
Cheers,
Ville
> Keep in mind I'm open to any solution.
>
> Let me frame my idea as a strawman so it is easier to shoot arrows at :-)
>
> Think: source code transformations that IDEs sometimes do.
> So, in this case say, ...
> You type in a complex expression expr. Then you press ctrl-V. The tool
> generates the type typedecl and an equals sign and sticks the cursor
> between them so you can type the variable name:
>
> typedecl. | = expr:
>
> Where | represents the cursor position.
>
> Jan can tell me if this is even something jline can do.
>
> The idea is, like tab, you type characters which don't correspond to
valid
> Java, but what you see is valid.
>
> Of course what character is typed to initiate this is arbitrary.
>
> Ideas...
>
> -Robert
>
>
>
>On October 29, 2015 11:17:24 PM Robert Field <robert.field at oracle.com>
wrote:
>
>> Thanks Cay putting this out for discussion, would love to come up with
>> some nice solution for this. I would like to avoid something that
>> straddles the snippet and command worlds which are now distinct.
>>
>> I don't think I expressed my idea very clearly -- mostly because it
isn't
>> at all clear to me ;-)
>> What I was thinking was something vaguely tab completion like, in that
you
>> wind up looking at a well formed snippet not all of which you explicitly
>> typed. But not literally a tab nor completion.
>>
>> Thanks,
>> Robert
>>
>>
>> On October 29, 2015 6:50:46 PM Cay Horstmann <cay at horstmann.com>
wrote:
>>
>>> When I teach, I like to use jshell for quick demos. I might predefine
>>>
>>> <T> Set<T> setOf(T... values) { return new
>>> TreeSet<>(Arrays.asList(values)); }
>>>
>>> and then construct two sets:
>>>
>>> Set<Integer> set1 = setOf(1, 2, 3);
>>> Set<Integer> set2 = setOf(2, 3, 5);
>>> set1.removeAll(set2)
>>>
>>> Except, that's a lot of typing, so I don't do that. I do
>>>
>>> setOf(1, 2, 3);
>>> setOf(2, 3, 5);
>>> $1.removeAll($2)
>>>
>>> Note the absence of types. The $n are automatically typed.
>>>
>>> But I lose track of those $n prettty soon. It would be nice if i could
>>> name them.
>>>
>>> I brought this up at the Java One presentation and suggested
>>>
>>> /var set1 $1
>>>
>>> or
>>>
>>> /var set2
>>>
>>> to name the last $n.
>>>
>>> Robert thought that was a bit too much like inventing a new langauge
>>> feature and suggested that one might be able to solve this with tab
>>> completion instead.
>>>
>>> I thought about this a bit and couldn't come up with a compelling way.
>>> Right now, when one hits Tab on a blank line, one is offered a
>>> collection of well over 400 possible completions (types, packages,
>>> classes, $ variables). Using that to get to something like Set<Integer>
>>> or TreeMap<String, TreeSet<Integer>> isn't satisfactory.
>>>
>>> Does anyone else think that an easy way of naming results is worthwhile?
>>> Any ideas on what the user interface should be?
>>>
>>> Cheers,
>>>
>>> Cay
>>>
>>>
>>> --
>>>
>>> Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com
More information about the kulla-dev
mailing list