Results 1 to 2 of 2

Thread: Script syntax enhancement = Array and Dicts/Associative Array Assignment

  1. #1
    Registered User
    Join Date
    Feb 2012
    Frankfurt am Main, Germany

    Script syntax enhancement = Array and Dicts/Associative Array Assignment


    thinking on the things I dislike in vfp compared to other languages I often grumble when I encounter the elegant way
    in Python to create new Lists and Dicts. In Javascript the concept is about identical, with minimal syntax difference.

    Totally leaving vfp compliance behind, but adding a nice twist to shorten code and add portability between supported *Lianja* script languages,
    I would like to be able to code just like Javascript or Python when initializing such structures in vfp syntax, as they can be accessed as objects in either one of both other languages ;-)
    Getting Lianja out of the door also clearly more important unless such functionality is already existing in the parser/compiler only needing exposure ;-)

    Python list / javascript Array code example:
    myArray = ["I", "am", 1, "initialized", "ListorArray"]

    I *do* realize that vfp arrays still start at array element one and am prepared to have my code work with compiler constants in loops if iterating a potentially portable array.

    For hashmaps (as they are not called such in either language...) a new SET could be introduced SET Hashmap = ["Python","Javascript"]
    Set Hashmap to "Python" allows

    myDict = { "who" : "I",
    "verb" : "am",
    "count": 1,
    "adjective" : "Musterstadt",
    "Datatype" : "ListOrArray" }

    resulting in a vfp object based on empty with every dict entry added as Addproperty(myDict, KeyName, KeyValue)
    so that myDict.Who == "I".

    Set Hashmap to "Javascript" allows

    myAssocArray = { who : "I",
    verb : "am",
    count : 1,
    adjective : "Musterstadt",
    Datatype : "ListOrArray" }

    resulting in a vfp object based on empty with every Associative Array entry added as Addproperty(myAssocArray, KeyName, KeyValue)
    so that again myAssocArray.Who == "I".

    Vfp syntax difference being here that capitalization is irrelevant in vfp. Having a pre-defineable template/base class would be the icing of the cake,
    to set developer defined basic and/or hidden properties, starting with "__" or "_" from Python perspective.
    I do realize that a special template decorator function can handle the "icing" part, similar to most JS coding ;-)

    I also do realize that vfp datetime can have a single ":" inside curly braces, but believe it should still be parseable as clearly different.
    Also clear that I could code a custom class doing such init stuff for a handful of basic key value pairs through an .init() creating the empty result class.
    But missing from that would be the option to just cut and paste into the other script language defined in the SET.

    Perhaps Barry can early on offer ballpark estimate on implementation effort ranging from "I think I can reuse..." to "too difficult/fragile/much effort"
    from his knowledge of the vfp-syntax parser/compiler before too many ask for it (if others want it at all).

    I do realize that today the bulk of traditional statically typed languages go for either JSON or XML-variants and scoff at ini files,
    but for me a lot of such things/use cases belong either in a table record or "real" source code. Sometimes old ways are best IMHO ;-)

    comments please

    Last edited by lazyfox; 2013-02-15 at 02:53.

  2. #2
    Lianja Team chris.mavin's Avatar
    Join Date
    Feb 2012
    London UK
    Hi Thomas,

    I think you'll find Lianja has a lot of this functionality already.

    Take a look at JSON_DECODE(), ARRAY() and OBJECT().




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Journey into the Cloud
Join us