Is white space relevant when casting from the 'any' type in Apama EPL? - apama

I am on Apama 10.3 (Community Edition):
any emptyString := "";
any emptyDictionary := new dictionary<string,any>;
string myString := <string> emptyString;
dictionary<string,any> := <dictionary<string,any>> emptyDictionary;
The cast in line 3 works, but in line 4 Designer complains about unexpected token: <. Only if I use white spaces does it work:
dictionary<string,any> := <dictionary< string,any> > emptyDictionary;
In the documentation Developing Apama Applications this is not mentioned but on page 296 when casting with optional<>, the correct syntax with the white spaces is used.
Does this work as expected or is it a bug?

The problem here isn't about casting to an any type. This is due to the EPL parser always interpreting expression >> as a right-shift operator. If you need to close two angle brackets, you always need to use a space between them. It’s only the closing brackets that are affected (as you’d never need to write << in EPL).
The form I always use is:
dictionary<string,any> x := <dictionary<string,any> > emptyDictionary;
sequence<sequence<string> > jaggedArray := new sequence<sequence<string> >;

Related

Formatting math expression before parsing using math_expressions package in Flutter

How to properly format a math expression before passing it to the math_expressions package in flutter?
Context
I'm using math_expressions package but there are two cases I found when it throws an error:
A. Missing an asterisk before a parenthesis.
B. Missing parenthesis within the expression.
E.g.
// Throws error
final expression = "8(3+1)"; // A
final expression = "8(3+1"; // B
// Executes correctly
final expression = "8*(3+1)";
final Parser parser = Parser();
Expression exp = parser.parse(expression);
ContextModel cm = ContextModel();
final double result = exp.evaluate(EvaluationType.REAL, cm);
I'm aware of the syntactic requirement of the package so I'd like to properly format the expression before passing it to the parser since I cannot guarantee user input will comply to the requirement mentioned before.
What I've got so far
A. Missing an asterisk before a parenthesis:
I read about the replaceAllMapped method but I don't really know how to start from here in order to add the missing asterisks when needed.
B. Missing parenthesis within the expression. (solved)
Hypothesis
A. Missing an asterisk before a parenthesis:
I think the way is to create an array of digits, search for coincidences of a digit + parenthesis and then replace it with the addition of an asterisk like this: digit + "*" + parenthesis
Any ideas on how to solve this appropriately?

Counting Characters in a String in Swift with Loop

