1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Indirect function specification

Discussion in 'Suggestions' started by Steve Fabian, Apr 12, 2010.

  1. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    Existing TCC syntax (actually, even 4DOS syntax) allows the user to specify
    the names of environment or internal variables, GOTO and GOSUB labels,
    internal and external commands to be used indirectly by the value of a
    variable, e.g., %[%xyz] or GOTO x_%xyz. Many times it would be useful to
    specify the name of a variable function in an analogous manner (equivalent
    to "function pointer" in the C language):

    for %f in ( CRC32 MD5 ) echo %f=%@%f[s,%xyz]

    If I am mistaken, and such syntax already exists, I'd be very happy to learn
    what it is!
    --
    Steve
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,859
    Likes Received:
    83
    "Many times" may be overstating the case slightly, since this is the first
    request for this in 20 years! (It can in fact be done with existing
    variable expansion, though it's not exactly simple or intuitive.)

    Do you have real examples of why you need this?

    Rex Conn
    JP Software
     
  3. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    | ---Quote---
    || Existing TCC syntax (actually, even 4DOS syntax) allows the user to
    || specify
    || the names of environment or internal variables, GOTO and GOSUB
    || labels, internal and external commands to be used indirectly by the
    || value of a variable, e.g., %[%xyz] or GOTO x_%xyz. Many times it
    || would be useful to specify the name of a variable function in an
    || analogous manner (equivalent to "function pointer" in the C
    || language):
    ||
    || for %f in ( CRC32 MD5 ) echo %f=%@%f[s,%xyz]
    | ---End Quote---
    | "Many times" may be overstating the case slightly, since this is the
    | first request for this in 20 years!

    Having my doctorate in laziness and procastrination, never having requested
    it before just means that I never bothered to put my desires in writing.
    This time I had been in the mood to submit suggestions, and this was just
    one.

    | (It can in fact be done with existing variable expansion, though it's not
    | exactly simple or intuitive.)

    Please provide an example!

    | Do you have real examples of why you need this?

    Yes - see the failing syntax in my OP. In fact the example is exactly what I
    wanted to do: create a command line (or alias or batch file) which reports
    the various hash codes for a string parameter. Why not "unroll the loop"?
    Because in loop form each new function needs to be added to the enumeration
    only once, keeping it simple.
    --
    Steve
     

Share This Page