The inserted conditional code regex for Raku - raku

How to do the inserted conditional code regex in Raku regex
As analogue to its Perl regex
my $F = 1;
'foobarbar' =~ / (?(?{ $F }) foo | bar ) bar /x ;
Please help out after tried so hard a day to no avail, thanks.

Quick answer
my $F = 1;
'foobarbar' ~~ / (<?{ $F }> foo | bar ) bar / ;
say $/; # use `say` to get a "human friendly" `gist` of a value
displays:
「foobar」
0 => 「foo」
whereas:
my $F = 0;
'foobarbar' ~~ / (<?{ $F }> foo | bar ) bar / ;
put $/; # use `put` to get a simple computer stringification of a value
displays:
barbar
Quicker answers
Please help out after tried so hard a day to no avail, thanks.
You are more than welcome to keep asking questions here on SO. We will do our best to answer the same day you ask, and the Qs you ask and answers we provide will help everyone. So, thanks for asking, and keep them coming. That said, there are much quicker ways to get answers, and they're typically better answers than we can provide here:
"Chat" (Even if you don't like participating in real-time discussions, still read Chat logs below.)
If you like real-time discussion, there are IRC, Discord etc channels.
You can ask or answer questions, or more generally enjoy yourself, in real-time, right now, by clicking web page that will take you to the #raku-beginners IRC channel to visit a Raku noob "chat" channel. If any Rakoons are around (we're currently mostly English speaking folk living in Europe or the US, though that'll hopefully expand in coming years), you'll typically get friendly engagement in a few minutes.
There are several other channels. Click the logs link below to see a list.
Chat logs
Chat channels are (normally) publicly logged and searchable. More than a dozen mines containing something like a million diamonds in the rough -- comments made by Rakoons and visitors in real time continuously since 2005.
For many purposes, searching these logs is vastly richer pickings than googling (which is frequently useless). For example, googling the doc site for matches of \Q (a Perl escape that has a Raku equivalent) lists 50 false positives with just one true positive, whereas a search for \Q in the old Raku channel displays a long list of matches, and my brief review of them suggests many of them are useful.
Search features include filtering by nick. For example, a search for comments by TimToady (Larry Wall) containing the word macro.
You can even use Raku regexes! (If you do, please be thoughtful. For example, to avoid timeouts you may need to break a search into several submissions, each spanning less than 15 years.)
In summary, you can not only search nearly two decades worth of Rakoons and non Rakoon visitors making unimaginably terrible jokes while productively discussing every bit of code (in Raku or any other PL) and every Raku topic that anyone has cared to discuss, but also search with precision to keep the signal to noise ratio high.
Doc If you want to search and read documentation, follow my guide below to quickly get answers to many questions from doc.raku.org, the main doc website:
Search The doc site's search box (top right of the website) is more useful than it might seem. You may not know what to type in. Even if you know what to type in, it may not be in the doc. Even if it is in the doc, it might not be included in the drop-down list of matches. But you should still try because there's an often overlooked "search the entire site" option listed at the very bottom of the drop-down (after all the listed matches).
For example, if you type condition into the search box, and select the "Search the entire site for condition" entry, you'll see the matches on the doc site as seen by google. If you then browse through them you'll see the <?{condition}> yes-pattern | no-pattern example. You could have found the answer to your Q in about two minutes flat by just popping condition in the search box!
BTW, if searching does not work for you, please feel free to provide feedback about what you tried and failed to find. (And thanks if you do.)
Read Sometimes search won't get you the answer but it's still worth reading doc because you just aren't using the right words in the search box. For quick access to the most important parts of the doc website relevant to questions like yours -- especially how to transfer knowledge of another PL to Raku -- click on the word Language in the green area at the top of the doc site. This will take you to the Raku Language tab, which includes great info as follows:
There are "Language X to Raku" Migration guides that show how to do things in Raku that are equivalent to doing them in some other PL. You should definitely take advantage of The Perl to Raku guide. (We'd appreciate feedback about it too.) It's broken into six parts so far; you should start with the Perl to Raku guide - in a nutshell. In it you'll see a Special matchers generally fall under the <> syntax section; it provides this example (slightly modified):
(?{condition)) yes-pattern | no-pattern # Perl
becomes
<?{condition}> yes-pattern | no-pattern # Raku
There's also detailed language reference info. The Language tab's Fundamental topics section includes a Regexes page; in it you'll find a Regex Boolean condition check section that contains a whole section entirely dedicated to what you've asked about.
There are of course many more resources (especially the old design speculation docs), but hopefully the above will help you find answers to many questions more quickly. Good luck!

This will work:
my $F=1
'foobar' ~~ / ^^ "{ $F ?? "foo" !! "bar" }" bar /; # 「foobar」
$F=0
'foobar' ~~ / ^^ "{ $F ?? "foo" !! "bar" }" bar /; # Nil
Code blocks in regexes will be run, but unless you convert them explicitly to strings (via quotes) they will be discarded.

Related

CHM/HHP: maximum length of variable names in [ALIAS] section

What is the maximum length of variable names in the [ALIAS] section of HHP files?
I_AM_WONDERING_ABOUT_THE_MAXIMUM_LENGTH_OF_THIS_STRING_RIGHT_HERE=this-is-some-really-helpful-html-file.html
I have found a CHM/HHP specification right here:
https://www-user.tu-chemnitz.de/~heha/viewchm.php/hs/chmspec.chm/hhp.html
That page only talks about the length of the overall line, though (and not about the length of the variable name). Very specific question, I know. Still, someone may be able to point me somewhere.
As far as I know never asked before and I never heard about limitations. But I think this is because nobody used long variable names in this place so far.
The purpose of the two files e.g. alias.h and map.h is to ease the coordination between developer and help author. The mapping file links an ID to the map number - typically this can be easily created by the developer and passed to the help author. Then the help author creates an alias file linking the IDs to the topic names. That was the idea behind years (decades) ago by Ralph Walden (ex Microsoft).
Please note HTMLHelp is about 20 years old and these context ID strings inside a alias.h file were derived from WinHelp as a predecessor of HTMLHelp.
You'll find some further Information at Creating Context-Sensitive Help for Applications.
In general I'd recommend to use ID's with a fixed format because of the better legibility like shown below:
;-------------------------------------------------------------
; alias.h file example for HTMLHelp (CHM)
; www.help-info.de
;
; All IDH's > 10000 for better format
; last edited: 2006-07-09
;---------------------------------------------------
IDH_90001=index.htm
IDH_10000=Context-sensitive_example\contextID-10000.htm
IDH_10010=Context-sensitive_example\contextID-10010.htm
IDH_20000=Context-sensitive_example\contextID-20000.htm
IDH_20010=Context-sensitive_example\contextID-20010.htm
I'd recommend to use less than 1024 bytes per line.

wit.ai 'Only if..' not working

I am new in wit.ai. I'm confused with it. I have few questions:
how works Actions: 'Only if..' and 'Always if...'
simply I have 2 entities: 'Hi' and 'Botname',I have 2 stories: when say 'Hi' wit answers 'answer1', when say 'Botname', wit answers 'answer2'. It's Ok, but when combined 'Hi Botname', I want wit to answer 'answer1', but I can't echieveit without adding story. I try to add in Actions ->'Answer2'-'Only if..' 'doesn't have' ->'Hi', but still it answers 'Answer2' and I don't understend why :)
second question I sometimes don't get adequate answer from wit and I don't know how to avoid such cases. For example: entity 'constitution' and in 'understending' when writing 'station' wit gets 'constitution', this two words are different. and what to do? please, help with it.
To the first question, I'd suggest that rather than trying to use the keyword and free-text format of entities, you define and assign a trait entity which will not necessarily try to match the exact word, but the feeling of the sentence.
For example
Given the situation above, if you were to train an intent
called "greeting" to recognize all sentences with "Hi" in it as
greetings, then the result of "Hi Botname" will continue to be the
result of Hi. Also, if you're going to be using branching, enitites
will have to be defined as trait entities in either case.
To the second (And this will help with the first), you just have to spend some time training the bot to understand. You can't rush the brush. You'll have to feed it some examples before it can understand the difference in the words, and start to pick those differences up in future words.
The Wit Bot engine was released only a little while ago, so we're all learning it now, but I hope I could help you with the little knowledge I've gained.

Article buddy text encryption or something else?

I tried out "article buddy" (http://article-buddy.com/sales-page/)
They claim to change any content into original content for the search engines.
Everytime I tested the output of the tool it passed copyscrape and such.
After a while I tried finding out how the tool was fooling the tests because the text did not seem to change in any way. After I pasted the so called original content into "textpad" (text editor). I saw a lot of weird characters especially the question mark that replaced certain characters in the text.
Example (original text):
WestBow Press titles are regularly reviewed by Thomas Nelson & Zondervan for new, talented authors. While there is no guarantee of the number of titles to be signed each year, this is an opportunity to get your foot in the door. - See more at:
Example (output text of article buddy):
W??tB?w Pr??? t?tl?? are regularly r?v??w?d b? Th?m?? N?l??n & Z?nd?rv?n for n?w, t?l?nt?d authors. Wh?l? th?r? ?? n? gu?r?nt?? ?f th? numb?r ?f t?tl?? t? b? ??gn?d each ???r, th?? ?? an opportunity t? g?t ??ur f??t ?n th? door. - S?? m?r? ?t:
Does anyone know what is going on here?
I have seen multiple tools like this one in the past. Typically, the way it works is that it spins the content and replace words or whole sentences.
This used to work back in the days. My suggestion is to not waist your time and money on those. The only acceptable thing these days is original content.

Why does this search for [help/dont-ask] return irrelevant results in DSE?

Why does this ridiculously simple query on data.stackexchange.com return results that don't have [help/dont-ask] in the comment text? I feel like I'm missing something mind-numbingly obvious here.
select top 10 Id, PostId, Text
from comments
where text like '%[help/dont-ask]%'
Results I currently get:
Id PostId Text
-- ------- -----------------------------------
1 35314 not sure why this is getting downvoted -- it is correct! Double check it in your compiler if you don't believe him!
2 35314 Yeah, I didn't believe it until I created a console app - but good lord! Why would they give you the rope to hang yourself! I hated that about VB.NET - the OrElse and AndAlso keywords!
4 35195 I don't see an accepted answer now, I wonder how that got unaccepted. Incidentally, I would have marked an accepted answer based on the answers available at the time. Also, accepted doesn't mean Best :)
9 47239 Jonathan: Wow! Thank you for all of that, you did an amazing amount of work!
10 45651 It will help if you give some details of which database you are using as techniques vary.
12 47428 One of the things that make a url user-friendly is 'discover-ability', meaning you can take a guess at url's simply from the address bar. http://i.love.pets.com/search/cats+dogs could easily lead to http://i.love.pets.com/search/pug+puppies etc
14 47481 I agree, both CodeRush and RefactorPro are visually impressive (most of which can be turned off BTW), but for navigating and refactoring Resharper is much better in my opinion of using both products.
15 47373 Just wanted to mention that this is an excellent solution if you consider the problem to be linear (i.e. treating `A1B2` as a single number). I still think the problem is multi-dimensional, but I guess we'll just have to wait for the author to clarify :)
16 47497 Indeed, the only way to do this is get the server to generate your CSS file which can be done in many ways depending on which language you are using. HttpHandlers are common in C#. You could use jQuery or the likes to add styling to every element with the class 'ourColur' and parametrise your JS
18 47513 This advice goes against the spirit of CSS, which is separation of content and presentation. You way requires changing HTML for presentation sake, and stating in content which elements have same color.
...none of which contains the magic link (or even the text dont-ask).
Because [] delimits a set of characters to find.
You need to escape them.
Or just use CHARINDEX as the search is unsargable anyway.
WHERE CHARINDEX('[help/dont-ask]', text) > 0

How exact phrase search is performed by a Search Engine?

I am using Lucene to search in a Data-set, I need to now how "" search (I mean exact phrase search) mechanism has been implemented?
I want to make it able to result all "little cat" hits when the user enters "littlecat". I now that I should manipulate the indexing code, but at least I should now how the "" search works.
I want to make it able to result all "little cat" hits when the user enters "littlecat"
This might sound easy but it is very tough to implement. For a human being little and cat are two different words but for a computer it does not know little and cat seperately from littlecat, unless you have a dictionary and your code check those two words in dictionary. On the other hand searching for "little cat" can easily search for "littlecat" aswell. And i believe that this goes beyong the concept of an exact phrase search. Exact phrase search will only return littlecat if you search for "littlecat" and vice versa. Even google seemingly (expectedly too), doesnt return "little cat" on littlecat search
A way to implement this is Dynamic programming - using a dictionary/corpus to compare your individual words against(and also the left over words after you have parsed the text into strings).
Think of it like you were writing a custom spell-checker or likewise. In this, there's also a scenario when more than one combination of words may be left over eg -"walkingmydoginrain" - here you could break the 1st word as "walk", or as "walking" , and this is the beauty of DP - since you know (from your corpus) that you can't form legitimate words from "ingmydoginrain" (ie rest of the string - you have just discovered that in this context - you should pick the segmented word as "Walking" and NOT walk.
Also think of it like not being able to find a match is adding to a COST function that you define, so you should get optimal results - meaning you can be sure that your text(un-separated with white spaces) will for sure be broken into legitimate words- though there may be MORE than one possible word sequences in that line(and hence, possibly also intent of the person seeking this)
You should be able to find pretty good base implementations over the web for your use case (read also : How does Google implement - "Did you mean" )
For now, see also -
How to split text without spaces into list of words?