AutoHotkey Community

It is currently May 26th, 2012, 6:52 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: April 9th, 2005, 2:46 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I could hardly wait to get home and try the new functions. Gorgeous! We can even have variable number of arguments with a little trick, as the example below shows. The MIN#(x) and MAX#(x) functions take a list of numbers, parse them into an array and search this array for the smallest or the greatest number. The calling is simple
Code:
MIN#("1, -5, 2.345, 0")
MAX#("0," x "," y "," z)
The later one uses variables. Their values are substituted at the call, the function just sees a bunch of numbers.

I copy here the test script I played with. Hope you like to experiment, too.
Code:
!1::
   InputBox x, Parameter, type in a number,, 160, 140
   InputBox f, Function,  function name?,,   160, 140
   IfEqual f, SQRT, MsgBox %  SQRT(x)
   IfEqual f,  EXP, MsgBox %   EXP(x)
   IfEqual f,  LOG, MsgBox %   LOG(x)
   IfEqual f,   LN, MsgBox %    LN(x)
   IfEqual f,  ABS, MsgBox %   ABS(x)
   IfEqual f, CEIL, MsgBox %  CEIL(x)
   IfEqual f,FLOOR, MsgBox % FLOOR(x)
return


!2::
   InputBox x, Parameter 1, type in a number,, 160, 140
   InputBox y, Parameter 2, type in a number,, 160, 140
   InputBox f, Function,    function name?,,   160, 140
   IfEqual f,  MIN, MsgBox %   MIN(x,y)
   IfEqual f,  MAX, MsgBox %   MAX(x,y)
   IfEqual f,  MOD, MsgBox %   MOD(x,y)
   IfEqual f,  POW, MsgBox %   POW(x,y)
   IfEqual f,ROUND, MsgBox % ROUND(x,y)
return

!3::
   InputBox x, Parameter 1, type in a number,, 160, 140
   InputBox y, Parameter 2, type in a number,, 160, 140
   InputBox z, Parameter 3, type in a number,, 160, 140
   InputBox f, Function,    function name?,,   160, 140
   IfEqual f,MIN, MsgBox % MIN#(x "," y "," z)
   IfEqual f,MAX, MsgBox % MAX#(x "," y "," z)
return

MAX(x,y)
{
   IfLess x,%y%, Return y
   Return x
}

MAX#(x)     ; MAX#("1,-5,2.345," var1 "," var2)
{
   StringSplit y, x, `,, %A_Space%%A_Tab%
   mx := y%y0%
   loop % y0-1
      IfLess mx, % y%A_Index%, SetEnv mx, % y%A_Index%
   Return mx
}

MIN(x,y)
{
   IfLess x,%y%, Return x
   Return y
}

MIN#(x)     ; MIN#("1,-5,2.345," var1 "," var2)
{
   StringSplit y, x, `,, %A_Space%%A_Tab%
   mx := y%y0%
   loop % y0-1
      IfGreater mx, % y%A_Index%, SetEnv mx, % y%A_Index%
   Return mx
}

MOD(x,m)
{
   Transform y, mod, %x%, %m%
   Return y
}

SQRT(x)
{
   Transform y, sqrt, %x%
   Return y
}

POW(x,p)
{
   Transform y, pow, %x%, %p%
   Return y
}
...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2005, 2:57 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Oh, I'm experimenting all right. *evil snicker*


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 9th, 2005, 3:51 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Laszlo wrote:
We can even have variable number of arguments with a little trick, as the example below shows.
Nice trick and a great set of functions you put together. Although I'm going to look into native support for a varying number of arguments, support for default parameters -- which allow the caller to omit optionally omit them -- is probably a higher priority.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], mrhobbeys, nothing, siterip, Stigg and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group