List Members Can Be Accessed with Partial Name? Is This a Feature

list members can be accessed with partial name? Is this a feature?

It's a feature that is meant to help in interactive mode. You can tighten it locally, see help(options) which has

 ‘warnPartialMatchArgs’: logical.  If true, warns if partial
matching is used in argument matching.

‘warnPartialMatchAttr’: logical. If true, warns if partial
matching is used in extracting attributes via ‘attr’.

‘warnPartialMatchDollar’: logical. If true, warns if partial
matching is used for extraction by ‘$’.

Example:

R> l <- list(key = 1)
R> l$k
[1] 1
R> options("warnPartialMatchDollar"=TRUE)
R> l$k
[1] 1
Warning message:
In l$k : partial match of 'k' to 'key'
R>

and you can further promote warnings to errors if you so choose (and that option is described on the same page).

Accessing members of the other half of a partial class

Unless VB.NET generates different stuff in its LINQ to SQL files from C# the classes of the DB tables aren't within the DataContext class, just beside it.

So you have the class MyNamespace.DataContext.Concession when the other half of the partial class is realy MyNamespace.Concession

Cross referencing 10k+ file names with partial-name list, to isolate matching files

Hope I get your question right. I'll be using fruits as example.

Exact matching

Let's say your folder contains 10 files of fruits, and you wish to extract the file name of orange, dragon fruit and melon.

# this is your 10k files
Allspecieslist <- c("abc_apple.filetype", "abc_orange.filetype",
"abc_grape.filetype", "abc_melon.filetype",
"abc_mango.filetype", "abc_pear.filetype",
"abc_watermelon.filetype", "abc_dragon fruit.filetype",
"abc_kiwi fruit.filetype", "abc_durian.filetype")

# let's pretend these are your target species
Taxonomy <- data.frame(Fruit = c("orange", "dragon fruit", "melon"))

# google regex if you wish to know more about the matching patterns
output_list <- Allspecieslist[str_extract(Allspecieslist, "(?<=_).*(?=\\.)") %in% Taxonomy$Fruit]

[1] "abc_orange.filetype" "abc_melon.filetype"
[3] "abc_dragon fruit.filetype"

Create list artificially

If you are sure that your target species are in your 10k files, you don't actually need to match them, you can just create a list to match the file name style.

prefix = ("abc_")
[1] "abc_"

suffix = (".filetype")
[1] ".filetype"

paste0(prefix, Taxonomy$Fruit, suffix)
[1] "abc_orange.filetype" "abc_dragon fruit.filetype"
[3] "abc_melon.filetype"

Creating object from class with __declspec(dllexport)

Your class MyClass is exported, hence you should write in your main :

Part::MyClass myClass;
myClass.read();

If you want to call your function as you actually do in your main, you should write in your file.h :

namespace Part{

void PartExport read();

}

But in this case you will lose your class encapsulation.


Another thing : to create your dll you have to specify the __declspec(dllexport) to export the function in the library.

But when your are using it, you should not tell your executable that you want to export this function as it was already exported in your library.

I advise you to compile your dll defining this macro in your project : PART_EXPORT_DLL

Then write it like this in your file.h:

//file.h
#ifdef PART_EXPORT_DLL
# define PartExport __declspec(dllexport)
#else
# define PartExport __declspec(dllimport)
#endif
namespace Part{

class PartExport MyClass : public data::anotherClass{
MyClass();
void read();
};
}

And when you want to import it, be sure not to define PART_EXPORT_DLL

Why can't I access C# protected members except like this?

The "protected" keyword means that only a type and types that derive from that type can access the member. D has no relationship to C therefore cannot access the member.

