The docs say that fmt
Returns a string where each element in the list has been formatted according to $format [the first argument] and where each element is separated by $separator [the second argument].
Based on that description, I expected to be able to call .fmt on a List of Lists, and then pass a printf-style format string containing a % directive for each element in the inner list. But that doesn't work.
If you'd told me that I was wrong about ^^^^, I'd have expected that .fmt was auto-flattening its arguments and thus that each argument would be formatted and separated by the $separator. But that's also not what happens.
Instead, running this code
say (<a b c>, <1 2 3>, <X Y Z>).fmt('→%03s|', "\n=================\n");
produces this output:
→00a| →00b| →00c|
=================
→001| →002| →003|
=================
→00X| →00Y| →00Z|
That is, the format string is applied to each element in the inner lists, those lists are then stringified (without using the format string; note the between each | and → character), and then the separator is inserted between each outer list.
That leaves me with three questions:
Have I correctly described/understood the current behavior? [edit: nope. See below]
Is this behavior intentional or an odd bug? (I checked Roast, but didn't see anything either way)
Assuming this is intentional, why? Is there some way that this is consistent with Raku's general approach to handling lists that I'm missing? Or some other reason for this (imo) surprising behavior?
Edit:
After further investigation, I've realized that the behavior I observed above only occurs if the format string contains a width directive. Changing the →%03s| format string from above to →%s| produces the following output:
→a b c|
=================
→1 2 3|
=================
→X Y Z|
That is, without a width, the format string is applied after the list is stringified rather than before.
So I'm back to being confused/thinking at least some of this behavior must be buggy.
Ok, it looks like there were at least two bugs here. This should be fixed with https://github.com/rakudo/rakudo/commit/a86ec91e36 . Writing spectests for these situations, would be appreciated :-)
Related
I am new to using R and actually to most programming language, so I am a bit lost here. Hope you can help. I am using RCMap for whcih I have 4csv documents, I get the following error code:
Error in dimnames(x) <- dn :
length of 'dimnames' [1] not equal to array extent
I am sure it has something to do with my own data, because I get normal output if I use other people´s data. However, I don´t know where the problem is (not even in which of the four documents). I do have a lot of missing data, however changing the missing data to either blank spaces or NA, does not change the error code.
The documents of other people that I am able to run also contain missing data, although to a lesser extend.
Hope you can help,
best wishes, Doriene
I had a similar problem and it helped when i put a space in front of c__bacilli.
Ex: test <- subset_taxa(phylo, Class==" c__Bacilli")
How do you put multiple lines of statements inside an Elm main module
Example,
module Main exposing (main)
import Html exposing (text)
main =
text "1"
text "2"
The above does not work and gives this error
Detected errors in 1 module.
-- TOO MANY ARGS -------------------------------------------------- src/Main.elm
The `text` function expects 1 argument, but it got 3 instead.
5|> text "1"
6| text "2"
Are there any missing commas? Or missing parentheses?
Putting parenthesis and commas does not help.
Elm is an expression-based language. It doesn't have statements because it doesn't have side-effects. Instead it consists of expressions which return values associated with types that are verified at compile-time.
Your code is a valid expression syntactically, so I'm not sure how you got that specific error. I can't reproduce it either directly at top level, where expressions don't belong, or in a function where expressions do belong, but there I get a type error instead of a syntax error. You're leaving out some essential part of your code.
In any case, even if you put it correctly into a function this won't do what you want. There are multiple problems even then:
Your code will be interpreted as three arguments applied to the function text, '1', text, and '2', because the line-break is not significant.
'1' is a character literal, not a string literal. "1" is a string literal.
Whatever you're going to use this with, it most likely expects a single element, not a list of elements.
The correct way to return two elements as one is to wrap the two elements in a parent element, like 'span' for example:
module Main exposing (main)
import Html exposing (text, span)
main =
span []
[ text "1"
, text "2"
]
Lastly, I recommend that you begin learning by following the official Elm guide. Elm is different enough that a trial-and-error approach based on what tends to work in JavaScript is likely to just lead to frustration.
I have got a term from which I want to get set of variables name.
Eg. input: my_m(aa,b,B,C,max(D,C),D)
output: [B,C,D] (no need to be ordered as order of appearance in input)
(That would call like set_variable_name(Input,Output).)
I can simply get [B,C,D,C,D] from the input, but don't know how to implement set (only one appearance in output). I've tried something like storing in rbtrees but that failed, because of
only_one([],T,T) :- !.
only_one([X|XS],B,C) :- rb_in(X,X,B), !, only_one(XS,B,C).
only_one([X|XS],B,C) :- rb_insert(B,X,X,U), only_one(XS,U,C).
it returns tree with only one node and unification like B=C, C=D.... I think I get it why - because of unification of X while questioning rb_in(..).
So, how to store only once that name of variable? Or is that fundamentally wrong idea because we are using logic programming? If you want to know why I need this, it's because we are asked to implement A* algorithm in Prolog and this is one part of making search space.
You can use sort/2, which also removes duplicates.
I have a simple grammar that works for the most part, but at one place it reports error and I think it shouldn't, because it can be resolved using backtracking.
Here is the portion that is problematic.
command: object message_chain;
object: ID;
message_chain: unary_message_chain keyword_message?
| binary_message_chain keyword_message?
| keyword_message;
unary_message_chain: unary_message+;
binary_message_chain: binary_message+;
unary_message: ID;
binary_message: BINARY_OPERATOR object;
keyword_message: (ID ':' object)+;
This is simplified version, object is more complex (it can be result of other command, raw value and so on, but that part works fine). Problem is in message_chain, in first alternative. For input like obj unary1 unary2 it works fine, but for intput like obj unary1 unary2 keyword1:obj2 is trys to match keyword1 as unary message and fails when it reaches :. I would think that it this situation parser would backtrack and figure that there is : and recognize that that is keyword message.
If I make keyword message non-optional it works fine, but I need keyword message to be optional.
Parser finds keyword message if it is in second alternative (binary_message) and third alternative (just keyword_message). So something like this gives good results: 1 + 2 + 3 Keyword1:Value
What am I missing? Backtracking is set to true in options and it works fine in other cases in the same grammar.
Thanks.
This is not really a case for PEG-style backtracking, because upon failure that returns to decision points in uncompleted derivations only. For input obj unary1 unary2 keyword1:obj2, with a single token lookahead, keyword1 could be consumed by unary_message_chain. The failure may not occur before keyword_message, and next to be tried would be the second alternative of message_chain, i.e. binary_message_chain, thus missing the correct parse.
However as this grammar is LL(2), it should be possible to extend lookahead to avoid consuming keyword1 from within unary_message_chain. Have you tried explicitly setting k=2, without backtracking?
I'm extracting terms from the query calling ExtractTerms() on the Query object that I get as the result of QueryParser.Parse(). I get a HashTable, but each item present as:
Key - term:term
Value - term:term
Why are the key and the value the same? And more why is term value duplicated and separated by colon?
Do highlighters only insert tags or to do anything else? I want not only to get text fragments but to highlight the source text (it's big enough). I try to get terms and by offsets to insert tags by hand. But I worry if this is the right solution.
I think the answer to this question may help.
It is because .Net 2.0 doesnt have an equivalent to java's HashSet. The conversion to .Net uses Hashtables with the same value in key/value. The colon you see is just the result of Term.ToString(), a Term is a fieldname + the term text, your field name is probably "term".
To highlight an entire document using the Highlighter contrib, use the NullFragmenter