AutoHotkey Community

It is currently May 27th, 2012, 3:23 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 417 posts ]  Go to page Previous  1 ... 21, 22, 23, 24, 25, 26, 27, 28  Next
Author Message
 Post subject:
PostPosted: May 28th, 2010, 10:18 pm 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1713
Location: Somewhere near you
wolf_II wrote:
Strange, it still works for me.

A few days ago I noticed that the urldownloadtofile command failed on my pc, should I reinstall ahk?

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2010, 10:25 pm 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
I don't know what to recommend, really. Do you think your AutoHotkey.exe got corrupted somehow?

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2010, 10:28 pm 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1713
Location: Somewhere near you
Not corrupted I think. But when I tried to use the urldownloadtofile command, it always failed.

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2010, 10:37 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
tomoe_uehara wrote:
Not corrupted I think. But when I tried to use the urldownloadtofile command, it always failed.
Perhaps and update of your antivirus/firewall software? AHK might be blocked and not allowed to access the internet, try to turnoff your AV/Firewall and see what happens. (turn it back on of course after the test)

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2010, 1:34 am 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
Code:
VarSetCapacity(TEST, 4, 0), NumPut(1, TEST, 0, "UInt")
MsgBox,, Byte Order, % (NumGet(TEST, 0, "Char") ? "Little" : "Big") "-endian"

Is this a valid test for endianness?

Code:
MsgBox,, Word Size, 32 bit

How about this for Word Size?

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: host introspection
PostPosted: May 29th, 2010, 6:55 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
wolf_II wrote:
Code:
VarSetCapacity(TEST, 4, 0), NumPut(1, TEST, 0, "UInt")
MsgBox,, Byte Order, % (NumGet(TEST, 0, "Char") ? "Little" : "Big") "-endian"

Is this a valid test for endianness?

Code:
MsgBox,, Word Size, 32 bit

How about this for Word Size?

endianness test looks ok.
could use ptrsize from ahkL for something close to wordsize:
http://www.autohotkey.net/~Lexikos/Auto ... c.htm#vars


Report this post
Top
 Profile  
Reply with quote  
 Post subject: arithmetic evaluator
PostPosted: May 29th, 2010, 6:59 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Fixed example needing attention: arithmetic evaluator
calclex.ahk
Code:
tokenize(string, lexer)
{
  stringo := string  ; store original string
  locationInString := 1
  size := strlen(string)
  tokens := object()
 
start:
  Enum := Lexer._NewEnum()
  While Enum[type, value]  ; loop through regular expression lexing rules
  {
    if (1 == regexmatch(string, value, tokenValue))
    {
      token := object()     
      token.pos := locationInString
      token.value := tokenValue
      token.length := strlen(tokenValue)
      token.type := type
      tokens._Insert(token)
      locationInString += token.length
      string := substr(string, token.length + 1)
      goto start
    }
    continue
  }
  if (locationInString < size)
    msgbox % "unrecognized token at " substr(stringo, locationInstring)
  return tokens
}

