DDMathParser - Using a string as an argument in a custom function - objective-c

I would like to make a function which would allow me to pass a string in the argument - what's the best way to do this?
eg..
Moles("Ca(OH)2")
Any help would be extremely gratefully received.

I ended up putting this in by parsing strings as variables. So for DDMathParser:
someFunction("Hello")
... is equivalent to:
someFunction($Hello)
However, this means you can have variables now with more complex stuff:
someFunction("Hello world")
Moles("Ca(OH)2")
... etc

Related

Python: run a class method that takes an argument in a new thread

I am trying to do the same thing as in this question: Run Class methods in threads (python), but the class method I want to invoke in a separate thread takes an extra argument, apart from self. A.Rodas's solution does not work: if I try Thread(target=self.class_method, args=(self, arg2)).start(), it says I have 3 arguments instead of 2, while if try args=(arg2), it is breaking my arg2 string into constituent elements and saying 334234 arguments! Any ideas? Thanks
You should do it like this:
threading.Thread(target=self.class_method, args=(arg2,)).start()
It is hard to tell from the format of your question, but I think the issue is that you shouldn't be including self in the args tuple.
i.e.
threading.Thread(target=self.class_method, args=(arg2)).start()

Velocity template function from string literal

Is it possible to call a function that was created from string literal? For example
${object}.staticPartOfFunctionName${dynamicPartOfFunctionName}()
doesn't return correct value, but instead just prints the object and the function name.
$object.staticFunctionName()
prints correctly, and
$object.staticPartOfFunctionName${dynamicPartOfFunctionName}()
gives warning "Encountered ")"
You don't have to use introspection:
#evaluate("\$object.staticPartOfFunctionName${dynamicPartOfFunctionName}()")
Well, I found one solution myself from Java side:
$object.getClass().getMethod("staticPartOfFunctionName$dynamicPartOfFunctionName").invoke($object))
I don't know if it's any good, so if someone knows how to do it velocity way, lemme know.

String template to set the default value of PARAMETER

Is it possible, in ABAP, to evaluate string templates dynamically?
Normally, you will have some string template in code that will be checked by the compiler. (The variables in the curly brackets are checked by the compiler at compile time).
However, is it possible to have a string evaluated at runtime?
So, instead of:
data(val) = |System ID: { sy-sysid }|.
I would like the string to be interpolated to come from elsewhere, for example:
parameter: p_file type string lower case default '/mnt/{ sy-sysid }/file.txt'.
In this case, I would like to have the value of p_file to be evaluated at runtime to substitute the variable (sy-sysid) with the runtime value.
You could, of course, program your own substitution by finding all occurrences of variables with curly brackets with a regex expression, then evaluate the variable values with ASSIGN and substitute them back into the string, but I am looking for a built-in way to do this.
Sorry, this is maybe a stupid example, but hopefully you understand what I mean. (If not, please let me know in the comments and I will try and clarify).
The problem in your snippet is not with string template but with PARAMETER behavior. It does not allow dynamics in DEFAULT clause.
To achieve what you want you should use INITIALIZATION and set path value in runtime:
parameter: p_file type string lower case.
INITIALIZATION.
p_file = | /mnt/{ sy-sysid }/file.txt |.
Unfortunately, the example you gave, does not make any sense to me. ABAP String templates are evaluated at run-time and type-checked at compile-time.
In your example, it is always the run-time value of SY-SYSID that will be written to the variable.
I guess what you want to do is circumvent compile-time checks for expressions inside a string template.
Please try to give us your actual use case, so maybe we find an even better solution to your problem.
However, here is what I think could help you:
Personally, I do not recommend to write code like the one below, because it is extremely error-prone likely to mislead other programmers and because there is very likely a better solution.
Given that you know the name of a variable at run-time, try this:
".. say LV_VARNAME is a charlike variable that contains a
" variable name at runtime.
"NOTE that the variable LV_VARNAME must be visible in the scope of the
"following code.
FIELD-SYMBOLS: <my_var> TYPE any.
ASSIGN (lv_varname) TO <my_var>.
DATA(lv_str) = |The value is { <my_var> }|.

How to name a function that creates fixpoint results on its input?

I have a function that decorates a string. If the decorated string is again fed to the function, it is guaranteed not to change. How is the standard naming convention for such a function? I'll probably create a namespace because I need to have a few of those functions.
I've come up with:
repetition_safe.decorate(me);
fixpoint_gen.decorate(me);
one_time_effect.decorate(me);
but I don't really like any of these.
How would you name the namespace or function?
How about:
StringDecorator.MakeImmutable(input);
I think "MakeImmutable" is better than "Decorate" as the later is ambiguous i.e. a user reading the code won't know what "decorate" does, whereas "makeImmutable" will inform the user that this function will make the input string immutable/non-changable.

Defining protocols without parameters

I am trying to define a protocol method without adding parameters but couldn't find the correct syntax.
Here is the definition (it has a syntax error)
- (void)cameraOverlayView:(CameraOverlayView *)cameraOverlay didTakePhoto;
I don't want to pass any values with the second parameter. My aim is only to signal that something happened to the delegate instance.
How should I write the definition?
Your the second part of the method is not formatted correctly:
- (void)cameraOverlayView:(CameraOverlayView *)cameraOverlay didTakePhoto;
Because of the space, it's expecting a parameter. Instead, work the didTakePhoto part into the method name, like:
- (void)cameraOverlayViewDidTakePhoto:(CameraOverlayView *)cameraOverlay;
- (void)cameraOverlayViewDidTakePhoto:(CameraOverlayView *)cameraOverlay;
basically in objective c you can't have method name parts dangling after parameters...
so:
illegal:
-(void)methodWith:(int)theInt forMyMom;
normal:
-(void)methodForMyMomWithInt:(int)theInt;
legal but strange
-(void)method:(int)theInt :(int)theOtherInt;
with the selector: #selector(method::)
This is an issue of Objective-C convention. You could rewrite it as:
- (void)cameraOverlayView:(CameraOverlayView *)cameraOverlayViewDidTakePhoto;