Flex set-difference - flex-lexer

I would like to know how do I define a set difference (A/B) in flex , thank you

If you mean the difference of two character classes, flex provides
the {-} operator.
This operator's explanation will be found in the Flex manual chapter on Patterns.
Hope this helps

You can do this type of thing quite easily with ActionLinq (ActionLinq.org)
var A:IEnumerable = Enumerable.from([1,2,3,4]);
var B:IEnumerable = Enumerable.from([2,3,4,5]);
var diff:Array = A.except(B).toArray();

Related

How to use FParsec to parse identifiers with different start and end characters

I'm having difficulty working out the best way to parse identifiers that have different characters at the start and end. For example, let's say that the start characters of our identifiers may be upper and lowercase only, while the middle of an identifier may also include digits and colons. The end of an identifier may not be a colon, but may be an apostrophe.
So the following are all legal identifiers:
f, f0, f:', f000:sdfsd:asdf
But the following are not:
0, hello:, he'llo
I can't see how best to handle the backtracking: a colon is fine in the middle, but we need some lookahead to determine whether we are at the end of the identifier.
EDIT:
Thanks for the suggestions. Using a regex is a pragmatic approach, but I find it slightly disappointing that there doesn't seem to be clean/obvious way of doing this otherwise.
I also think you should use regex, however I came up with a different pattern:
let pattern = regex #"^([a-zA-Z]+[a-zA-Z0-9:]*[a-zA-Z']?)$"
which will hold all of your wanted Matches in the first group. You can use an online RegExp tool to validate your matches/grouping.
You can handle this with a regex parser
let ident = regex #"[A-Za-z][A-Za-z0-9\:]*[A-Za-z0-9\']"
http://www.quanttec.com/fparsec/reference/charparsers.html

What does an exclamation mark in Lua do?

Question is in the title, really. I saw someone use this earlier and I didn't know what the ! was used for.
local lowestIndex = 0;
local lowestValue = false;
for k, v in ipairs(playerElement) do
if !lowestValue or v.value < lowestValue then
lowestIndex = k;
lowestValue = v;
end
end
As others have said, ! normally has no function in Lua, and the code you posted would not normally be valid. However, it's quite trivial to extend Lua's parser to allow for custom syntax, and it's not unheard of for projects which embed Lua to add "more familiar" C-style syntax such as !var and != in addition to not var and ~=. One notable project which does this is Garry's Mod, and I'm sure there are others.
Of course, using custom syntax when the normal syntax is available (or customising it in the first place) is best avoided, if possible, to avoid exactly this sort of confusion.
It's a syntax error.
Some languages, mostly C and its relatives, use ! as a logical "not" operator, but Lua uses the not keyword instead, and does not use ! for anything as far as I know (not even as part of the inequality operator; it uses ~= where C uses !=).
You appear to have gotten hold of some Lua code written by someone who doesn't know that.

Bug in my regular expression

I'm trying to look at a string and reject anything that has seq= or app= in the string. Where it gets tricky is I need elements with q=something or p=something.
The seq= part of the string is always preceded an & and app= is always preceded by a ?
I have absolutely no idea where to start. I've been using http://www.rubular.com/ to try and figure it out but to no avail.
Any help would be hugely appreciated.
Based on your question, I believe you could just reject any strings that match the following expression:
[\?&](?:seq|app)=
This will match any string that contains a ? or & followed by either app= or seq=. The ?: inside the parentheses just tells the regular expression not to bother to capture matching groups as sub-matches. They're not really necessary, but what the heck.
Here's a Rubular link with some samples.

syntax of binary:split with multiple patterns

What is the correct syntax when we use multiple patterns ?
test3()->
test4(<<"1234567890">>).
test4(A)->
X = binary:split(A,[<<"3">>,<<"8">>]),
X.
[<<"12">>,<<"4567890">>]
I was expected 3 elements!
In order to get 3 elements, you should use the split/3 function and to specify the global option ("Repeats the split until the Subject is exhausted"):
binary:split(<<"1234567890">>,[<<"3">>,<<"8">>],[global]).
and you'll get:
[<<"12">>,<<"4567">>,<<"90">>]
More on this, in the official doc: http://www.erlang.org/doc/man/binary.html#split-3
Hope it helps.

Point-free style with objects/records in F#

I'm getting stymied by the way "dot notation" works with objects and records when trying to program in a point-free functional style (which I think is a great, concise way to use a functional language that curries by default).
Is there an operator or function I'm missing that lets me do something like:
(.) object method instead of object.method?
(From what I was reading about the new ? operator, I think it works like this. Except it requires definition and gets into the whole dynamic binding thing, which I don't think I need.)
In other words, can I apply a method to its object as an argument like I would apply a normal function to its argument?
Short answer: no.
Longer answer: you can of course create let-bound functions in a module that call a method on a given type... For example in the code
let l = [1;2;3]
let h1 = l.Head
let h2 = List.hd l
there is a sense in which "List.hd" is the version of what you want for ".Head on a list". Or locally, you can always do e.g.
let AnotherWay = (fun (l:list<_>) -> l.Head)
let h3 = AnotherWay l
But there is nothing general, since there is no good way to 'name' an arbitrary instance method on a given type; 'AnotherWay' shows a way to "make a function out of the 'Head' property on a 'list<_>' object", but you need such boilerplate for every instance method you want to treat as a first-class function value.
I have suggested creating a language construct to generalize this:
With regards to language design
suggestions, what if
SomeType..Foo optArgs // note *two* dots
meant
fun (x : SomeType) -> x.Foo optArgs
?
In which case you could write
list<_>..Head
as a way to 'functionize' this instance property, but if we ever do anything in that arena in F#, it would be post-VS2010.
If I understand your question correctly, the answer is: no you can't. Dot (.) is not an operator in F#, it is built into the language, so can't be used as function.

Resources