Features I miss from other languages & syntax ideas

Propose new features and changes
User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Features I miss from other languages & syntax ideas

21 Oct 2017, 02:04

:beard: Just a list of features, mostly convenience oriented, I frequently wish I had in AHK:

Named Parameter Assignment/Pass-By-Name:
passing values to optional parameters by name
[example]

Code: [Select all] [Download] GeSHi © Codebox Plus

SampleFunction(var1, var2 := "default1", var3 := "default2") {
Msgbox % var1 . var2 . var3
}

SampleFunction("required string", var3:"optional param var3")


Operator Overloading:
overload default operators for custom class objects

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Function Overloading:
multiple functions of the same name, differentiated by param count

Code: [Select all] [Download] GeSHi © Codebox Plus

Add(v1, v2) {
return v1 + v2
}
Add(v1, v2, v3) {
return v1 + v2 + v3
}


Defined Literals
read-only variables that visible to all and resolved/replaced with their values at script auto-execute time

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Lambda Expressions: (my most wanted feature)
functions that can be declared and called in active context

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Switches: (i have a feeling most will consider these unnecessary, but i added it nonetheless)
should be obvious for most, select code path based on expression contents

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



some syntax ideas that I haven't seen in other languages, maybe bad/good ideas
is value in range (compact), instead of using between and

Code: [Select all] [Download] GeSHi © Codebox Plus

x := 55
if(x ~= 50..100 or x ~= 150..200)
return true

is instance of type class

Code: [Select all] [Download] GeSHi © Codebox Plus

Class myObj ...
x := new myObj()
if(x ~= myObj)
return true

is value one of any values, shorthand for x == 4 or x == 6 or x == 10

Code: [Select all] [Download] GeSHi © Codebox Plus

x := 5
if(x == 4,6,10)
return true
Last edited by KuroiLight on 22 Oct 2017, 15:06, edited 4 times in total.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
User avatar
nnnik
Posts: 2509
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Features I miss from other languages

21 Oct 2017, 02:16

I disagree with the switches due to several reasons:
A) Their main point is replacing long if/else constructions - however they fail to replace every if/else construct their is. They only replace a very specific rare case.
B) They are supposed to be more readeable but are so rare that when approaching them it will only make the reader confused and decrease readability.

I'm not particulary fond of defined literals either. Why not use a variable name instead and make it super global?

I perfectly agree with the rest though
Recommends AHK Studio
User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: Features I miss from other languages

21 Oct 2017, 02:37

I agree that I don't frequently find my self needing switches, but its one of those features that when handy is really handy. However that if possible their usability could be extended increasing their use.
image the following (with many more cases): ;)

Code: [Select all] [Download] GeSHi © Codebox Plus

switch(mouseX, mouseY) {
(100..1000), (50..500): ;evaluated and compared in the same order they are passed to switch
return "x is between 100-1000 and y is between 50-500"
(>1000), (<50):
return "x is greater than 1000 and y is less than 50"
}

---
as for B, if you mean assume-global , I really don't like the idea of polluting the global scope, this could easily cause collisions, isn't memory efficient and imo hurts read-ability. And the use case I ment for #define would be like when declaring settings or const values that you want to use in more than one place without having to scope with global all over the place.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]

01/24/18

User avatar
nnnik
Posts: 2509
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Features I miss from other languages

21 Oct 2017, 02:45

This switch would only be worse on the eyes. So if you don't mind hurting eyes I reccomend using Objects for that:

As for B no I don't mean assume global I explicitly meant super global:

Code: [Select all] [Download] GeSHi © Codebox Plus

global I_ACT_LIKE_A_STATIC := 12
fn()
{
Msgbox % I_ACT_LIKE_A_STATIC
}

Towards me I never understood the pollution argument for variables vs. statics since statics also pollutes every scope.
Recommends AHK Studio
User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: Features I miss from other languages

21 Oct 2017, 02:53

nnnik wrote:This switch would only be worse on the eyes.

Maybe, I may have been spoiled by Perl, I'm used to some weird looking code thats fun to write but later just as fun to read, lol.
I like the idea of multi-param switches and range comparisons though, maybe not the <> because its a bit confusing whats going on there.

nnnik wrote:As for B no I don't mean assume global I explicitly meant super global:

Code: [Select all] [Download] GeSHi © Codebox Plus

global I_ACT_LIKE_A_STATIC := 12
fn()
{
Msgbox % I_ACT_LIKE_A_STATIC
}

Towards me I never understood the pollution argument for variables vs. statics since statics also pollutes every scope.

Ah lol, didn't even realize (or forgot) global could do that.

EDIT**
Maybe just the ability to compare a value with ranges would be more useful, like:

Code: [Select all] [Download] GeSHi © Codebox Plus

x := 55
if(x ~= 50..100 or x ~= 150..200)
return true

instead of

Code: [Select all] [Download] GeSHi © Codebox Plus

x := 55
if x between 50 and 100
return true
if x between 155 and 200
return true
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]

01/24/18

User avatar
nnnik
Posts: 2509
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Features I miss from other languages

21 Oct 2017, 03:30

KuroiLight wrote:Maybe just the ability to compare a value with ranges would be more useful, like:

Code: [Select all] [Download] GeSHi © Codebox Plus

x := 55
if(x ~= 50..100 or x ~= 150..200)
return true

Iactually support this idea:
[c]~=[\c] is currently used in AutoHotkey to match a Regular Expression which in a very broad sense could be called the comparison between a string and a string range.
So if we add more stuff to more types I think this could become an extremly useful operator:

Code: [Select all] [Download] GeSHi © Codebox Plus

