String substitution

This topic is specifically for discussions on the new APL64 Project currently in development. This topic is open for all to browse. However, to post, one must have a registered account on the APLDN forum only available to APL+Win licensee under a current APL+Win Subscription.

Moderators: Tech Support, phpbb_admin

String substitution

Postby Davin Church » September 26th, 2018, 7:53 pm

While I like the idea of being able to plug values directly into a string, I'm not so sure that I like it as a direct part of the language. I guess it's not too bad considering that you process other data constructions within strings (escaped characters, etc.), but it certainly sounds like it belongs to a higher-level functionality - one that you can apply or not apply as desired.
Davin Church
 
Posts: 504
Joined: February 24th, 2007, 1:46 am

Re: String substitution

Postby Davin Church » September 26th, 2018, 8:26 pm

I've been doing this same thing with an APL function since the DOS days ... it even uses the same symbology! I called it ∆fib (for fill-in-the-blank). Let me tell you some of the things I did with it. Perhaps some things might become future ideas for APL64.

  • First of all, if the {value} wasn't defined or any APL error is encountered then no substitution would occur.
  • Functions (result-returning) were permitted as well as variables.
  • Simple constants (limited to things like numbers and quoted strings) were also permitted as values (for use with formatters, below).
  • Formatting was also available in the form {value:formatter}. Formatter is a monadic function that takes value as its argument. For instance, {price:dollarfmt} would take the numeric price and format it for display (with a dollar sign, commas, and two decimals). The same formatter function is thereby generic and could be used in many places with different variables.
  • A formatter function could also be provided with a "right argument" in the syntax string. Since the original value is normally passed as a right argument, when this syntax occurs the given "argument" value is actually passed to the formatter as a left argument so the value can still be passed as a right argument. For example, {price:dollarfmt 0} might do the same job as above but using no decimals at all.
  • More than one formatter function can be used by stringing together additional formatters separated by colons. For example, say you had a variable containing an M or F gender. You could format it with {gender:he_she:mixed_case} to get a "He" or "She" result, nicely formatted for inclusion into a paragraph.
  • And finally, the enclosed value could be any arbitrary APL expression if it is prefixed by the Execute ("⍎") symbol, such as {⍎2×⍳5}.
(My personal routine does a few more things that are specific to my programming environment and are not applicable here.)

So does that give you any ideas about what might be useful?
Davin Church
 
Posts: 504
Joined: February 24th, 2007, 1:46 am

Re: String substitution

Postby Davin Church » September 26th, 2018, 8:30 pm

Question: When is the binding of values done with this substitution? I wouldn't expect it to be at reference time, because then you couldn't make a copy of the original. And I wouldn't expect it to be at the time it is displayed on the session, because it may never be displayed or there may not be a session. So what causes the values to be inserted? And what happens if you need the substitution to happen at some other point in time (because of the availability of values)?
Davin Church
 
Posts: 504
Joined: February 24th, 2007, 1:46 am


Return to APL64 Project

Who is online

Users browsing this forum: No registered users and 1 guest

cron