It seems pretty common to me to have an argument, in a dynamically typed language that is either an Object or a key to lookup that object. For instance when I'm working with a database I might have a method getMyRelatedStuff(person)
All I really need to lookup the related stuff is the id of the person so my method could look like this i...
This is a module named XYZ.
def func(x)
.....
.....
if __name__=="__main__":
print func(sys.argv[1])
Now I have imported this module in another code and want to use the func. How can i use it?
import XYZ
After this, where to give the argument, and syntax on how to call it, please?
...
null coalescing translates roughly to return x, unless it is null, in which case return y
I often need return null if x is null, otherwise return x.y
I can use return x == null ? null : x.y;
Not bad, but that null in the middle always bothers me -- it seems superfluous. I'd prefer something like return x :: x.y;, where what follows th...
Consider this case:
public class SomeClass {
public void someMethod() {
new SomeInterface() {
public void someOtherMethod() {
new SomeOtherInterface() {
new someThirdMethod() {
//My question is about code located here.
}...
I'm having trouble with templates and dependent types:
namespace Utils
{
void PrintLine(const string& line, int tabLevel = 0);
string getTabs(int tabLevel);
template<class result_t, class Predicate>
set<result_t> findAll_if(typename set<result_t>::iterator begin, set<result_t>::iterator end, Predicate pred) // warning C...
I'm having compiler errors, and I'm not sure why. What am I doing wrong here:
Hangman.cpp:
set<char> Hangman::incorrectGuesses()
{
// Hangman line 103
return Utils::findAll_if<char>(guesses.begin(), guesses.end(), &Hangman::isIncorrectGuess);
}
bool Hangman::isIncorrectGuess(char c)
{
return correctAnswer.find(c) == strin...
The Python documentation specifies that is is legal to omit the parentheses if a function only takes a single parameter, but
myfunction "Hello!"
generates a syntax error. So, what's the deal?
(I'm using Python 3.1)
EDIT:
The statement that I read only applies to generator expressions:
The parentheses can be omitted on ca...
At just after 2:40 in ShadowofCatron's Scala Tutorial 3 video, it's pointed out that the parentheses following the name of a thunk are optional. "Buh?" said my functional programming brain, since the value of a function and the value it evaluates to when applied are completely different things.
So I wrote the following to try this out....
I am a C# guy trying to translate some of my OOP understanding over to php. I'm trying to make my first class object, and are hitting a few hitches.
Here is the beginning of the class:
<?php
require("Database/UserDB.php");
class User {
private var $uid;
private var $username;
private var $password;
private var $realname;
...
I have just seen this in code
var thisYear = (new Date()).getFullYear();
See it live on JSbin.
This is cool, as I've always done something like that in 2 lines, i.e. create the new object instance and assigned it to a variable, then called the method on it.
Is this new method fine to use everywhere? Any gotchas?
...
What is the difference between += and =+?
Specifically, in java, but in general also.
...
I thought that the query below would naturally do what I explain, but apparently not...
My table looks like this:
id | name | g | partner | g2
1 | John | M | Sam | M
2 | Devon | M | Mike | M
3 | Kurt | M | Susan | F
4 | Stacy | F | Bob | M
5 | Rosa | F | Rita | F
I'm trying to get the id where either the g or g2 value equals 'M'......
I would like to pass a NSMutableArray by reference so that it can be altered by another method. What would be the correct syntax for this?
Thanks,
...
I read the other posted solutions to using structs and resolving the "Expected specifier-qualifier-list before struct" related errors, but those aren't working. Is it different in Objective C? Do I need to declare my struct somewhere else in the class? It gives me the error on the line where I declare the typedef. Here is how it look...
Hi,
I am working on an application and would like to apply some syntax highlighting to some user entered text. I have looked around and some people are suggesting that this can be done in OS 3.2+ but posts seem to be from before the NDA was lifted. Does anyone have any suggestions as to how to go about doing this?
I would be interested...
Hi guys,
The following code works like a charm:
BEGIN TRY
BEGIN TRANSACTION
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK;
DECLARE @ErrorMessage NVARCHAR(4000),
@ErrorSeverity int;
SELECT @ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY();
...
I'm probably typical in being bewildered by the many syntaxes of Wpf binding. Does anyone know of a chart that lays out all the possibilities. Across one axis is all the variations of binding syntaxes (Static, Dynamic, Self, ...), the other axis are all the variations of scoping and type. The intersection of the axis show an example.
Su...
What part of the C++ specification restricts argument dependent lookup from finding function templates in the set of associated namespaces? In other words, why does the last call in main below fail to compile?
namespace ns {
struct foo {};
template<int i> void frob(foo const&) {}
void non_template(foo const&) {}
}
int main(...
In C there is a do while loop and pascal's (almost) equivalent is the repeat until loop, but there is a small difference between the two, while both structures will iterate at least once and check whether they need to do the loop again only in the end, in pascal you write the condition that need to met to terminate the loop (REPEAT UNTIL...
Update: I tried a version of the script without the "beforeContentUpdate" part, and this script returns the following JSON
{"COLUMNS":["TNAME","TBRIEF","GAMEID","TITLEID","RDATE","GNAME","PABBR","PNAME","RSCORE","RNAME"],
"DATA":[["Dark Void","Ancient gods known as 'The Watchers,' once banished from our world by superhuman Adepts, have ...