Operators vs Methods

Discuss the future of the AutoHotkey language
iseahound
Posts: 355
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Operators vs Methods

05 Oct 2018, 18:20

So I hate to bring this up but Click does not return anything...

Code: Select all

CoordMode("Mouse", "Screen")
SetMouseDelay(100)
list := [[ 30, A_ScreenHeight-25]   ; click start menu
        ,[600, 600]]                ; click away
MsgBox list.1.1
clickfn := Func("Click")
newList := map(list, clickfn)
MsgBox newList.1.1
return


map(array, func) {
   outarr := []
   for i,v in array
      outarr[i] := %func%(v*)
   return outarr
}
I'm surprised, since this is my first time using v2. Needless to say this behavior is VERY odd.
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Operators vs Methods

06 Oct 2018, 01:29

How is this odd? What did you expect click to return?
Recommends AHK Studio
guest3456
Posts: 2468
Joined: 09 Oct 2013, 10:31

Re: Operators vs Methods

06 Oct 2018, 02:52

iseahound wrote:So I hate to bring this up but Click does not return anything...Needless to say this behavior is VERY odd.
you should hate to bring it up because it makes no sense. this is not odd at all. you're searching for a problem when there is none. you asked for a way to map Click and i provided it. naturally Click() isn't going to return anything useful so you're aren't looking to use the return value, but rather just execute the Click. Click was just a command in v1, and in v2 all commands can be called with function syntax. because there is no OutputVar param for the Click command, the function version doesn't return anything. you should know that, but you admit you haven't even used v2. and yet you are citing the Commands vs Functions link.. :crazy:

typically map() is used in functional programming in which case you would want the return value, so you can chain shit together like reduce(filter(map())):

the code below works in BOTH v1 and v2 (remove the % in the MsgBox for v2)

Code: Select all

list := [1,2,3,4,5]
MsgBox % reduce(filter(map(list, Func("increment")), Func("isEven")), Func("sum"))
; map = [2,3,4,5,6]
; filter = [2,4,6]
; reduce = 12
return


increment(a) {
   return a+1
}

sum(a,b) {
   return a+b
}

isEven(a) {
   return (Mod(a,2) = 0)
}


map(array, func) {
   outarr := []
   for i,v in array
      outarr[i] := %func%(v)
   return outarr
}


reduce(array, func, init:=0) {
   out := init
   for i,v in array
      out := %func%(out, v)
   return out
}


filter(array, func) {
   outarr := []
   for i,v in array
      if %func%(v)
         outarr.Push(v)
   return outarr
}

v2 only (fat arrows):
Spoiler
iseahound wrote:this is my first time using v2.
shouldn't that be a prerequisite before starting a thread such as this?

iseahound
Posts: 355
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Operators vs Methods

11 Oct 2018, 12:49

nnnik wrote:How is this odd? What did you expect click to return?
I expected Click to return its arguments, unmodified.
guest3456 wrote:
iseahound wrote:this is my first time using v2.
shouldn't that be a prerequisite before starting a thread such as this?
I don't know. This will take a long time to explain, and I will make a new thread, so this one can focus on operators and methods. As a brief rebuttal, consider the order of your arguments. You've placed the array first, and the function second. Instead try this:

Code: Select all

greaterThan100 := Func("Max").Bind(100)
MsgBox % greaterThan100.call(99)
Now I've built up functions from smaller functions by binding a partial argument to existing functions. So with map and click it should be:

Code: Select all

ClickAll := Func("map").Bind(Func("Click"))
%ClickAll%(array)
where the map function becomes "apply to all" as in %ClickAll%().
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Operators vs Methods

11 Oct 2018, 15:47

I cannot see a single good reason why a function should return its own inputs
Recommends AHK Studio
iseahound
Posts: 355
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Operators vs Methods

11 Oct 2018, 19:38

Image
Because in this case the function click is defined as an input (A) to an output (A) + side effect (∊).

Also consider these 3 properties:
Image
Now as a bonus, try to find a function that satisfies all three properties :p

You could make the argument that Click is an effect and not a function, mapping its inputs to nothing, but then you'd also assume that there exist effect types and function types.

