AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1036 posts ]  Go to page Previous  1 ... 43, 44, 45, 46, 47, 48, 49 ... 70  Next
Author Message
 Post subject:
PostPosted: July 22nd, 2010, 2:35 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
Could you allow passing literal expressions such as "string" or 5 as ByRef parameter?

I don't always need the modified value, and it would be nicer to use if you didn't have to define it as a variable first.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 3:12 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Lexikos wrote:
I am considering changing it.
That would be awsome :)
Logically, I think obj.x[] should be same as obj.x[""] or am I wrong?

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 3:55 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
fragman wrote:
Could you allow passing literal expressions such as "string" or 5 as ByRef parameter?

Yeh, I always wondered why this hadn't been supported when default ByRef value was introduced.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 10:58 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
fragman wrote:
Could you allow passing literal expressions such as "string" or 5 as ByRef parameter?
Perhaps, but some load-time validation would be sacrificed.
HotKeyIt wrote:
Logically, I think obj.x[] should be same as obj.x[""] or am I wrong?
Haven't we already been over this? It is useful to be able to distinguish between [] and [""]. Aside from that, there's nothing particularly intuitive about treating [] as [""] or even using [""] in general. Finally, it's only loosely related to the change I was talking about.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2010, 12:53 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Lexikos wrote:
Haven't we already been over this? It is useful to be able to distinguish between [] and [""]

I just don't get it why this is useful :(
Especially that you can't save anything in object[], only run a meta function :?

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2010, 1:36 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
For the very reason that nothing can be "saved in" object[], it is guaranteed to always run the meta-function. If an object is used to store any arbitrary string value (including ""), making [] equivalent to [""] would exclude its use for any other special purpose. If you want them to be equivalent, you can make them equivalent via __Get.

In addition, there is no key specified with x[]:=y, so creating a key-value pair by default would be illogical. You've told it to assign the value to nothing, so it does exactly that.

FYI, in IronAHK that syntax is used to extend arrays.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2010, 7:39 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Thank you very much Lexikos, that really makes sense. Now I can consider this for my scripts :D

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 26th, 2010, 12:07 am 
Offline

Joined: March 12th, 2009, 12:02 pm
Posts: 3
(sorry for bad english) :oops:
thanks so much for your excellent works;
i want to ask, is possible to serialize (like in java ...) ahkL object, make it persistent, save to a file? if this is not possible now, do you support this features in future? it would be great! thanks for your interest for now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2010, 4:44 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
It is possible using an enumerator and FileAppend or FileOpen(). The file format and code to create it is entirely up to you - there is no ready-made function.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2010, 12:20 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
2kraker148
For start, take a look at tinku's RichObject, there is print function:

Code:
objPrint(ast, reserved=0)
{
  if !isobject(ast)
    return " " ast " "
 
  if !reserved
    reserved := object("seen" . &ast, 1)  ; to keep track of unique objects within top object
 
  enum := ast._newenum()
  while enum[key, value]
  {
    if reserved["seen" . &value]
      string .= key . ": WARNING: CIRCULAR OBJECT SKIPPED !!!`n " 
    else
      string .= key . ": " . objPrint(value, reserved) "`n"
  }
  return "(" string ") "
}


This is serialization, you need reverse function to de-serialize objects.
You could try to change or utilize YAML by HotkeyIt to work with objects.

If you require to (de)serialze binary data, there are various functions on the forum that deal with binary <-> hex, mime, compress etc.. conversion

Lex wrote:
there is no ready-made function

However, there is a need for standardized serialization function, probably the best via library with documentation for it included in your official docs. Most of the similar languages have something like that, either internally or via library.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2010, 2:23 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
majkinetor wrote:
However, there is a need for standardized serialization function, probably the best via library with documentation for it included in your official docs.
I agree. I have many other priorities at the moment so will not consider working on this myself. Whether it is built-in or implemented in script, I think the most important part would be to ensure objects can define how they are serialized. For instance, objects may be strictly serialized individually allowing references between them, or have their contents nested in the output of the parent object. One object might contain strings and another might contain binary data in "string" fields. (I see that YAML supports both references and binary data.) Some fields might not even be needed, and some types of objects might need specialized de-serialization behaviour. Serializing or de-serializing an object's base is a bit of a grey area.

One advantage of including important functionality like this as a script library is that anyone can learn from, adapt or improve it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2010, 2:41 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
Serializing or de-serializing an object's base is a bit of a grey area.

What prevents one to threat base as any other object in this manner ?

Quote:
Some fields might not even be needed, and some types of objects might need specialized de-serialization behaviour.

The good mechanism would involve default and user provided handlers. Then library of specialized handlers could me made for specific cases.

Also, the perfect library shouldn't bind user to any standard like JSON or YAML but make them default only. DI can be used to keep all other mechanisms in place while allowing injection of desired serialization schema without changing the rest of the framework.

On the other hand, this might be to complicated for AHK as needs of AHK users are not similar to those of mainstream languages users despite recent popularization of AHK as general prog language. Perhaps sticking to JSON or YAML might have its merits in achieving simplicity.

Quote:
One advantage of including important functionality like this as a script library is that anyone can learn from, adapt or improve it.

This is certainly true. Aside from that it would provide good standards for saving the state of the program for debugging for users that are not interested in serialization. Debuging is important for everybody.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2010, 11:17 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
majkinetor wrote:
What prevents one to threat base as any other object in this manner ?
("Threat" should be "Treat".) I guess it would work, though perhaps not well. When multiple objects of the same "type" (objects with a common base object) are serialized, it would be a waste of time and space to serialize the base object each time. If the de-serializer doesn't know how to get a reference to the base object, it would need to create a copy for each object. Additionally, the base object may contain implementation details which are not really relevant and are more likely to change between versions than the fields used in the object.
Quote:
The good mechanism would involve default and user provided handlers. Then library of specialized handlers could me made for specific cases.
That's more or less what I was thinking.
Quote:
DI can be used to keep all other mechanisms in place while allowing injection of desired serialization schema without changing the rest of the framework.
I'm not familiar with the acronym "DI", but I can guess what you're talking about. The serializer can handle enumerating the object's contents, recursively handling object references (and eliminating cycling references), while allowing the object (or its base) to have the final say in what actually gets serialized. It can do this by passing itself to a method in the target object, providing format-agnostic methods to write out data (like 'write field "x" with value "y" of type "z"' not 'write "field: value"').

Another grey area: object and int keys. Often (but not always) int keys are used to form a list/array, and the most intuitive way to serialize it would be as a list rather than a hash. As for object keys, I'm not sure.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2010, 11:04 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
The problem with base over-serialization can be solved by introducing guid for recognized bases.

Quote:
Often (but not always) int keys are used to form a list/array, and the most intuitive way to serialize it would be as a list rather than a hash.

This is one form of already mentioned thing:
Lex wrote:
and some types of objects might need specialized de-serialization behaviour.

Once a set of serialization procedures is created and you have a mean to associate particular procedure with particular key or object, this becomes just a special case.
As for object keys, perhaps guids can be used again. IF key is an object, u serialize it as a guid, then make reference to actual object serialized elsewhere. So you could for instance have key serialization and value serialization parts of whole process that are joined at the end.

Quote:
I'm not familiar with the acronym "DI"

Dependency Injection.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2010, 3:11 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
I must refrain from further discussion on this topic as I'm sure it could go on forever. I'm sure you'd all like to see the next revision out sooner...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1036 posts ]  Go to page Previous  1 ... 43, 44, 45, 46, 47, 48, 49 ... 70  Next

All times are UTC [ DST ]


Who is online

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