Wish to directly recognize the second { as object literal instead of block-begin, to fully support "Keyword parameter"

Discuss the future of the AutoHotkey language
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Wish to directly recognize the second { as object literal instead of block-begin, to fully support "Keyword parameter"

Post by V2User » 31 Dec 2022, 04:46

Dear @Lexicos
Wish to directly recognize the second brace { as object literal instead of a block-begin in double brace {{, to fully support "Keyword parameter" calling.
Currently, we have to write to avoid error:

Code: Select all

; AHK VSERION: 2.0.0
ob:=Cl()
func1()
{
	(0),{base:ob,para1:3,para2:5}.f()
	,{base:ob,para1:8,para2:9}.f()
}
func1()
class Cl{
	prpt1:='0'
	f(){
		OutputDebug(this.prpt1 . this.para1 . this.para2)
	}
}
but with this improvement, we can write:

Code: Select all

ob:=Cl()
func1()
{
	{base:ob,para1:3,para2:5}.f()
	,{base:ob,para1:8,para2:9}.f()
}
func1()
class Cl{
	prpt1:='0'
	f(){
		OutputDebug(this.prpt1 . this.para1 . this.para2)
	}
}
Obviously, it is redundant and unsightly if it is wrapped with any more parentheses just to make codes run. Note: the second brace { closely following the first block brace { will never occur in this V2 language. That is to say, ambiguity will never occur too. So, why not just to fill this real blank which never occurs in all existing V2 codes at present? It is just a single judgement: whether the brace { is right next to another {. It is just a little improvement. It would not produce too much complication for the syntax parser I guess, and much less likely to break any existing code in V2.
The usage in the above code is a little like keyword parameters in Python but far more powerful and flexible than keyword parameters as it's object. Object Oriented Programming can reduce the use of parameters but it even goes one step further to avoid parameters through OOP. You are truly much worth to achieve this enhancement and make OO in V2 more convenient. The Object Oriented Programming in V2 will get reinforced. It can be promoted for heavy use.
It is the last struggle.
Last edited by V2User on 31 Dec 2022, 22:54, edited 3 times in total.

lexikos
Posts: 9664
Joined: 30 Sep 2013, 04:07
Contact:

Re: Wish to directly recognize the second { as object literal instead of block-begin, to fully support "Keyword paramete

Post by lexikos » 31 Dec 2022, 21:10

Are you suggesting that an expression statement would be allowed to start with { only at the start of a block? I'm definitely not adding any such special case to the language, after having removed similar special cases and inconsistencies. I feel it is much better to require parentheses in all cases.

Obviously, it is redundant and unsightly if it is wrapped with any more parentheses just to make codes run.
I disagree. Parentheses provide clarity not only to the parser, but to the reader as well.

Note: the second brace { closely following the first block brace { will never occur in this V2 language.
There is a possibility for v2.x to implement lexically scoped variables, in which case it would be meaningful to use a standalone block, even at the start of another block, to limit the scope of a variable.

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: Wish to directly recognize the second { as object literal instead of block-begin, to fully support "Keyword paramete

Post by V2User » 31 Dec 2022, 23:13

@Lexicos
Last struggle, use `{ to escape from block brace to literal brace, perhaps in V2.x, or perhaps use another symbol if there is a better one. Because the usage of object literal with method will be heavily used at least by me.
Code might be like below.

Code: Select all

; AHK VSERION: 2.0.0
ob:=Cl()
func1()
{
	`{base:ob,para1:3,para2:5}.f()
	,{base:ob,para1:8,para2:9}.f()
}
func1()
class Cl{
	prpt1:='0'
	f(){
		OutputDebug(this.prpt1 . this.para1 . this.para2)
	}
}
It can provide clarity to the parser.

lexikos
Posts: 9664
Joined: 30 Sep 2013, 04:07
Contact:

Re: Wish to directly recognize the second { as object literal instead of block-begin, to fully support "Keyword paramete

Post by lexikos » 01 Jan 2023, 01:26

Why should `{ indicate an expression where { is a block?

There are already several other ways to "provide clarity to the parser".

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: Wish to directly recognize the second { as object literal instead of block-begin, to fully support "Keyword paramete

Post by V2User » 01 Jan 2023, 11:11

@Lexicos
lexikos wrote:
01 Jan 2023, 01:26
Why should `{ indicate an expression where { is a block?

There are already several other ways to "provide clarity to the parser".
But you have already done something for `{. `{ would provide not only clarity to the parser but also consistency. See this code below.

Code: Select all

c::(
d::(send('c'))
e::`{ ;`{ acts like (
f::`{base:Cl()} ;it should acts like (send('c')) too, but it is just the only line that can not run.
Class Cl{
	f(){
		OutputDebug(32)
	}
}
Among all of these Escape Sequences, `{ is the only special case which cannot be applied to other places like all other `. `{ can take less code just like e::`{ is less than e::send('{').
I'm definitely not adding any such special case to the language, after having removed similar special cases and inconsistencies.
So, may you consider killing a special case once more just like what you said above in order to improve consistencies of V2 one step further?

lexikos
Posts: 9664
Joined: 30 Sep 2013, 04:07
Contact:

Re: Wish to directly recognize the second { as object literal instead of block-begin, to fully support "Keyword paramete

Post by lexikos » 01 Jan 2023, 19:35

You quoted my question but your post does not answer it:
I wrote:Why should `{ indicate an expression where { is a block?

But you have already done something for `{.
Not me; Helgef.

`{ in that context denotes a literal symbol, stripped of any special meaning, consistent with `;:: and "`"". You are asking for `{ to act as an expression symbol instead of a block symbol. This is not consistent.
`{ is the only special case which cannot be applied to other places like all other `.
That's false on multiple counts.
1. `{ can be used both in e::`{ and in MsgBox "`{", with the same meaning: a literal brace. It just isn't necessary in the second case.
2. Most other escape sequences are not meaningful outside of quoted strings, hotstrings and similar contexts.

It is special in that no other escape sequences are recognized for remapping, but that is because every other key name doesn't need to be escaped.
f::`{base:Cl()} ;it should acts like (send('c')) too
It does. Like d::(send('c')), it has the same effect as using a block and a separate line.

Code: Select all

a::(  ; remap
b::(send('c'))  ; statement
c::{
    (send('c'))  ; statement
}
d::`{  ; remap
e::`{a:1}  ; invalid statement
f::{
    `{a:1}  ; invalid statement
}
just like e::`{ is less than e::send('{').
Taking less code isn't the point. A remap is not the same as a hotkey that sends a key or text. Also, beside the point, but send('{') will not do anything useful.
So, ...
The rest of this question made no sense to me.

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: Wish to directly recognize the second { as object literal instead of block-begin, to fully support "Keyword paramete

Post by V2User » 01 Jan 2023, 22:47

@Lexicos
Sorry, perhaps makes no sense but I have to say that I've typed something wrong above. It is not f::`{base:Cl()} but `f::{base:Cl()}.f() instead.
What I want to express is that when functions with parameters can "one line" then methods with literal should the same "one line" too:

Code: Select all

c::ff(32) ;can one line
d::`{base:Cl(),para:32}.ff() ;should one line like above

try ff(32) ;can one line
try `{base:Cl(),para:32}.ff() ;should one line like above


ff(c)=>OutputDebug(c)
Class Cl{
	ff()=>OutputDebug(this.para)
}
Obviously, one line above is less perhaps more elegant than the current below:

Code: Select all

d::{
	(0)
	,{base:Cl(),para:32}.ff()
}
try{
	(0)
	,{base:Cl(),para:32}.ff()
}
"Object Oriented should be deeply supported by V2" is my opinion, even in one-line cases. Methods with literal are what I am going to use everywhere in V2, perhaps may be promoted and popularized in the future. At least methods should be totally on an equal footing with functions. Shouldn't they? :P
You quoted my question but your post does not answer it:
Why should `{ indicate an expression where { is a block?
Can these above answer your questions? :P

lexikos
Posts: 9664
Joined: 30 Sep 2013, 04:07
Contact:

Re: Wish to directly recognize the second { as object literal instead of block-begin, to fully support "Keyword paramete

Post by lexikos » 02 Jan 2023, 00:02

You already explained that, and no, that all completely fails to answer my question.
Why should `{ indicate an expression where { is a block?
Given all alternatives already available for use and other possibilities not yet implemented, why should this specific syntax have the interpretation you are asking for?

Post Reply

Return to “AutoHotkey Development”