Finally imagine you have a data. After passing your data through click it disappears. Instead of disappearing, functions should return a new state such that future functions can act upon the state and return new states. Note that data is never modified, a function creates a new state containing the modified data.

Apologies for the brief response, but you can see effect types in action in the experimental language Koka and I think in Purescript, a functional language that compiles to Javascript. (I think)

EDIT: Just to clarify, a function does not return its own inputs. It returns a copy of the input with any modifications.
Helgef
Posts: 3303
Joined: 17 Jul 2016, 01:02
Contact:

Re: Operators vs Methods

12 Oct 2018, 01:16

Click has no obvious candidate for epsilon. Compare to, for example numput, which maps A -> A + e

Cheers.
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Operators vs Methods

12 Oct 2018, 01:26

A return value for a specific program can only be defined once. And you want to assign it to an architecture that is currently not present in AHK.
Currently Click returns nothing. However in the future it may return the window or the control it ended up clicking on.
Or maybe we really do find a way to tell if a click was likely successful.
All of these possibilities are more important than adding the one you suggested - which can be summed up as just return its inputs.
Recommends AHK Studio
guest3456
Posts: 2468
Joined: 09 Oct 2013, 10:31

Re: Operators vs Methods

12 Oct 2018, 10:24

iseahound wrote:. As a brief rebuttal, consider the order of your arguments. You've placed the array first, and the function second.

.. So with map and click it should be:

Code: Select all

ClickAll := Func("map").Bind(Func("Click"))
%ClickAll%(array)
where the map function becomes "apply to all" as in %ClickAll%().
good thing i've created that map() function myself, i can change the argument order as i please (and so can you). how is this a rebuttal at all? you were completely unaware that you could create your own map() function, and now youre shown a solution, and you're rebutting it? lol

iseahound
Posts: 355
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Operators vs Methods

12 Oct 2018, 11:58

I've never considered the existence of a map() function to be paramount, but rather trivial. In other words, I was surprised that a map() function was not built in.

Had a map() function been built in, it would have error-ed out because:
  • Click is not a function, so map would have returned an empty state.
  • The fact is that an object can not be the 1st argument due to partial evaluation and binding of arguments, currying
Currying evaluates a function by taking a function with multiple arguments and evaluating its first argument first, thus returning a function that accepts a second argument. I've shown how this would be accomplished in AutoHotkey, and honestly it's slightly weird with percent signs around the function reference. The truth is that many people would consider the order of arguments to be insignificant, but that's because AHK makes things easy. It can seem insignificant, but when designing a computer language, it's important to realize that it's a system for computation. And computation is a form of change, which most math teachers would call calculus. So looking back towards lambda calculus, we can see that multiple arguments do not exist and only the concept of partial evaluation or decomposing an input into multiple arguments exist. It happens that both forms are isomorphic, so choose which ever form is more convenient.