instance~=class
number~=range
string~=regex
;...
Recommends AHK Studio
User avatar
jeeswg
Posts: 3594
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Features I miss from other languages & syntax ideas

21 Oct 2017, 12:30

I've done various scripts that parse text, and every new syntax notation is a nightmare to implement, so I would always guard against adding in new notational devices especially if they can be achieved by relatively short simple functions. I also like the idea of keeping AutoHotkey as simple as possible. Despite this I'm not against being decisive where necessary.

It would be good if you linked or provided workaround code for any of the features you want, so that people can be sure what you want.

One area where I, in principle, agree is that I think that AHK should have better, i.e. function, versions of Between/Contains/In/IsType.

Re. switches, one possibly interesting idea you've reminded me of, is that if an object doesn't have a key, to be able to return some value other than blank, cf. IniRead. Whether that should be a feature of standard arrays, or whether AutoHotkey could make certain object classes available as standard templates would be the secondary question.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
nnnik
Posts: 2509
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Features I miss from other languages & syntax ideas

21 Oct 2017, 13:19

I think I have told you before that your solution for AutoHotkey parsing is not exactly optimal.
I doubt that AutoHotkey would stop evolving because a single one of it's users parsing scripts has stopped working.
I am pretty sure that I will develop my own AutoHotkey fork in time - I will use that to showcase my feature requests.
Recommends AHK Studio
User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: Features I miss from other languages

22 Oct 2017, 15:03

nnnik wrote:So if we add more stuff to more types I think this could become an extremly useful operator:

Code: [Select all] [Download] GeSHi © Codebox Plus

instance~=class
number~=range
string~=regex
;...

The addition of is instance of type class sounds really good too. I will add it to OP.

jeeswg wrote:I've done various scripts that parse text, and every new syntax notation is a nightmare to implement

Currently the ~= operator has only one use and it really only applies when there is a string on the right, I don't really see how it would add much of a nightmare to add a check for a range on the right for range comparison.
jeeswg wrote:relatively short simple functions

having a dedicated function is kinda ugly, if I was just looking for shorthand alone i'd use regex 55 ~= "[50-150]" works just fine, but its likely more expensive than a builtin range operator.
This can get even worse when you want to use variable ranges 55 ~= "[" . lower_bound . "-" . upper_bound . "]" were you have several string ops and a regex op, instead of the proposed 55 ~= lower_bound..upper_bound or 55 ~= %lower_bound%..%upper_bound% (depending on how its implemented) were you have 2 derefs and a range op.
jeeswg wrote:It would be good if you linked or provided workaround code for any of the features you want, so that people can be sure what you want.

Click on the features name they are linked to wiki pages describing what they are, most of the proposed features don't have decent workarounds.

nnnik wrote:I am pretty sure that I will develop my own AutoHotkey fork in time - I will use that to showcase my feature requests.

If you do I would be happy to use it and (assuming I have time) contribute if you need. Do you have a list of features in one post so I can see all what your wish-list is?
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]

01/24/18

guest3456
Posts: 2165
Joined: 09 Oct 2013, 10:31

Re: Features I miss from other languages & syntax ideas

22 Oct 2017, 18:41

why are lambda's necessary? why not just extract into a separate function?

User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: Features I miss from other languages & syntax ideas

22 Oct 2017, 22:59

guest3456 wrote:why are lambda's necessary? why not just extract into a separate function?

Because lambdas are fun. :lol:

They are good for situations where you need a quick one off function for a short amount time (e.g. loops); and situations where you need to generate, swap or store functions.
Wiki has some good examples of its uses >Anonymous Functions<.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]

01/24/18

User avatar
derz00
Posts: 404
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: Features I miss from other languages

23 Oct 2017, 19:34

KuroiLight wrote:
nnnik wrote:I am pretty sure that I will develop my own AutoHotkey fork in time - I will use that to showcase my feature requests.

If you do I would be happy to use it and (assuming I have time) contribute if you need. Do you have a list of features in one post so I can see all what your wish-list is?


@nnnik are you basing off v2?

@KuroiLight it seems there are many threads, etc on this forum (In Wish List, Bug Reports, AutoHotkey v2 Development) with wishes, things to develop, etc. Someone should take the time to organize some of it ;)
try it and see
...
User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: Features I miss from other languages

24 Oct 2017, 10:17

derz00 wrote:@KuroiLight it seems there are many threads, etc on this forum (In Wish List, Bug Reports, AutoHotkey v2 Development) with wishes, things to develop, etc. Someone should take the time to organize some of it ;)

Yea it would be cool if we could get a community agreed upon wishlist organized into one post and stickied.
Last edited by KuroiLight on 24 Oct 2017, 13:37, edited 1 time in total.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]

01/24/18

User avatar
derz00
Posts: 404
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: Features I miss from other languages & syntax ideas

24 Oct 2017, 11:16

YES And I imagine nnnik also has a list somewhere too :P
try it and see
...
User avatar
jeeswg
Posts: 3594
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Features I miss from other languages & syntax ideas

21 Jan 2018, 15:42

For switches, you can get some good outcomes by using the ternary operator:
Switch/Case statement - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=13&t=27794&p=187486#p187486
User avatar
KuroiLight
Posts: 324
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: Features I miss from other languages & syntax ideas

22 Jan 2018, 20:28

Pretty creative way of doing it, but it isn't immediately apparent what your doing there, which is why I think dedicated syntax is better.
I'm actually not that attached to switches anymore since the same thing could be accomplished using a function lookup table.
This could be further improved with the addition of an eval function (which executes a string of code), but this opens a whole 'nother can of worms.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]

01/24/18


Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 1 guest