I'm trying to loop through a string and count its characters in Swift. This code successfully outputs the character count, but I receive this warning:
warning: immutable value 'character' was never used; consider
replacing with '_' or removing it for character in quote {
^~~~~~~~~
_
This is my code:
var quote = "hello there"
var count = 0
for character in quote {
count = count + 1
}
print("\(count)")
Does anyone know why I have this warning? Also, is this the best way to approach this task? Thanks.
Please read the error message carefully, it tells you precisely what's wrong and what you can do.
immutable value 'character' was never used
That's indeed true, the variable character is unused. The compiler provides two fixes:
consider replacing with '_' or removing it
The latter is not an option in a loop, so use the first, replace character with an underscore
for _ in quote {

Swift custom operators with Unicode combining characters

TL;DR
Can I coax the compiler to accept a combining character as a postfix operator?
The references at Swift.org and GitHub and this useful gist suggest that combining characters (e.g. U+0300 ff.) may serve as operators in Swift.
With judicious implementation (omitted here) I can say “Fiat Lux” and there is
prefix operator ‖ // Find the norm.
postfix operator ‖ // Does nothing.
func / // Scalar division.
which allows
let vHat = v / ‖v‖ // Readable as math.
or even
let v̂ = v / ‖v‖ // Loving it.
The OCD in me wants now to use the combining circumflex as a (topfix) operator like this:
let normalizedV = v̂ // Combining char is really a postfix.
So I leap in and try to write:
postfix operator ^ // Want this to be *combining* circumflex.
postfix func ^(v: Vector) -> Vector { v / ‖v‖ }
and can do it with plain old U+005E circumflex, but get (various) compiler errors when I try with the combining circumflex U+0302.
An operator name (or any other identifier) cannot start with the U+0302 character. Like all combining marks, it is an allowed “operator-character” but not an allowed “operator-head”. From Lexical Structure > Operators in “The Swift Programming Language”:
GRAMMAR OF OPERATORS
operator → operator-head operator-charactersopt
...
operator-character → U+0300–U+036F

What does the ?= operator do in Swift?

I just came across some code that looks like this:
var msg:String = "";
msg ?= err["ErrorMessage"].text;
The err variable is from SwiftyXMLParser from what I can see in the code. I'm at a loss about the meaning of the ?= (questionmark-equals) operator. I cannot find documentation about it. What is it doing?
This question is a quite interesting topic in Swift language.
In other programming languages, it is closed to operator overloading whereas in Swifty terms, it is called Custom Operators. Swift has his own standard operator, but we can add additional operator too. Swift has 4 types of operators, among them, first 3 are available to use with custom operators:
Infix: Used between two values, like the addition operator (e.g. 1 + 2)
Prefix: Added before a value, like the negative operator (e.g. -3).
Postfix: Added after a value, like the force-unwrap operator (e.g. objectNil!)
Ternary: Two symbols inserted between three values.
Custom operators can begin with one of the ASCII characters /, =, -, +, !, *, %, <, >, &, |, ^, ?, or ~, or one of the Unicode characters.
New operators are declared at a global level using the operator keyword, and are marked with the prefix, infix or postfix modifiers:
Here is a sample example in the playground[Swift 4].
infix operator ?=
func ?= (base: inout String, with: String)
{
base = base + " " + with
}
var str = "Stack"
str ?= "Overflow"
print(str)
Output:
Stack Overflow
Please check the topic name Advanced operator in apple doc.

Strange results when deleting all special characters from a string in Progress / OpenEdge

I have the code snippet below (as suggested in this previous Stack Overflow answer ... Deleting all special characters from a string in progress 4GL) which is attempting to remove all extended characters from a string so that I may transmit it to a customer's system which will not accept any extended characters.
do v-int = 128 to 255:
assign v-string = replace(v-string,chr(v-int),"").
end.
It is working perfectly with one exception (which makes me fear there may be others I have not caught). When it gets to 255, it will replace all 'y's in the string.
If I do the following ...
display chr(255) = chr(121). /* 121 is asc code of y */
I get true as the result.
And therefore, if I do the following ...
display replace("This is really strange",chr(255),"").
I get the following result:
This is reall strange
I have verified that 'y' is the only character affected by running the following:
def var v-string as char init "abcdefghijklmnopqrstuvwxyz".
def var v-int as int.
do v-int = 128 to 255:
assign v-string = replace(v-string,chr(v-int),"").
end.
display v-string.
Which results in the following:
abcdefghijklmnopqrstuvwxz
I know I can fix this by removing 255 from the range but I would like to understand why this is happening.
Is this a character collation set issue or am I missing something simpler?
Thanks for any help!
This is a bug. Here's a Progress Knowledge Base article about it:
http://knowledgebase.progress.com/articles/Article/000046181
The workaround is to specify the codepage in the CHR() statement, like this:
CHR(255, "UTF-8", "1252")
Here it is in your example:
def var v-string as char init "abcdefghijklmnopqrstuvwxyz". def var v-int as int.
do v-int = 128 to 255:
assign v-string = replace(v-string, chr(v-int, "UTF-8", "1252"), "").
end.
display v-string.
You should now see the 'y' in the output.
This seems to be a bug!
The REPLACE() function returns an unexpected result when replacing character CHR(255) (ÿ) in a String.
The REPLACE() function modifies the value of the target character, but additionally it changes any occurrence of characters 'Y' and 'y' present in the String.
This behavior seems to affect only the character ÿ. Other characters are correctly changed by REPLACE().
Using default codepage ISO-8859-1
Link to knowledgebase