June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,127 @@
; Associative arrays in AutoIt.
; All the required functions are below the examples.
; Initialize an error handler to deal with any COM errors..
global $oMyError = ObjEvent("AutoIt.Error", "AAError")
; first example, simple.
global $simple
; Initialize your array ...
AAInit($simple)
AAAdd($simple, "Appple", "fruit")
AAAdd($simple, "Dog", "animal")
AAAdd($simple, "Silicon", "tetravalent metalloid semiconductor")
ConsoleWrite("It is well-known that Silicon is a " & AAGetItem($simple, "Silicon") & "." & @CRLF)
ConsoleWrite(@CRLF)
; A more interesting example..
$ini_path = "AA_Test.ini"
; Put this prefs section in your ini file..
; [test]
; foo=foo value
; foo2=foo2 value
; bar=bar value
; bar2=bar2 value
global $associative_array
AAInit($associative_array)
; We are going to convert this 2D array into a cute associative array where we
; can access the values by simply using their respective key names..
$test_array = IniReadSection($ini_path, "test")
for $z = 1 to 2 ; do it twice, to show that the items are *really* there!
for $i = 1 to $test_array[0][0]
$key_name = $test_array[$i][0]
ConsoleWrite("Adding '" & $key_name & "'.." & @CRLF)
; key already exists in "$associative_array", use the pre-determined value..
if AAExists($associative_array, $key_name) then
$this_value = AAGetItem($associative_array, $key_name)
ConsoleWrite("key_name ALREADY EXISTS! : =>" & $key_name & "<=" & @CRLF)
else
$this_value = $test_array[$i][1]
; store left=right value pair in AA
if $this_value then
AAAdd($associative_array, $key_name, $this_value)
endif
endif
next
next
ConsoleWrite(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" & @CRLF)
AAList($associative_array)
ConsoleWrite(@CRLF & "Removing 'foo'..")
AARemove($associative_array, "foo")
ConsoleWrite(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" & @CRLF)
AAList($associative_array)
AAWipe($associative_array)
; end
func AAInit(ByRef $dict_obj)
$dict_obj = ObjCreate("Scripting.Dictionary")
endfunc
; Adds a key and item pair to a Dictionary object..
func AAAdd(ByRef $dict_obj, $key, $val)
$dict_obj.Add($key, $val)
If @error Then return SetError(1, 1, -1)
endfunc
; Removes a key and item pair from a Dictionary object..
func AARemove(ByRef $dict_obj, $key)
$dict_obj.Remove($key)
If @error Then return SetError(1, 1, -1)
endfunc
; Returns true if a specified key exists in the associative array, false if not..
func AAExists(ByRef $dict_obj, $key)
return $dict_obj.Exists($key)
endfunc
; Returns a value for a specified key name in the associative array..
func AAGetItem(ByRef $dict_obj, $key)
return $dict_obj.Item($key)
endfunc
; Returns the total number of keys in the array..
func AACount(ByRef $dict_obj)
return $dict_obj.Count
endfunc
; List all the "Key" > "Item" pairs in the array..
func AAList(ByRef $dict_obj)
ConsoleWrite("AAList: =>" & @CRLF)
local $k = $dict_obj.Keys ; Get the keys
; local $a = $dict_obj.Items ; Get the items (for reference)
for $i = 0 to AACount($dict_obj) -1 ; Iterate the array
ConsoleWrite($k[$i] & " ==> " & AAGetItem($dict_obj, $k[$i]) & @CRLF)
next
endfunc
; Wipe the array, obviously.
func AAWipe(ByRef $dict_obj)
$dict_obj.RemoveAll()
endfunc
; Oh oh!
func AAError()
Local $err = $oMyError.number
If $err = 0 Then $err = -1
SetError($err) ; to check for after this function returns
endfunc
;; End AA Functions.

View file

@ -1,6 +1,6 @@
import system'collections.
program =
public program =
[
// 1. Create
var aMap := Dictionary new.

View file

@ -1,27 +1,26 @@
julia> hash = {'a' => 97, 'b' => 98} # list keys/values
{'a'=>97,'b'=>98}
dict = Dict('a' => 97, 'b' => 98) # list keys/values
# Dict{Char,Int64} with 2 entries:
# 'b' => 98
# 'a' => 97
julia> hash = {c => int(c) for c = 'a':'d'} # dict comprehension
{'a'=>97,'c'=>99,'b'=>98,'d'=>100}
dict = Dict(c => Int(c) for c = 'a':'d') # dict comprehension
# Dict{Char,Int64} with 4 entries:
# 'b' => 98
# 'a' => 97
# 'd' => 100
# 'c' => 99
julia> hash['é'] = 233 ; hash # add an element
{'a'=>97,'c'=>99,'b'=>98,'é'=>233,'d'=>100}
dict['é'] = 233; dict # add an element
# Dict{Char,Int64} with 3 entries:
# 'b' => 98
# 'a' => 97
# 'é' => 233
julia> hash = Dict() # create an empty dict
Dict{Any,Any}()
emptydict = Dict() # create an empty dict
# Dict{Any,Any} with 0 entries
julia> for c = 'a':'d' hash[c] = int(c) end ; hash # fill it
{'a'=>97,'c'=>99,'b'=>98,'d'=>100}
dict["a"] = 1 # type mismatch
# ERROR: MethodError: Cannot `convert` an object of type String to an object of type Char
julia> hash = (Char=>Int64)['a' => 97, 'b' => 98] # create a typed dict
['a'=>97,'b'=>98]
julia> hash["a"] = 1 # type mismatch
ERROR: no method convert(Type{Char}, ASCIIString)
in setindex! at dict.jl:533
julia> hash = Dict(['a','b','c'], [97,98,99]) # constructor
['a'=>97,'c'=>99,'b'=>98]
julia> typeof(hash) # type is infered correctly
Dict{Char,Int64} (constructor with 3 methods
typeof(dict) # type is infered correctly
# Dict{Char,Int64}

View file

@ -0,0 +1,28 @@
my %h1 = key1 => 'val1', 'key-2' => 2, three => -238.83, 4 => 'val3';
my %h2 = 'key1', 'val1', 'key-2', 2, 'three', -238.83, 4, 'val3';
# Creating a hash from two lists using a metaoperator.
my @a = 1..5;
my @b = 'a'..'e';
my %h = @a Z=> @b;
# Hash elements and hash slices now use the same sigil as the whole hash. This is construed as a feature.
# Curly braces no longer auto-quote, but Perl 6's qw (shortcut < ... >) now auto-subscripts.
say %h1{'key1'};
say %h1<key1>;
%h1<key1> = 'val1';
%h1<key1 three> = 'val1', -238.83;
# Special syntax is no longer necessary to access a hash stored in a scalar.
my $h = {key1 => 'val1', 'key-2' => 2, three => -238.83, 4 => 'val3'};
say $h<key1>;
# Keys are of type Str or Int by default. The type of the key can be provided.
my %hash{Any}; # same as %hash{*}
class C {};
my %cash{C};
%cash{C.new} = 1;

View file

@ -0,0 +1,10 @@
# Project Associative array/Creation
# Date 2018/03/24
# Author Gal Zsolt [~ CalmoSoft ~]
# Email <calmosoft@gmail.com>
myarray = [["one",1],
["two",2],
["three",3]]
see find(myarray,"two",1) + nl
see find(myarray,2,2) + nl