makeCalcLexer()
{
  calcLexer := object()
  PLUS := "\+"
  MINUS := "-"
  MULT := "\*"
  DIV := "/"
  OPEN := "\("
  CLOSE := "\)"
  NUMBER := "\d+"
  WS := "[ \t\n]+"
  END := "\."
  RULES := "PLUS,MINUS,MULT,DIV,OPEN,CLOSE,NUMBER,WS,END"
  loop, parse, rules, `,
  {
    type := A_LoopField
    value := %A_LoopField%
    calcLexer._Insert(type, value)
  }
  return calcLexer
}

printTokens(tokens)
{
  loop % tokens._MaxIndex()
  { 
    tokenString .= printToken(tokens[A_Index]) "`n`n"
  }
  return tokenString
}


printToken(token)
{
  string := "pos= " token.pos "`nvalue= " token.value "`ntype= " token.type
  return string
}
calculator.ahk
Code:
/*
hand coded recursive descent parser
expr   : term ( ( PLUS | MINUS )  term )* ;
term   : factor ( ( MULT | DIV ) factor )* ;
factor   : NUMBER | '(' expr ')';
*/

calcLexer := makeCalcLexer()
string := "((3+4)*(7*9)+3)+4"
tokens := tokenize(string, calcLexer)
msgbox % printTokens(tokens)
ast := expr()
msgbox % printTree(ast)
msgbox % expression := evalTree(ast)
filedelete expression.ahk
fileappend, % "msgbox % " expression, expression.ahk
run, expression.ahk
return


expr()
{
  global tokens
  ast := object(1, "expr")
  if node := term()
    ast._Insert(node)   
  loop
  {
    if peek("PLUS") or peek("MINUS")
    { 
      op := getsym()
      newop := object(1, op.type, 2, op.value)
      node := term()
      ast._Insert(newop)
      ast._Insert(node)
    }
    Else 
      Break
  }
  return ast
}

term()
{
  global tokens
  tree := object(1, "term")
  if node := factor()
    tree._Insert(node)
  loop
  {
    if  peek("MULT") or peek("DIV")
    { 
      op := getsym()
      newop := object(1, op.type, 2, op.value)
      node := factor()
      tree._Insert(newop)
      tree._Insert(node)
    }
    else
      Break
  }
  return tree
}

factor()
{
  global tokens
  if peek("NUMBER")
  { 
    token := getsym()
    tree := object(1, token.type, 2, token.value)
    return tree
  }
  else if  peek("OPEN")
  {
    getsym()
    tree := expr()
    if  peek("CLOSE")
    {
      getsym()
      return tree
    }
    else
      error("miss closing parentheses ")
  }
  else 
    error("no factor found")
}

peek(type, n=1)
{
global tokens
  if (tokens[n, "type"] == type)
  return 1
}

getsym(n=1)
{
global tokens
return token := tokens._Remove(n)
}

error(msg)
{
global tokens
msgbox % msg " at:`n" printToken(tokens[1])
}


printTree(ast)
{
if !ast
return

n := 0
  loop
  {
  n += 1
    if !node := ast[n]
      break
    if !isobject(node)
      treeString .= node
    else
      treeString .= printTree(node)
  }
  return ("(" treeString ")" )
}

evalTree(ast)
{
if !ast
return

n := 1
  loop
  {
  n += 1
    if !node := ast[n]
      break
    if !isobject(node)
      treeString .= node
    else
      treeString .= evalTree(node)
  }
if (n == 3)
return treeString
  return ("(" treeString ")" )
}

#include calclex.ahk

I wonder how much more work to turn this into a tiny parser generator...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2010, 4:44 pm 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1713
Location: Somewhere near you
Image Go AHK go..!!

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject: abstract types
PostPosted: June 2nd, 2010, 2:53 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Solved a few more unsolved tasks:
http://rosettacode.org/wiki/Abstract_type#AutoHotkey
http://rosettacode.org/wiki/Add_a_varia ... AutoHotkey
http://rosettacode.org/wiki/Flatten_a_list#AutoHotkey
http://rosettacode.org/wiki/Associative ... AutoHotkey
http://rosettacode.org/wiki/Call_a_func ... n_language
http://rosettacode.org/wiki/Call_a_fore ... AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 2nd, 2010, 5:23 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
previously thought undoable... (by me :wink: )
runtime evaluation
Code:
; requires AutoHotkey_H or AutoHotkey.dll
msgbox % eval("3 + 4")
msgbox % eval("4 + 4")
return
 
 
eval(expression)
{
global script
script =
(
    expression(){
    return %expression%
  }
)
renameFunction("expression", "")  ; remove any previous expressions
gosub load ; cannot use addScript inside a function yet
exp := "expression"
return %exp%()
}
 
load:
DllCall(A_AhkPath "\addScript","Str",script,"Uchar",0,"Cdecl UInt")
return
 
renameFunction(funcName, newname){
static         
x%newname% := newname   ; store newname in a static variable so its memory is not freed
strput(newname, &x%newname%, strlen(newname) + 1)
if fnp := FindFunc(funcName)
  numput(&x%newname%, fnp+0, 0, "uint")
}

