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 

Challenge: translate rosettacode - Was promoting autohotkey
Goto page Previous  1, 2, 3 ... 23, 24, 25, 26, 27, 28  Next
 
Reply to topic    AutoHotkey Community Forum Index -> General Chat
View previous topic :: View next topic  
Author Message
tomoe_uehara



Joined: 05 Sep 2009
Posts: 1591
Location: Somewhere near you

PostPosted: Fri May 28, 2010 9:18 pm    Post subject: Reply with quote

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?
_________________

The quick onyx goblin jumps over the lazy dwarf
Back to top
View user's profile Send private message
wolf_II



Joined: 18 Oct 2007
Posts: 343
Location: Saarland, Germany

PostPosted: Fri May 28, 2010 9:25 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
tomoe_uehara



Joined: 05 Sep 2009
Posts: 1591
Location: Somewhere near you

PostPosted: Fri May 28, 2010 9:28 pm    Post subject: Reply with quote

Not corrupted I think. But when I tried to use the urldownloadtofile command, it always failed.
_________________

The quick onyx goblin jumps over the lazy dwarf
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Fri May 28, 2010 9:37 pm    Post subject: Reply with quote

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 Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
wolf_II



Joined: 18 Oct 2007
Posts: 343
Location: Saarland, Germany

PostPosted: Sat May 29, 2010 12:34 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Sat May 29, 2010 5:55 am    Post subject: host introspection Reply with quote

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/AutoHotkey_L/docs/Misc.htm#vars
Back to top
View user's profile Send private message Send e-mail Visit poster's website
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Sat May 29, 2010 5:59 am    Post subject: arithmetic evaluator Reply with quote

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...
Back to top
View user's profile Send private message Send e-mail Visit poster's website
tomoe_uehara



Joined: 05 Sep 2009
Posts: 1591
Location: Somewhere near you

PostPosted: Sun May 30, 2010 3:44 pm    Post subject: Reply with quote

Go AHK go..!!
_________________

The quick onyx goblin jumps over the lazy dwarf
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Wed Jun 02, 2010 1:53 am    Post subject: abstract types Reply with quote

Solved a few more unsolved tasks:
http://rosettacode.org/wiki/Abstract_type#AutoHotkey
http://rosettacode.org/wiki/Add_a_variable_to_a_class_instance_at_runtime#AutoHotkey
http://rosettacode.org/wiki/Flatten_a_list#AutoHotkey
http://rosettacode.org/wiki/Associative_arrays/Iteration#AutoHotkey
http://rosettacode.org/wiki/Call_a_function_from_a_foreign_language
http://rosettacode.org/wiki/Call_a_foreign-language_function#AutoHotkey
Back to top
View user's profile Send private message Send e-mail Visit poster's website
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Wed Jun 02, 2010 4:23 am    Post subject: eval and eval in environment Reply with quote

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 Wed Jun 02, 2010 5:03 am; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Wed Jun 02, 2010 4:58 am    Post subject: singleton borg pattern Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
wolf_II



Joined: 18 Oct 2007
Posts: 343
Location: Saarland, Germany

PostPosted: Fri Jun 04, 2010 1:37 pm    Post subject: Reply with quote

User ILAN12346 on the german forum has produced this code for 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!
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Fri Jun 04, 2010 2:08 pm    Post subject: bignum math Reply with quote

wolf_II wrote:
User ILAN12346 on the german forum has produced this code for 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 Fri Jun 04, 2010 3:08 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
wolf_II



Joined: 18 Oct 2007
Posts: 343
Location: Saarland, Germany

PostPosted: Fri Jun 04, 2010 2:26 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Mon Jun 07, 2010 3:03 am    Post subject: Percentage_difference_between_images Reply with quote

previously unsolved: Percentage_difference_between_images
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> General Chat All times are GMT
Goto page Previous  1, 2, 3 ... 23, 24, 25, 26, 27, 28  Next
Page 24 of 28

 
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