I can't seem to find the option for ordering a reference item based on appearance of the key values in cite. I have the following in my .bib file:
#misc{test,
author = "Test",
title = "Title",
note = "6 October 2016",
howpublished = "\url{https://www.google.nl}"
}
which gives the following:
However I would like to have the reference item in the order: [Author, Title, Note, Howpublished] just as I have described in the #misc. Is this possible?
Related
I want to transform the strategy code number in my Strategy Code column (Data table) into strategy name based on the dim_strategy table. My Challenge is there can be more than 1 strategy code appear in each row and hence I want to use + as the delimiter to combine different strategy name in Data table.
This is the desired output in Data table:
This query will achieve that for you. You will need to change the source for whatever your table source is but the rest of the steps should be exactly the same.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"No.", Int64.Type}, {"Strategy Code", type text}}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Strategy Code", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Strategy Code"),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Strategy Code", Int64.Type}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type1", {"Strategy Code"}, dim_strategy, {"Strategy Code"}, "dim_strategy", JoinKind.LeftOuter),
#"Expanded dim_strategy" = Table.ExpandTableColumn(#"Merged Queries", "dim_strategy", {"Strategy"}, {"Strategy"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded dim_strategy",{"Strategy Code"}),
#"Grouped Rows" = Table.Group(#"Removed Columns", {"No."}, {{"Stretagy Name", each Text.Combine([Strategy], " + "), type nullable text}})
in
#"Grouped Rows"
Or you could add a column
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Strategy Name", each Text.Combine(
List.Transform(Text.Split([Strategy Code],","), each
dim_strategy[Strategy]{List.PositionOf(dim_strategy[Strategy Code],Number.From(_))}
),", "))
in #"Added Custom"
It converts the Strategy Code to a list, then to numerical list, finds the position of that in the dim_strategy Strategy Code column, then pulls the corresponding Strategy column and recombines the list into text
List.Buffer dim_strategy2[Strategy Code] as an earlier step if dataset is large
I have a method where i iterate through list of objects. For each object i want to print the value of 'block_data' based on "block_type" in the order of above to below. Notice that sometimes the block_type title is above text and sometimes its below text in the list of objects.
Sometimes i have other block_types like graph-pie-chart and i have block_labels for the chart and the block_data for the chart is also in a list based on block_labels. And all the block_type in the List coul be something else and another order. But i still want it in the order of the List of objects i get like the example below. I wonder how i can achieve this with dart?
class Book {
getBookInfo() {
final List listOfItems = [
{"block_type": "title", "block_data": "Books"},
{"block_type": "text", "block_data": "This is the textblock of books"},
{"block_type": "text", "block_data": "This is the textblock of publishers"},
{"block_type": "title", "block_data": "Publishers"},
{"block_type": "graph-pie-chart", "block_labels": ["Total sold","Sold copies","Reviews"], "block_data": ["3000", "100", "10"]},
{"block_type": "button", "link": "<link to a bookshop>"},
];
List selectedItem = listOfItems;
selectedItem.forEach((index) {
}
;
});
}
}
While strictly speaking, you are not incorrect to call each element of the list an object, they are more precisely of type Map<String,String>
You can use .where() to filter out maps that do not have a key of block_type and value of the block type that you need, then do your .forEach() to print the value you want.
You also might consider defining a class type to use instead of a Map in your listOfItems
I'm following the F# book Get Programming with F# and got to the part about shadowing. The simplest example they provide doesn't seem to be possible, so I'm wondering if either this syntax was removed or changed for F# 6 shadowing? I haven't been able to find anything stating that or how to do what the book offers as shadowing a record.
type Address =
{ Street: string
Town: string
City: string }
let home = { Street = "123 Main Street"; Town = "The Town"; City = "The City" }
let home = { home with City = "Second City" }
let home = { home with City = "Third City" }
When trying to build get an error stating: Duplicate definition of value 'home'
Edit
So after searching for answers without success as to why this doesn't work I tried putting the above into a function like so:
let testFunction =
let home = { Street = "123 Main Street"; Town = "The Town"; City = "The City" }
let home = { home with City = "Second City" }
let home = { home with City = "Third City" }
0
and it worked just fine. So my question now is why does shadowing work within a function but not outside? Is there a conflict with scoping on a module level that doesn't happen within a function's scope?
To add some more detail to the existing answers, there are four different cases.
Local definitions. If you are inside a function body, you can use shadowing and this is quite useful when doing a computation in multiple steps:
let adjust index =
let index = max 0 index
let index = min 100 index
index
Local definitions inside class. You are similarly allowed to shadow local definitions inside a class:
type A() =
let foo = 1
let foo = 2
member x.Foo = foo
Top-level in a script file. If you are at the top level in a script file (something.fsx) then you are allowed shadowing. The idea with script files is that they would be run manually, so it is useful to have multiple different versions - you just run the one you want by hand:
let test = calculation1 ()
let test = caluclation2 ()
Top-level in a module (source file). The only case where shadowing does not work is when you are in a module (or .fs file which becomes a module implicitly). In a module, definitions are public and they are compiled as static members of a class, so there is also a technical limitation (you cannot have multiple class members of the same name).
module Constants =
let answer = 1
let answer = 42 // error FS0037: Duplicate definition of value
Why shadowing is limited to function body?
There are probably some technical reasons. But the core reasons are IMO:
Naming is hard. Shadowing eases the pain but it can be confusing.
Also F# supports "tick naming" (home') to have a similar but different name. It's a kind of safer shadowing.
Just picking upon Lua and trying to figure out how to construct tables.
I have done a search and found information on table.insert but all the examples I have found seem to assume I only want numeric indices while what I want to do is add key pairs.
So, I wonder if this is valid?
my_table = {}
my_table.insert(key = "Table Key", val = "Table Value")
This would be done in a loop and I need to be able to access the contents later in:
for k, v in pairs(my_table) do
...
end
Thanks
There are essentially two ways to create tables and fill them with data.
First is to create and fill the table at once using a table constructor. This is done like follows:
tab = {
keyone = "first value", -- this will be available as tab.keyone or tab["keyone"]
["keytwo"] = "second value", -- this uses the full syntax
}
When you do not know what values you want there beforehand, you can first create the table using {} and then fill it using the [] operator:
tab = {}
tab["somekey"] = "some value" -- these two lines ...
tab.somekey = "some value" -- ... are equivalent
Note that you can use the second (dot) syntax sugar only if the key is a string respecting the "identifier" rules - i.e. starts with a letter or underscore and contains only letters, numbers and underscore.
P.S.: Of course you can combine the two ways: create a table with the table constructor and then fill the rest using the [] operator:
tab = { type = 'list' }
tab.key1 = 'value one'
tab['key2'] = 'value two'
Appears this should be the answer:
my_table = {}
Key = "Table Key"
-- my_table.Key = "Table Value"
my_table[Key] = "Table Value"
Did the job for me.
I'm not sure if this is possible due to the numerical indices, but hopefully someone can point me in the right direction.
Given the table of:
t = { 13, 200, 12, 15, 23 }
how can I nest a table using the numbers?
t["200"] = {"stuff", "more stuff", "even more stuff"}
doesn't seem to work, as it'll create a position 200 and fill in the empty cells with null. I'd add a letter as a suffix/prefix, but the problem comes trying to sort the table numerically. Is this even possible, or am I stuck with a different method? Thanks!
Slight edit due to a realisation:
t["200"] = {"stuff", "more stuff", "even more stuff"}
actually creates a key of "200", whereas:
t[200] = {"stuff", "more stuff", "even more stuff"}
creates the index 200 with everything else null.
First, DeadMG is correct; you used a string rather than a numerical index. However, even if you did use a number index, it wouldn't help.
If you do this:
someTable = {"value1", "value2", {"value3a", "value3b"}};
someTable[50] = {"value50a", "value50b"};
The length of the table, #someTable, will still be 3. Why? Because Lua defines arrays in a table based on contiguous elements. Remember: you can access any element of any table; they are all conceptually filled with nil until you give them an actual value.
Lua defines length for a table as the number of values in a table if you start counting from numerical index 1 until you reach the first nil value. Since someTable[4] is nil, the length is 3.
If you want to insert a new element at the end of an array table, then you can do this:
someTable[#someTable + 1] = "newValue";
The value can itself be a table:
someTable[#someTable + 1] = {"newValuea", "newValueb"};
If you're just asking how to access a nested table, that's simple, and it has nothing to do with the keys you use.
There is nothing special about nested tables. Tables are values, and table entries can be any value, including other tables.
If you have a table, and want to walk the array entries in it, you use this:
local aTable = {"first", "second", "third", ...}
for i, value in ipairs(aTable) do
--`value` contains the entries in the table.
end
A nested table is no different; it is simply a matter of getting the table.
local nestedTable = { "first", "second", "third", ...}
nestedTable[#nestedTable + 1] = {"newFirst", "newSecond", ...}
local aTable = nestedTable[#nestedTable];
for i, value in ipairs(aTable) do
--`value` contains the entries in the table.
end
Or you could just do ipairs(nestedTable[#nestedTable]). Note that the particular key used here (an integer value) is entirely unimportant. That key could have been a string, a floating-point number, another table, some user-data, etc. It doesn't matter.
Note also that we use ipairs because we only want to iterate over the array members of the table. The length of the array is defined above. If we wanted to loop over every member of the table, we would use pairs instead of ipairs. Of course, pairs does an unordered search, so it is not guaranteed to be in array order.
If you want to recursively find every element in a nested table, you can do this:
local function RecursiveSearch(aTable)
for key, value in pairs(aTable) do --unordered search
if(type(value) == "table") then
RecursiveSearch(value)
else
--Do something with this.
end
end
end
Note that the above can do an infinite loop, since it is possible for a table to have circular references:
local tableA = {}
local tableB = {tableA}
local tableA[1] = tableB
RecursiveSearch(tableA) --Infinite loop.
Perhaps it helps to view your assignment like this:
t = { [1] = 13, [2] = 200, [3] = 12, [4] = 15, [5] = 23 }
To change what is currently 200 (namely t[2]), you do:
t[2] = {"stuff", "more stuff", "even more stuff"}
Edit: that results in your table looking like this:
t = { [1] = 13, [2] = {"stuff", "more stuff", "even more stuff"}, [3] = 12, [4] = 15, [5] = 23 }
-- or, equivalent::
t = { 13, {"stuff", "more stuff", "even more stuff"}, 12, 15, 23 }
The trouble is your use of "". Your table t contains a bunch of numbers, and you're entering a string as the key. You want to iterate over the table and do... something that you didn't particularly well define. However, you can't add to a table whilst iterating over it, so you might have to do some funny stuff.
t = { 13, 200, 12, 15, 23 }
newt = {};
for key, value in pairs(t) {
newt[value] = { };
}
This will create a table entry in newt, where the key is a value in the table t, for all values in t.