runtime evaluation in an environment
Code:
msgbox % first := evalWithX("x + 4", 5)
msgbox % second := evalWithX("x + 4", 6)
msgbox % second - first
return
 
evalWithX(expression, xvalue)
{
global script
script =
(
    expression(){
    x = %xvalue%  ; := would need quotes
    return %expression%
  }
)
renameFunction("expression", "")  ; remove any previous expressions
gosub load ; cannot use addScript inside a function yet
exp := "expression"
return %exp%()
}
 
load:
DllCall(A_AhkPath "\addScript","Str",script,"Uchar",0,"Cdecl UInt")
return
 
renameFunction(funcName, newname){
static         
x%newname% := newname   ; store newname in a static variable so its memory is not freed
strput(newname, &x%newname%, strlen(newname) + 1)
if fnp := FindFunc(funcName)
  numput(&x%newname%, fnp+0, 0, "uint")
}


Last edited by tinku99 on June 2nd, 2010, 6:03 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: singleton borg pattern
PostPosted: June 2nd, 2010, 5:58 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
previously thought undoable...
http://rosettacode.org/wiki/Singleton#AutoHotkey
Code:
b1 := borg()
b2 := borg()
msgbox % "b1 is b2? " . (b1 == b2)
b1.datum := 3
msgbox % "b1.datum := 3`n...`nb1 datum: " b1.datum "`nb2 datum: " b2.datum ; is 3 also
msgbox % "b1.datum is b2.datum ? " (b1.datum == b2.datum)
return


borg(){
   static borg
   If !borg
      borg := Object("__Set", "Borg_Set"
                   , "__Get", "Borg_Get")
   return object(1, borg, "base", borg)
}


Borg_Get(brg, name)
{
  Return brg[1, name]
}

Borg_Set(brg, name, val)
{
  brg[1, name] := val
  Return val
}

!r::reload
!q::exitapp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 4th, 2010, 2:37 pm 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
User ILAN12346 on the german forum has produced this codefor Lucas-Lehmer test:
Code:
SetBatchLines, -1
M := 3, out := "Mersenne primes:`n"

Loop {
    a = 4
    Loop, % M - 2
        a := Mod(a**2 - 2, 2**M - 1)
    If a = 0
        MsgBox, % out .= " M" M ","
    M++
}

He wonders why the code "fails" after M19, and asks how to overcome the restriction of overflowing 2**M - 1. Can this problem be solved in an elegant way?

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: bignum math
PostPosted: June 4th, 2010, 3:08 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
wolf_II wrote:
User ILAN12346 on the german forum has produced this codefor Lucas-Lehmer test:
Code:
SetBatchLines, -1
M := 3, out := "Mersenne primes:`n"

Loop {
    a = 4
    Loop, % M - 2
        a := Mod(a**2 - 2, 2**M - 1)
    If a = 0
        MsgBox, % out .= " M" M ","
    M++
}

He wonders why the code "fails" after M19, and asks how to overcome the restriction of overflowing 2**M - 1. Can this problem be solved in an elegant way?
I think the task should be considered solved:
Quote:
calculate all Mersenne primes up to the implementation's maximum precision, or the 47th Mersenne prime. (Which ever comes first).
M19 is hitting the implementation precision limit i guess...

The underlying issue is bignum math support. Could just farm out exponentiation and mod functions to a dllcall to something that has bignum support. You already know about the Arbitrary-precision integers task, and discussion page on rosettacode.

Edit: I guess we have our own bignum library by laszlo


Last edited by tinku99 on June 4th, 2010, 4:08 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 4th, 2010, 3:26 pm 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
tinku99 wrote:
You already know about the Arbitrary-precision integers task

Oh yes, I remember very well. I was hoping for a possibility to squeeze M31 out of the code.

tinku99 wrote:
I think the task should be considered solved

Thanks, I will inform ILAN12346 about your approval.

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 7th, 2010, 4:03 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
previously unsolved: Percentage_difference_between_images


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 417 posts ]  Go to page Previous  1 ... 21, 22, 23, 24, 25, 26, 27, 28  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 7 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