You have a couple of options if you want to be able to access that member

  • Make it public
  • Make it internal. This will allow any types to access the member within the same assembly (or other assemblies should you add friend's)
  • Derive D from C

EDIT

This scenario is called out in section 3.5.3 of the C# spec.

The reason this is not allowed is because it would allow for cross hierarchy calls. Imagine that in addition to D, there was another base class of C called E. If your code could compile it would allow D to access the member E.F. This type of scenario is not allowed in C# (and I believe the CLR but I don't 100% know).

EDIT2 Why this is bad

Caveat, this is my opinion

The reason this is now allowed is it makes it very difficult to reason about the behavior of a class. The goal of access modifiers is to give the developer control over exactly who can access specific methods. Imagine the following class

sealed class MyClass : C {
override F(D d) { ... }
}

Consider what happens if F is a somewhat time critical function. With the current behavior I can reason about the correctness of my class. After all there are only two cases where MyClass.F will be called.

  1. Where it's invoked in C
  2. Where I explicitly invoke it in MyClass

I can examine these calls and come to a reasonable conclusion about how MyClass functions.

Now, if C# does allow cross hierarchy protected access I can make no such guarantee. Anyone in a completely different assembly can come by and derive from C. Then they can call MyClass.F at will. This makes it completely impossible to reason about the correctness of my class.

Partial member function template specialisation and data member access

As commented, you don't need to use partial specialization for this at all, indeed partial specialization is usually pretty easy to avoid, and preferred to avoid.

private:
template <class T>
struct tag{}; // trivial nested struct

template <class I, class T>
void push_impl(I first, I last, tag<T>) { ... } // generic implementation

template <class I, class T>
void push_impl(I first, I last, tag<std::complex<T>>) { ... } // complex implementation

public:
template <class InputIt>
void push(InputIt first, InputIt last)
{
push_impl(first, last,
tag<typename std::iterator_traits<InputIt>::value_type> {});
}

Since push_impl is a (private) member function you don't need to do anything special any more.

Compared to your proposed solutions, this has no extra performance cost. It's the same number of function calls, the only difference is passing a stateless type by value, which is a wholly trivial optimization for the compiler. And there's no sacrifice in encapsulation either. And slightly less boilerplate.

People search in SharePoint using partial names

I found this solution that works well enough for us.

Add a ContentEditor web part to the target page and go to the HTML editor button. Add the following HTML code. It creates two input fields (firstname/lastname) and then creates a query with the search terms included as property searches which will invoke the full-text search.

Note: you need to replace the search result page with the appropriate location for your configuration.

<script language="javascript">
//function to handle enter on keyboard
function txtWildPeopleFinder_KeyDown(e)
{
if (e.keyCode == 13 || e.keyCode==10)
{
e.returnValue=false;
DoWildPeopleSearch();
return false;
}
else
return true;
}
//escape apostrophes in search strings
function escapestr(str)
{
return str.replace("'","%22");
}

//search function
function DoWildPeopleSearch()
{
var firstname = escapestr(document.all["firstname"].value);
var lastname = escapestr(document.all["lastname"].value);
var url;

//search on last name
if(firstname == "")
{
url = "/searchcenter/Pages/peopleresults.aspx?k=LastName%3A" + lastname;
window.location=url;
return;
}

//search on first name
if(lastname == "")
{
url = "/searchcenter/Pages/peopleresults.aspx?k=FirstName%3A" + firstname;
window.location=url;
return;
}

//first and last
url = "/searchcenter/Pages/peopleresults.aspx?k=lastname%3A" + lastname + "%20FirstName%3A" + firstname;
window.location=url;
return;
}
</script>

<table cellpadding="2" cellspacing="0" border="0" width="100%" ID="Table3">
<tr>
<td width="80" nowrap>
First Name:
</td>
<td width="100%">
<input size="20" maxlength="100" id="firstname" name="firstname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
</tr>
<tr>
<td width="80" nowrap>
Last Name:
</td>
<td>
<input size="20" maxlength="100" id="lastname" name="lastname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
</tr>
<tr>
<td>   </td>
<td>
<input type="button" onclick="DoWildPeopleSearch()" value="Search">
</td>
</tr>

</table>

Disable partial name idenfication of function arguments

From the language definition:

If the formal arguments contain ‘...’ then partial matching is only
applied to arguments that precede it.

fun <- function(..., sheeta = 1, sheetb = 2, sheepc = 3)
{<your function body>}

fun(sheep = rep(1,3))
# standard sheep
#1 3 1
#2 3 1
#3 3 1

Of course, your function should have assertion checks for the non-... parameters (see help("stopifnot")). You could also consider adding a . or _ to their tags to make name collisions less likely.

Edit:

"would it be possible to achieve the same effect without having the ... at the beginning ?"

Yes, here is a quick example with one parameter:

fun <- function(sheepc = 3, ...)
{
stopifnot("partial matching detected" = identical(sys.call(), match.call()))
list(...)
}

fun(sheep = rep(1,3))
# Error in fun(sheep = rep(1, 3)) : partial matching detected

fun(ball = rep(1,3))
#$ball
#[1] 1 1 1


Related Topics



Leave a reply



Submit