Skip to content

Using indirection in Simpol

Forums Forums SIMPOL Programming Using indirection in Simpol

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #297
    Jim Locker
    Member

    Take a string of the format variable;value In SBL, I can separate this string, thus extracting both the variable name and the associated desired value, and I can then use indirection like this to assign the value to my actual variable in the program. kw$ = MID$ (a$,1,div%% – 1) kwval$ = MID$ (a$,div%% + 1,slen%% – div%%) kw$ = kw$ + “$” kw$$ = kwval$ Now of course I can separate a string in simpol, but can I assign a value like this? How, syntactically, would I use indirection to achieve this result?

    #1808
    Jim Locker
    Member

    Well, I did wind up implementing it as a hashed array. That works fine
    but isn't what I originally intended.

    The SBL code I provided essentially did the SBL analog of the C pointer
    organization:

    int foo
    int *bar

    bar = foo
    *foo = 3

    printf("%dn",foo)

    except, of course, that SBL would take the variable reference by name,
    rather than by an address pointer.

    Since simpol takes function references by name at runtime it seems to me
    that it could also easily take variable references by name at runtime.
    You have a symbol table someplace internally; you have to. The
    indirection by name just involves walking that symbol table to find the
    variable name, just as you walk a function symbol table to find a
    function.

    In my specific case, I have a config file (actually several config files)
    that are organized as keyword;value pairs. I have global variables that
    match the keywords, and assign the values to those variables which then
    are used effectively as constants throughout the program run.

    The path of least resistance turned out to be to define an array then load
    the array as array[keyword] = value.

    This worked fine, but there are cases where pointers are very nice.

    #1694
    Michael
    Keymaster

    Jim wrote:
    > Take a string of the format variable;value
    >
    > In SBL, I can separate this string, thus extracting both the variable
    > name and the associated desired value, and I can then use indirection
    > like this to assign the value to my actual variable in the program.
    >
    > kw$ = MID$ (a$,1,div%% – 1) kwval$ = MID$ (a$,div%% + 1,slen%% –
    > div%%)
    >
    > kw$ = kw$ + "$" kw$$ = kwval$
    >
    > Now of course I can separate a string in simpol, but can I assign a
    > value like this? How, syntactically, would I use indirection to
    > achieve this result?
    >

    I don't think it is possible to define a new variable at runtime. This
    gets dealt with at compile time. Having said that, I have just about
    never found a need for this approach in the past in my SIMPOL
    programming. Take a step back and describe what this is trying to
    accomplish. You may find that an array can do things for you that you
    otherwise couldn't have done, for example.

    Ciao, Neil

    #1671
    Michael
    Keymaster

    Jim wrote:
    > Well, I did wind up implementing it as a hashed array. That works
    > fine but isn't what I originally intended.
    >
    > The SBL code I provided essentially did the SBL analog of the C
    > pointer organization:
    >
    > int foo int *bar
    >
    > bar = foo *foo = 3
    >
    > printf("%dn",foo)
    >
    > except, of course, that SBL would take the variable reference by
    > name, rather than by an address pointer.
    >
    > Since simpol takes function references by name at runtime it seems to
    > me that it could also easily take variable references by name at
    > runtime. You have a symbol table someplace internally; you have to.
    > The indirection by name just involves walking that symbol table to
    > find the variable name, just as you walk a function symbol table to
    > find a function.
    >
    > In my specific case, I have a config file (actually several config
    > files) that are organized as keyword;value pairs. I have global
    > variables that match the keywords, and assign the values to those
    > variables which then are used effectively as constants throughout the
    > program run.
    >
    > The path of least resistance turned out to be to define an array then
    > load the array as array[keyword] = value.
    >
    > This worked fine, but there are cases where pointers are very nice.

    Actually, it isn't really an issue of pointers, since you basically have
    that in SIMPOL. What you were looking for is a way to take a string
    value and create a variable from it. The thing is, variable names are
    not preserved through compilation. If, on the other hand, you had a huge
    type and wanted to track down a matching property name for a given
    string, that you could do.

    Ciao, Neil

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.