Seek AHK equivalent to Perl idioms that facilitate commenting out lines of lists/arrays/...

Propose new features and changes
Sticky
Posts: 10
Joined: 12 Apr 2017, 22:08

Seek AHK equivalent to Perl idioms that facilitate commenting out lines of lists/arrays/...

Post by Sticky » 23 Jun 2022, 18:47

BRIEF:

I like the way Perl makes ,comma optional terminators rather than required separators or terminators in constructs like ordinary and associative arrays. It allows you to put one entry per line, and easily comment-out an entire line without having to rejigger the syntax to add or replace a ,comma that may or may not be necessary depending on whether adjacent lines have been commented in or out.

Indeed, several significant programming languages have added this sort of thing late, several versions in, when they realize that programmers were asking for it. I think this sort of thing can now be considered a BKM in the design of programming language syntax.

Code: Select all

$ bash $> cat EXAMPLE-Perl-independent-lines.pl 
@a = (
    1,
    # 2,  # <---  comment-out an entire line
    3,
    );
%h = (
    a => 1,
    # b=>2,  # <---  comment-out an entire line
    c => 3,
    );
foreach $v ( @a ) { print "<$v>"}; print "\n";
foreach $k ( sort keys %h ) { print "[$k$h{$k}]"}; print "\n";
OK
$ bash  $>  perl ./EXAMPLE-Perl-independent-lines.pl 
<1><3>
[a1][c3]
OK

AutoHotKey does not support this sort of thing.

Code: Select all

;; AHK syntax is *not* Perl-like, and does *not*  facilitate independent lines.
;; This code is not accepted by AutoHotKey.
a := [
1,
2,
3,
]

h := {
	a:1,
	b:2,
	c:3,
}

The closest I have been able to come to this in AutoHotKey is as follows: to have dummy 0 elements at the beginning and end of a and AutoHotKey array, and 0:0 elements at the beginning and end of an AutoHotKey associative array/object. I have to arrange to have the code using these linear and associative arrays skip the placeholder elements. If 0 and 0:0 are not acceptable as placeholders because those keys and values are needed, I have to come up with others.


Combining this with AutoHotKey's line continuation, I get the following:

Code: Select all

a := [0
,    1
,    2
,    3
,0]

h := {0:0
,	a:1
,	b:2
,	c:3
,0:0}
While I can live with this, it does look somewhat ugly.


I wonder if anybody has a better way?


-----------


In case anyone cares, I like this approach that allows individual lines clauses or sub expressions to be commented-out so much that I often write code like

Code: Select all

if(0
   || expr1
   ;; || expr2   ; <-- disabled his part of the expression
   || 
   ||0) 
{
      ...
}
and

Code: Select all

msgbox,% ""
   . "Title:"
   . "`n" . "thing #1: " . thing1
   ;;. "`n" . "thing #2: " . thing2
   . "`n" . "thing #3: " . thing3
Although unfortunately AutoHotKey does not allow this trick to be used for function arguments - unnecessary placeholders and function arguments look really bad. but then again whenever I get fancy functions I usually start making them except pseudo-keywords as associative arrays:

Code: Select all

my_notification_fn("message"
, { 0:0
,      msgbox: "longer message"
,      timeout: 1.5
,      tooltip: "short message"
,      tts_say_through_speakers: "problem"
, 0:0 }
Last edited by Sticky on 08 Jul 2022, 14:24, edited 3 times in total.

gregster
Posts: 8884
Joined: 30 Sep 2013, 06:48

Re: Please add topic title here!

Post by gregster » 23 Jun 2022, 19:06

I surely wouldn't expect changes in v1 (due to backwards compatibility and limited future), and I generally wouldn't see Perl as an example to follow, but afaik AHK v2 is more liberal: https://lexikos.github.io/v2/docs/Scripts.htm#continuation
See the "Continuation by enclosure" section.

Btw, please add a meaningful topic title (you can edit your original post, but it might need approval again). Thank you!

Topic moved to 'Wish List' subforum.

Sticky
Posts: 10
Joined: 12 Apr 2017, 22:08

Re: Please add topic title here!

Post by Sticky » 06 Jul 2022, 19:33

OK, I give: *how*do I edit this post to change the title? I can see how to edit other posts I have made, that happen to have titles. But I don't get the "edit" widget on this post.

Is it possible that you don't get that edit widget on a post that doesn't have a proper title? or that it somehow gets hidden?

gregster
Posts: 8884
Joined: 30 Sep 2013, 06:48

Re: Please add topic title here!

Post by gregster » 06 Jul 2022, 19:47

You press the pencil icon on the first post of this topic, like on any post you want to edit. Then you change the 'subject' line, and press 'Submit' (after that, you might have to wait for approval):

Change topic title.png
Change topic title.png (33.11 KiB) Viewed 881 times

Of course, it's recommended to add a meaningful topic subject line right from the start, instead of waiting a few weeks. ;)
Sticky wrote:
06 Jul 2022, 19:33
Is it possible that you don't get that edit widget on a post that doesn't have a proper title? or that it somehow gets hidden?
Since I added a provisional topic title two weeks ago, it currently has a proper title. And I have checked just now: your post is - and was - not locked.
Would be news to me, that you can't edit first posts of a topic on the 'Wish List' subforum (and I see that other people have done it). But just in case, what title would you like to give it?

Edit: I guess it worked :thumbup:

Post Reply

Return to “Wish List”