As for it seeming unnatural for Click to return its arguments, the only explanation that remains is that click is not a function but an effect. Any attempt to return a window, or something else is too non-deterministic, and likely to error out. It may be possible, but for the time being it should return nothing since it interacts with the world, and a program in AutoHotkey, like most programs, make assumptions about the world. (in fact most languages like Python which output to the console make 0 assumptions about the console, or even if the console exists. I think that if stdout isn't captured it just disappears or gets garbage collected or something.)
iseahound
Posts: 355
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Operators vs Methods

12 Oct 2018, 12:10

Helgef wrote:Click has no obvious candidate for epsilon. Compare to, for example numput, which maps A -> A + e

Cheers.
I'm pretty sure the + means choice, so A gets mapped to A or e. Careful with the symbols! They tend to mean different things in different areas of mathematics. That's why I wanted operator overriding, it's much better to think of + as a symbol, nothing more and nothing less.

Here's a computerphile video about moving from classical logic to intuitionistic logic: https://www.youtube.com/watch?v=SknxggwRPzU
guest3456
Posts: 2468
Joined: 09 Oct 2013, 10:31

Re: Operators vs Methods

12 Oct 2018, 12:33

iseahound wrote:I've never considered the existence of a map() function to be paramount, but rather trivial. In other words, I was surprised that a map() function was not built in.

Had a map() function been built in, it would have error-ed out because:
  • Click is not a function, so map would have returned an empty state.
  • The fact is that an object can not be the 1st argument due to partial evaluation and binding of arguments, currying
Currying evaluates a function by taking a function with multiple arguments and evaluating its first argument first, thus returning a function that accepts a second argument. I've shown how this would be accomplished in AutoHotkey, and honestly it's slightly weird with percent signs around the function reference. The truth is that many people would consider the order of arguments to be insignificant, but that's because AHK makes things easy. It can seem insignificant, but when designing a computer language, it's important to realize that it's a system for computation. And computation is a form of change, which most math teachers would call calculus. So looking back towards lambda calculus, we can see that multiple arguments do not exist and only the concept of partial evaluation or decomposing an input into multiple arguments exist. It happens that both forms are isomorphic, so choose which ever form is more convenient.

As for it seeming unnatural for Click to return its arguments, the only explanation that remains is that click is not a function but an effect. Any attempt to return a window, or something else is too non-deterministic, and likely to error out. It may be possible, but for the time being it should return nothing since it interacts with the world, and a program in AutoHotkey, like most programs, make assumptions about the world. (in fact most languages like Python which output to the console make 0 assumptions about the console, or even if the console exists. I think that if stdout isn't captured it just disappears or gets garbage collected or something.)
what point are you trying to make?

rewrite the map() function i provided and put your function argument first instead of second. done.

you started this by making a claim "what AHK is missing out on", i showed you that it isn't missing out on it. you gave the mapping Click example, i solved it. now you're complaining about a parameter order that you can freely change, and accomplish your currying goal. if there is something else that you're trying to do with AHK that you cannot, ask again, and lets see if someone can do it or if you've reached a true limitation of the language.
iseahound wrote:Click is not a function, so map would have returned an empty state.
Click is a function now, but you're unfamiliar with v2 so you didn't know that

iseahound wrote:and honestly it's slightly weird with percent signs around the function reference.
rtfm. so use .Call() instead. works in both v1 and v2
https://autohotkey.com/docs/objects/Func.htm#Call
https://lexikos.github.io/v2/docs/objects/Func.htm#Call

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

Re: Operators vs Methods

12 Oct 2018, 12:52

.Call() does not work with all function types you can call-
Recommends AHK Studio
Helgef
Posts: 3303
Joined: 17 Jul 2016, 01:02
Contact:

Re: Operators vs Methods

12 Oct 2018, 13:14

I'm pretty sure the + means choice
If you know what numput does it is pretty obvious what it means.
Careful with the symbols! They tend to mean different things in different areas of mathematics.
Are we doing strict mathematics here? I don't think so.

Cheers.

Edit:
iseahound wrote:There's no strict mathematics, only mathematics.
If you want it to be black or white, you could argue that everything is mathematics, or nothing is, however, havning a more multifaceted view is more practical. This discussion doesn't interest me.
I'll elaborate some of my ideas is a future post.
:thumbup:

Cheers.
Last edited by Helgef on 13 Oct 2018, 06:37, edited 1 time in total.
iseahound
Posts: 355
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Operators vs Methods

12 Oct 2018, 14:14

I'll elaborate some of my ideas is a future post. For the time being, it would be wise to remember the history of programming. I was taught lambda calculus and scheme first, and although I hated it and absolutely dispised it, calling it useless, impractical, and without meaning, lately it is the exact opposite. There's no strict mathematics, only mathematics. You think there is a difference between the two, but that distinction is becoming more and more blurred.

An analogy: If I had an apple and told you its exact cellular structure, that its principle taste compounds were isoamylvalerate and beta-damascone, that its color, shape, and texture were mapped to precise mathematical equations shown here, would this change your perception of this apple?

No way. You'd probably enjoy it's superior taste and texture the same way all of humanity has since time past.

You'd eat it.

But what if I told you there was a desire to create a new fruit? Neither Apple, nor pear, peach, grape or otherwise. Something new.

Suddenly, it's necessary. A biologist, genetic engineer, chemist, biochemist, and more.
User avatar
jeeswg
Posts: 5424
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Operators vs Methods

18 Oct 2018, 17:34

@iseahound: If higher level concepts have influenced your AutoHotkey v2 Development ideas, what about lower level concepts? Assembly language etc. Cheers.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 14 guests