What is the opposite of string interpolation? - terminology

Suppose you have a string:
$MY_PATH/test.txt
And suppose MY_PATH is defined as /foo/bar. After interpolation, the string now looks like this:
/foo/bar/test.txt
What do you call the opposite function? That is, what do you call the act of going from /foo/bar/test.txt to $MY_PATH/test.txt? Extrapolation?

Related

How do I pass objects to functions in ooRexx?

I'm a long-time mainframe Rexx programmer who is trying out objects in ooRexx. The results are surprising. For example, here is a program:
#!/usr/bin/rexx
a = .number~new(3.14)
say "a =" a
say "a~val =" a~val
call say_number a
exit 0
say_number:
procedure
parse arg num
say "In say_number"
say "num =" num
say "num~val =" num~val
return
::class number public
::attribute val get public
::method init ; expose val ; use arg val
::method new ; expose val ; use arg val
::method string ; return "'"self~val"'"
The result is:
> number
a = '3.14'
a~val = 3.14
In say_number
num = '3.14'
18 *-* say "num~val =" num~val
8 *-* call say_number a
REX0097E: Error 97 running /home/tony/bin/.scripts/number line 18: Object method not found
REX0476E: Error 97.1: Object "'3.14'" does not understand message "VAL"
It appears that the object is being resolved to its string value before it's passed to the say_number function. Weird! Am I missing something obvious?
Well, that didn't take long. I changed parse to use in the function, and everything worked as expected. Per the Reference manual:
USE ARG retrieves the argument objects provided in a program, routine,
function, or method and assigns them to variables or message term
assignments.
PARSE assigns data from various sources to one or more variables
according to the rules of parsing. ... If you specify UPPER, the
strings to be parsed are translated to uppercase before parsing. If
you specify LOWER, the strings are translated to lowercase. Otherwise
no translation takes place.
Presumably PARSE converts the arguments to a string so that it can change case as requested (or defaulted).

How to convert jsonAST.Jint to int

I am attempting to learn Scala, and I'm trying to parse a JSON file. I have two lines of code:
var jVal:JValue = parse(json);
val totalCount:Int = (jVal \\ "totalCount").asInstanceOf[Int];
However, (jVal \\ "totalCount") returns a JInt instead of an int. If I print it as a string, it looks like "JInt(38)".
How on earth do I convert this to a regular int? My current code throws an exception saying that
net.liftweb.json.JsonAST$JInt cannot be cast to java.lang.Integer
I've scoured the internet, but I can't find any answers. I would really prefer not to manually parse and remove the "JInt()" part of the string just to get it as an integer.
Surely I am missing a simple way to do this?
Since JInt is a case class, a convenient way to extract the value is using an extractor expression, either in a match:
myJValue match {
case JInt(x) => /* do something with x */
case JString(s) => /* do something with s */
/* etc. */
}
or just an assignment statement, when you know what type to expect:
val JInt(totalCount) = (jVal \\ "totalCount")
This will define totalCount to be the value of "totalCount" in your JSON. Note that it will be of type BigInt. If you want to, you can convert your BigInt to an Int with the toInt method. But if your number is too big for an Int, this method will give you a different number instead of an error. So if huge numbers are at all a possibility, you'll want to check first with isValidInt.
You can also get the value using the num field or values method, but in your code that's harder to work with. To use num, you'd have to do a cast of your JValue to JInt. And if you don't cast to JInt, you won't know the type of the result of values.

How can I loop over a map of String List (with an iterator) and load another String List with the values of InputArray?

How can I iterate over a InputArray and load another input array with the same values except in lower case (I know that there is a string to lower function)?
Question: How to iterate over a String List with a LOOP structure?
InputArray: A, B, C
OutputArray should be: a, b, c
In case, you want to retain the inputArray as such and save the lowercase values in an outputArray, then follow steps in below image which is self explanatory:
In the loop Step, Input Array should be /inputArray and Output Array should be /outputArray.
Your InputArray field looks like a string field. It's not a string list.
You need to use pub.string:tokenize from the WmPublic package to split your strings into a string list and then loop through the string list.
A string field looks like this in the pipeline:
A string list looks like this in the pipeline:
See the subtle difference in the little icon at the left ?
I can see two cases out here.
If your input is a string
Convert the string to stringlist by pub.string:tokenize service.
Loop over the string list by providing the name of string list in input array property of loop.
within loop use pub.string:toLower service as transformer and map the output to an output string.
put the output string name in the output array property of Loop.
once you come out of the loop you will see two string lists, one with upper case and one with lower case.
If your input is a string list.
In this case follow steps 2 to 5 as mentioned above.

Ti-basic passing function as an argument to another function

In Matlab you can declare an anonymous function and pass it to another function.
[y] = someFunction(#(x) x.^2 , [a bunch of numbers]);
I'd like to do something similar on my TI-89 calculator. I have a function that takes a "math-function" as one of its arguments and I'm trying to do it like this:
myfunction(3/x,1,2)
and my function looks something like this:
myfunction(f,xl,xu)
Func
local a,b
f(xl)→a
f(xu)→b
Return [a,b]
EndFunc
I know I can input my functions in the "y=" editor and then access them inside the function but I would really like to be able to input the math-function directly as an argument. How can I do this?
The builtin expr function in TI-BASIC can be used to turn a string into an expression. Here's how to implement your function this way:
myfunction(f,xl,xu)
Func
Local a,b,x
xl→x
expr(f)→a
xu→x
expr(f)→b
Return [a,b]
EndFunc
The call to your function will be myfunction("3/x",1,2). Be sure to enclose the definition of f in double quotes so it is treated as a string.
"TI-89 BASIC does not have first-class functions; while function definitions as stored in variables are fully dynamic, it is not possible to extract a function value from a variable rather than calling it. In this case, we use the indirection operator #, which takes a string and returns the value of the named variable, to use the name of the function as something to be passed."
http://rosettacode.org/wiki/Higher-order_functions#TI-89_BASIC

How to split the string in vba

I have a string like
string1= "sample thing(model)"
I need to get the string inside the parantheses i.e model. And i'm using the below code but not working. which method do i need to use.
vString1 = Split(string1, "(",2)
If you know it's always gonna be the parens, I would use the Instr() method. Combined with the Mid() function, it would look like this:
'Find the location of the open parens
X = Instr (string1, "(")
'Find the location of the close parens
Y = Instr (string1, ")")
'Use the Mid function to find the string located inside the parens
MyString = Mid(string1, X, Y)