dhh1128 / intent

the intent formal language
https://intentlang.org
2 stars 1 forks source link

support functionality like *nix rename utility to map strings to code tokens #96

Open dhh1128 opened 9 years ago

dhh1128 commented 9 years ago

Consider the following block of code:

pSettings->bIgnoreDirectoryForLinks = OmnivoreGetBooleanProperty("IGNORE_DIRECTORY_FOR_LINKS");
        pSettings->bIncludeSelectionLists = OmnivoreGetBooleanProperty("INCLUDE_SELECTION_LISTS");
        pSettings->iMinCJKnGramLength = OmnivoreGetIntProperty("MIN_CJK_NGRAM_LENGTH");
        pSettings->iMaxCJKnGramLength = OmnivoreGetIntProperty("MAX_CJK_NGRAM_LENGTH");
        pSettings->bUsePrefixForMeta = OmnivoreGetBooleanProperty("USE_PREFIX_FOR_META");
        pSettings->bUsePrefixForTitle = OmnivoreGetBooleanProperty("USE_PREFIX_FOR_TITLE");
        pSettings->bUsePrefixForLinks = OmnivoreGetBooleanProperty("USE_PREFIX_FOR_LINKS");
        pSettings->bUsePrefixForForm = OmnivoreGetBooleanProperty("USE_PREFIX_FOR_FORM");
        pSettings->bUsePrefixForAlt = OmnivoreGetBooleanProperty("USE_PREFIX_FOR_ALT");
        pSettings->bUsePrefixForLinkText = OmnivoreGetBooleanProperty("USE_PREFIX_FOR_LINK_TEXT");

Notice that the member that we're setting on the left side of each assignment has an orderly correspondence to the string literal on the right side. What we want, to make code much simpler, is something like this:

MapToMember(pSettings, <member match expr>, OmnivoreGetBooleanProperty, <renamed or transformed match expr>)

Perhaps a better name for this function would be "Dispatch". There are so many examples of dispatching (mapping from constants, user input, enums, etc) to a function call. Doing this more cleanly and with less repetition would be a big win.