I wish to type in a multi-line array as follows:
ast ← ('∘'
('a' ('p'))
('b'
('q' ('v'))
('r'))
('c'
('s' ('w' 'x'))
('t' ('y' 'z'))))
This is correctly paranthesized, but I am unable to copy-paste it into the Dyalog APL RIDE interface. I searched around, and found two answers both of which do not help me:
A github issue: Unable to paste any DFN from dfns website asks about pasting DFNS, which explains that one can use ∇. When I type the ∇, the UI of the text-box changes and becomes dark gray, which is encouraging, but on typing ast ← { <ENTER> or ast ← ( <ENTER> it errors out.
This SO question on multi-line text values in APL asks how to input text. I tried to use the { } method, but when I type ast ← { <ENTER> it already errors out.
So, how does one type multiline data in APL?
The session doesn't currently support multi line arrays.
For now, you still have to create multi dimensional arrays programmatically for the most part (although you can, for example, create an editable text matrix, fill it with "numbers" and then use ⍎¨)
cmat←⍪''
)ed cmat
paste this
0123
2314
1244
then fix it (press Esc) and use
⍎¨cmat
For me, I find Shift-Enter and Ctrl-Enter are my best friends most of the time
It looks like you're trying to represent a tree as a nested array (look at dfns tview and tnest and other tree stuff for more on that). As such, it doesn't look like you really need multiline (all arrays in APL are hyperrectangular)?
ast←('∘'('a' ('p'))('b'('q'('v'))('r'))('c'('s' ('w' 'x'))('t' ('y' 'z'))))
Traditional functions (tradfns) can be copy and pasted readily, if they use the session input format:
∇ r ← larg Fun rarg
r ← larg, rarg
∇
Multi-line dfns can be pasted. First use the ]dinput user command.
]dinput
then paste
dfn ← {
⍺, ⍵
}
(btw, regarding ∇ from the previous comment, you can paste the multiline dfn and prepend with ∇, but you have to put ∇ on the last line [n] and press enter for it to fix the function. The ]dinput user command is a bit simpler)
In addition to Richard Park's excellent answer, it should be noted that Dyalog is working on multi-line arrays on two fronts:
Designing a new multi-line array notation
The newest edition was presented in 2018
⎕SE.Link.Serialise can create multi-line notation from most any array
⎕SE.Link.Deserialise will return the array specified by its argument notation array
Multi-line session input
Version 18.0 (due summer 2020) includes experimental multi-line session support. It has to be enabled with a configuration parameter.
It will detect unfinished dfns (e.g. MyFn←{ and 4{) and control structures (e.g. :If myVar>5 and :Class MyCl) but not array notation.
18.0 will also contain a tool, ⎕SE.Link.Array which allows wrapping multi-line array notation in a dfn:
{
[1 2 3
4 5 6]
}⎕SE.Link.Array⍬
Related
I am unable to submit multiple lines of Hy to Python without indentation:
import hy
expr=hy.read_str("(+ 1 1)(+ 2 2)")
hy.eval(expr)
=> 2
The second '(+ 2 2)' statement has apparently been ignored.
Obviously Python's raison d'etre is indentation, and of course the 'Hy Style Guide" shows everything constantly indented, and has this to say as well:
"New lines must ALWAYS be indented past their parent opening bracket."
So is there no way to avoid indentation in Hy and to submit a single, non-indented string via hy.eval(expr)?
Hy is a free-form language, like most programming languages and unlike Python. The style guide is only a style guide.
What you're seeing with read-str is issue #1591. Use do to combine multiple expressions into one.
No, indentation is not required in Hy, and (as Kodiologist notes) the Hy Style Guide's endless prattling on about indentation is, as it should be, nothing more than a suggestion.
However Hy does not have any sort of 'compound expression'-type of form, and the submission of a sequence of multiple statements to Hy does require additional tricks.
The obvious solution, to make submit multiple statements (aka 'forms') as a sequence does NOT work:
hy.eval(hy.read_str( "((+ 1 1) (+ 2 2))" ))
-> TypeError: 'int' object is not callable
Which occurs of course because Hy is trying to 'call' the number 2 as a function on the number 4.
One can collect sequences of forms in a list. However this captures all of their outputs:
hy.eval(hy.read_str( "[(+ 1 1) (+ 2 2)]" ))
-> [ 2 4 ]
Naturally for a very large computation with many steps it is possible to end up with a list of junk that one does not need, wasting memory. (However most Hy forms resolve to 'None' which is pretty small). So one can just wrap everything with a 'last' statement:
hy.eval(hy.read_str( "(last [(+ 1 1) (+ 2 2) (+ 3 3)] )" ))
-> 6
Probably the best solution is to use do as Kodiologist notes:
hy.eval(hy.read_str( "(do (+ 1 1) (+ 2 2) (+ 3 3) )" ))
-> 6
I'm refactorying a very big C project and I need to find out some part of code written by specific programmer.
Fortunately every guy involved in this project mark his own code using his email address in standard C style comments.
Ok, someone could say that this could be achieved easily with a grep from command line, but this is not my goal: I may need to remove this comments or substitute them with other text so regex is the only solution.
Ex.
/*********************************************
*
* ... some text ....
*
* author: user#domain.com
*
*********************************************/
From this post I found the right expression to search for C style comments which is:
\/\*(\*(?!\/)|[^*])*\*\/
But that is not enough! I only need the comments which contains a specific email address. Fortunately the domain of email address I'm looking for seems to be unique in the whole project so this could make it simpler.
I think I must use some positive lookahead assertion, I've tried this one:
(\/\*)(\*(?!\/)|[^*](?=.*domain.com))*(\*\/)
but it doesn't run!
Any advice?
You can use
\/\*[^*]*(?:\*(?!\/)[^*]*)*#domain\.com[^*]*(?:\*(?!\/)[^*]*)*\*\/
See the regex demo
Pattern details:
/\* - comment start
[^*]*(?:\*(?!\/)[^*]*)* - everything but */
#domain\.com - literal domain.com
[^*]*(?:\*(?!\/)[^*]*)* - everything but */
\*\/ - comment end
A faster alternative (as the first part will be looking for everything but the comment end and the word #domain):
\/\*[^*#]*(?:\*(?!\/)[^*#]*|#(?!domain\.com)[^*#]*)*#domain\.com[^*]*(?:\*(?!\/)[^*]*)*\*\/
See another demo
In these patterns, I used an unrolled construct for (\*(?!\/)|[^*])*: [^*]*(?:\*(?!\/)[^*]*)*. Unrolling helps construct more efficient patterns.
I have some verse references in articles that I want to link to the adjacent verses file.
Example:
some text (Gen 2:15, 16), other text (Ex 4:12, 13) more.. etc.
I could replace the first one with the following regex:
\(Gen \1: \2, \3\)
Here I fixed the "1" (book=) and the "Gen"
But I couldn't figure out how to use if|then so that I could give it all arrays of (Gen|Ex|Lev.. etc.), so that it replaces Gen with book number "1", Ex "2".. etc.
You need to somewhere define what all the book orders are. And you'll need to use some sort of scripting language, not just a plain old regex. For example, you could do something along the lines of:
books = ["Gen", "Ex", ..., "Rev"]
...and then replace book_name with books.index(book_name)+1
The exact code/syntax obviously depends on which language you choose to use.
With notepad++ you won't be able to get the order numbers.
But everything else is possible. You need to put each book on a new line:
find \), and replace by \n
Then use this pattern:
[a-z\s]+\(([a-z]+)\s+([0-9:]+)\,\s+([0-9]+)\)
and replace by:
\1: \2, \3
you'll get the list of urls. Which then you can merge back to one line if needed.
The only problem is the book number.
Demo is here: https://regex101.com/r/qN8mO7/2
I have this code in C but I only know how to extract string with regular expression that not inside comment code:
1. /* * "path_build()" function in "home.c" for more information.
2. * this is an example basic"
3. */
4.
5. /*** Free ***/
6. VALOR = string_make(format("%sxtra", libpath));
7. event_signal_string(EVENT_INITSTATUS, "Inicializando...");
should only return:
"%sxtra"
"Inicializando..."
I try:
".*"
but its don't work, it show me all text inside "", including the strings that inside /*...*/
I use EditPag Pro, RegExp panel.
It's a game translation project, I take the string of every C file and I translate to Spanish. I can't remove the comments of the original file.
The only thing I have clear is that this is the regex to find comments in C, maybe that will help the solution:
(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)
Any help?
Edit: I put number of lines.
Hernaldo, this is an interesting question.
Here are two versions because I am not sure if you want to capture the "inside of the string" or "the whole string"
The regexps below capture the strings to capture Group 1. You completely ignore the overall match (Group 0) and just focus on Group 1. To retrieve the strings, just iterate over Group 1 matches in your language (discarding empty strings if any).
Version 1: "The inside of the string"
(?s)/\*.*?\*/|"([^"]+)"
This will capture %sxtra and Inicializando... to Group 1.
Version 2: "The whole string"
(?s)/\*.*?\*/|("[^"]+")
This will capture "%sxtra" and "Inicializando..." to Group 1.
Please let me know if you have any questions!
Note: I did not handle /* nested /* comments */ */ as that was not specified in the question. That would require a bit of tweaking and probably a regex engine supporting recursion.
The final solution for EditPad 6/7 is:
(?<!^[ \t]*/?[*#][^"\n]*")(?<=^[^"\n]*")[^"]+
Link:
Regular expression for a string that does not start with a /*
I'm brand new to VXML (and coding in general) and apparently what I'm trying to do is... not normal, but hopefully it can be done.
I understand the principle concept of DTMF input with VXML where I use:
<grammar mode="dtmf"><![CDATA[ (*|0|1|2|3|4|5|6|7|8|9)<2-31> ]]></grammar>
<prompt>something here</prompt>
<noinput-nomatch-filled>conditions</noinput-nomatch-filled>
What I'm trying to do is take multiple actions to allow DTMF entry of letters based on their placement on the dialpad. You'd achieve this by first dialing the number that the letter is on (2-9), and the placement of that letter (1-4).
For example: "E" would be 3 and 2 on the dialpad.
I'm at a complete loss as to how this would work in VXML. What I'd like to do is this:
1) PROMPT: Please input your THREE letter code. Please enter your first letter.
2) Expect two DTMF inputs the first number between 2 and 9, the second number between 1 and 4. Based on this logic (33 = F, 94 = Z) the letter is set.
3) PROMPT: The letter you have entered is (INPUT). Is this correct? Press 1 for yes, 2 to retry.
4) Retry or go onto the next letter. So on and so forth.
If anyone has resources so I can stumble upon the answer to this myself, that'd be great! If anyone would like a bounty... that's an option, too! Thank you for reading!
The typical approach to this problem is just accept twice the number of tones as you expect or use a pound terminated input. Then use ECMAscript or server side code to translate the tone strings into the desired letters.
There are a couple of a ways to approach this problem:
1) You could just accept all 2 digit numbers in the grammar and do all validation/calculation on the server side.
and/or
2) Do some validation in the <filled> section and letter-decoding-from-number on the server-side (and then come back with the result and check with the user if that was the intended letter).
For the two-digit grammar, you could parameterize the built-in digits grammar as follows (please note that the URI scheme is platform-specific, so you may need to refer to the user manual of your voice browser to be sure of the exact scheme to be used)
<field type="digits?length=2">
<prompt>Please enter the code of the first letter</prompt>
</field>
There are other ways as well, like you could also do letter-decoding on the client-side using a script on the same page, but hopefully the above gives some ideas on what to choose based on your requirement.
(Actually, the OP would probably not be looking for an answer to this question after so long but hopefully it helps others who landed on this page searching for a solution to a similar question)
The best way could be to define a grammar that link each value to the result letter :
<grammar mode="dtmf" root="letter">
<rule id="letter">
<one-of>
<item>32<tag>E</tag></item>
...
</one-of>
</rule>
</grammar>
Another way is to let the user enter the 2 letters and process it with a EcmaScript function, or use the tag .
I am going to plan to add such feature in the Voximal the VoiceXML interpreter for Asterisk.
But are you sure that the users can be able to understand and use this method to enter letters ?