AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Single-line subroutine

 
Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
a_h_k



Joined: 02 Feb 2008
Posts: 626

PostPosted: Wed Dec 16, 2009 10:03 am    Post subject: Single-line subroutine Reply with quote

Recently i wanted to use a really simple subroutine
Code:
Sendi:Send i
But of course it didn't work (error)

Hotkeys can have them
Code:
Hotkey::Send i
So why not subroutines also ??
Back to top
View user's profile Send private message Visit poster's website
Tuncay n-l-i mobile
Guest





PostPosted: Wed Feb 24, 2010 6:14 pm    Post subject: Reply with quote

yes why not
Back to top
ruespe



Joined: 17 Jun 2008
Posts: 243

PostPosted: Wed Mar 03, 2010 9:33 am    Post subject: Reply with quote

Mmmhhh... why should it be easier to write
Code:
Gosub Sendi
:
:
:
Sendi:Send i
than to write
Code:
Send i
Question
_________________
Greetings
Rog
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Thu Mar 04, 2010 8:59 am    Post subject: Reply with quote

Why should
Code:
0or1:   v := !v
        Send %v%
        return
be equivalent to
Code:
0or1:
        v := !v
        return
        Send %v%
        return
and not
Code:
0or1:
        v := !v
        Send %v%
        return
???

Labels should be nothing more than a way to mark (or label) a particular line. Allowing same-line subroutines by automatically inserting return would be counter-intuitive, especially for users of other languages which have goto/same-line labels, or if goto is used with that particular label. Perhaps this ambiguity is why it is not allowed.

C and some similar languages allow same-line labels, but limit the characters allowed in label names (i.e. to alphanumeric characters/underscore). OTOH, AutoHotkey allows virtually anything besides whitespace, comma or operators like =. Supporting same-line labels while still allowing this freedom would require more complicated parsing methods and might introduce other conflicts.


That aside, I suppose that Gui and Menu would be better examples of where single-line subroutines would be convenient; i.e. because the code must be in a separate subroutine, not in-line.
Code:
Menu, M, Add, Help
Menu, M, Show
ExitApp

Help: MsgBox feature not implemented
OTOH, others have requested capabilities like:
Code:
Menu, M, Add, Help, MsgBox("feature not implemented")
Menu, M, Show
ExitApp
... which would lessen the need for same-line subroutines.
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Thu Mar 04, 2010 1:47 pm    Post subject: Reply with quote

Likewise (& however useful), perhaps single-line Hotkeys should be removed...cuz there are alot of people making this mistake...

Code:
F9::msgbox, This works...
msgbox, ...but it don't continue? why?

...but maybe instead of removing single-line Hotkeys...AutoHotkey could, by default (& overridably), complain about "stranded code", code that can never be reached, based on positioning...
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group