You're both good people. The amount of time I spent banging my head against the keyboard over that is pretty ridiculous. Seriously, thanks a bunch.
Out of interest, is there a way (outside the main method) to convert an Alpha class object to a String (or int) while still using it in the Beta constructor? If I can't convert these objects then I can see myself having major problems with collections.
Thanks, that's helpful. Guess I need to learn more before I start thinking about things in the right way. Will keeping working at this and see what results.You think of it the wrong way. Objects have a type and a behaviour. An Alpha isn't a String. If you had an object that could just be converted to a String why would you not use a String in the first place.
You can however give the Alpha object a behavior (method) that represents the object in a String like fashion. You already did this by overriding the toString method.
You will be able to do even more stuff once you understand interfaces. With them you can give objects expected behavior.
int main(){
char *token;
const char *delim = " \n";
char userInput[SETMAX];
int exitLoop = 0;
struct sigaction act;
act.sa_handler = SIG_IGN;
sigaction(SIGINT, &act, NULL);
while (exitLoop == 0)
{
struct mystruct C;
initCom(&C);
printf("Input: ");
fflush(stdout);
fgets(userInput, sizeof(userInput), stdin); //grab user input
token = strtok(userInput, delim);
printf("Hello World\n");
while (token != NULL) //analyze tokens
{
printf("Goodbye\n");
.......
listOf' :: Integer -> Gen a -> Gen [a]
listOf' n g = vectorOf (fromInteger n) g
prop_listOf' n g = forAll (listOf' n g) (\e -> length e == fromInteger n)
*Main > quickCheck (prop_listOf' (5 (arbitrary::Gen Integer)))
<interactive>:510:1: error:
* No instance for (Show (Gen a0))
arising from a use of `quickCheck'
* In the expression:
quickCheck (prop_listOf' (5 (arbitrary :: Gen Integer)))
In an equation for `it':
it = quickCheck (prop_listOf' (5 (arbitrary :: Gen Integer)))
<interactive>:510:13: error:
* Ambiguous type variable `a0' arising from a use of prop_listOf'
prevents the constraint `(Show a0)' from being solved.
Probable fix: use a type annotation to specify what `a0' should be.
These potential instances exist:
instance Show (Blind a) -- Defined in `Test.QuickCheck.Modifiers'
instance Show a => Show (Fixed a)
-- Defined in `Test.QuickCheck.Modifiers'
instance Show a => Show (Large a)
-- Defined in `Test.QuickCheck.Modifiers'
...plus 37 others
...plus 89 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
* In the first argument of `quickCheck', namely
`(prop_listOf' (5 (arbitrary :: Gen Integer)))'
In the expression:
quickCheck (prop_listOf' (5 (arbitrary :: Gen Integer)))
In an equation for `it':
it = quickCheck (prop_listOf' (5 (arbitrary :: Gen Integer)))
<interactive>:510:27: error:
* No instance for (Num (Gen Integer -> Integer))
arising from the literal `5'
(maybe you haven't applied a function to enough arguments?)
* In the expression: 5
In the first argument of prop_listOf', namely
`(5 (arbitrary :: Gen Integer))'
In the first argument of `quickCheck', namely
`(prop_listOf' (5 (arbitrary :: Gen Integer)))'
I was asked to redefine the function listOf in Haskell to take an integer n and create a list in which each element is generated by g, and then write a test using QuickCheck seeing that it works. I got this code:
I'm having a hard time parsing what it's telling me here. Why does it need to show anything?
I was asked to redefine the function listOf in Haskell to take an integer n and create a list in which each element is generated by g, and then write a test using QuickCheck seeing that it works. I got this code:
Code:listOf' :: Integer -> Gen a -> Gen [a] listOf' n g = vectorOf (fromInteger n) g prop_listOf' n g = forAll (listOf' n g) (\e -> length e == fromInteger n)
It compiles but when I run it, I get:
Code:*Main > quickCheck (prop_listOf' (5 (arbitrary::Gen Integer))) <interactive>:510:1: error: * No instance for (Show (Gen a0)) arising from a use of `quickCheck' * In the expression: quickCheck (prop_listOf' (5 (arbitrary :: Gen Integer))) In an equation for `it': it = quickCheck (prop_listOf' (5 (arbitrary :: Gen Integer))) <interactive>:510:13: error: * Ambiguous type variable `a0' arising from a use of prop_listOf' prevents the constraint `(Show a0)' from being solved. Probable fix: use a type annotation to specify what `a0' should be. These potential instances exist: instance Show (Blind a) -- Defined in `Test.QuickCheck.Modifiers' instance Show a => Show (Fixed a) -- Defined in `Test.QuickCheck.Modifiers' instance Show a => Show (Large a) -- Defined in `Test.QuickCheck.Modifiers' ...plus 37 others ...plus 89 instances involving out-of-scope types (use -fprint-potential-instances to see them all) * In the first argument of `quickCheck', namely `(prop_listOf' (5 (arbitrary :: Gen Integer)))' In the expression: quickCheck (prop_listOf' (5 (arbitrary :: Gen Integer))) In an equation for `it': it = quickCheck (prop_listOf' (5 (arbitrary :: Gen Integer))) <interactive>:510:27: error: * No instance for (Num (Gen Integer -> Integer)) arising from the literal `5' (maybe you haven't applied a function to enough arguments?) * In the expression: 5 In the first argument of prop_listOf', namely `(5 (arbitrary :: Gen Integer))' In the first argument of `quickCheck', namely `(prop_listOf' (5 (arbitrary :: Gen Integer)))'
I'm having a hard time parsing what it's telling me here. Why does it need to show anything?
Not a Haskell guy at all, but I think you might need to add type annotations to the prop_listOf' function.
I guess... But how would I fix it?Its been a while since i've used Haskell, but i think that quickcheck writes failed tests to the console, so it needs Show to be able to do that.
Guys, this is tangentially related to programming, but I don't know where else to ask.
Does anyone knows somewhere to share surveys? I made a survey to validade the results from a neural network for my Bachelor Thesis, but I'm having trouble getting results.
At my programme there are occasionally surveys sent out for school projects through the programme email. Maybe try asking the programme managers if they can help you out?
I only use try-catch when the app definitely needs to not crash when that function fails. Usually you want it to crash so you can find the error early. Rarely use exceptions other than switch statements since C# can't figure out when I've exhaustively matched.While at work the other day, I realized that sometimes I look at my code and wonder if I'm handling exceptions correctly. I am working in C#, and I have a few questions/comments:
-I feel like I have try/catch statements all over my code and to me, that feels wrong. Is it common to have these blocks all over a code base? It seems messy.
-I have difficulty knowing when to use try/catch due to the many "levels" of the application. For example, there might be a try/catch around "o.DoSomething()" in main, but within that method, there might be another try/catch block already there.
-I assume I always want to aim to not handle general exceptions, but instead handle specific exceptions. Is this the correct mindset?
Unfortunately, I am the only one looking at the code a lot of the time so I tend to see these issues and possibly confuse myself more than I should. This project deals with users editing configuration files so there is a LOT of room for user error in the project's current form. Are there any good guides out there focused on this topic? Exception handling definitely seems to be one of my weaker spots when it comes to implementation and I'd like to improve that.
I only use try-catch when the app definitely needs to not crash when that function fails. Usually you want it to crash so you can find the error early. Rarely use exceptions other than switch statements since C# can't figure out when I've exhaustively matched.
While at work the other day, I realized that sometimes I look at my code and wonder if I'm handling exceptions correctly. I am working in C#, and I have a few questions/comments:
-I feel like I have try/catch statements all over my code and to me, that feels wrong. Is it common to have these blocks all over a code base? It seems messy.
-I have difficulty knowing when to use try/catch due to the many "levels" of the application. For example, there might be a try/catch around "o.DoSomething()" in main, but within that method, there might be another try/catch block already there.
-I assume I always want to aim to not handle general exceptions, but instead handle specific exceptions. Is this the correct mindset?
Unfortunately, I am the only one looking at the code a lot of the time so I tend to see these issues and possibly confuse myself more than I should. This project deals with users editing configuration files so there is a LOT of room for user error in the project's current form. Are there any good guides out there focused on this topic? Exception handling definitely seems to be one of my weaker spots when it comes to implementation and I'd like to improve that.
import java.util.*;
public class Rod {
private ArrayList<Integer> arrayL = new ArrayList<Integer>();
private int numberOfDisks;
public Rod(int numberOfDisks) {
super();
this.numberOfDisks = numberOfDisks;
// Depending on the # of disks entered by user, this populates list
// array
for (int i = numberOfDisks; i > 0; i--) {
arrayL.add(i);
}
}
public ArrayList<Integer> getArrayL() {
return arrayL;
}
public int getNumberOfDisks() {
return numberOfDisks;
}
public int getDisk() {
return arrayL.get(arrayL.size());
}
public int addDisk() {
return getDisk();
}
public String toString() {
return; //contents of string how??
}
}
Can any of you beautiful fellas help me with this Java problem:
![]()
I can't, for the life of me, figure out how to set up the rod class. I'm wasting time with no progress. Thanks!
Nope, this is my first serious programming class in general.
Hey everyone. New to web stuff here.
I'm writing a web based interface for a program that takes an input file, crunches it (takes anywhere from 1 to 30 minutes) and returns an output zip file. Using python and flask I quickly threw something together and basically "/hash/download" returns the output file if it's done, or a simple error message if it's still processing. (hash is the md5 of the input file).
Question is, what should I look into implementing so that the client page doesn't have to send a request "/hash/download" every 5s?
WebSockets if you're looking to keep a connection and constantly update them. Assuming I'm understanding you right.
https://flask-socketio.readthedocs.io/en/latest/
https://github.com/kennethreitz/flask-sockets
Hey everyone. New to web stuff here.
I'm writing a web based interface for a program that takes an input file, crunches it (takes anywhere from 1 to 30 minutes) and returns an output zip file. Using python and flask I quickly threw something together and basically "/hash/download" returns the output file if it's done, or a simple error message if it's still processing. (hash is the md5 of the input file).
Question is, what should I look into implementing so that the client page doesn't have to send a request "/hash/download" every 5s?
-Long polling
-Websockets
-Server-sent events
-HTTP streams
-WebRTC data channel
Really depends on your browser compatibility needs as they all have their ups and downs.
I'll check those out too, thanks.
Browser requirements are not a problem, it's for internal use.
I'm trying to fill these private double members in this object with doubles stored in an array that gets passed to the object as a parameter but it keeps coming up with different numbers (like 2.023904e-310). Is it passing the address of the array element into the variable? How do I fix that?
Need example code
class someclass
{
private:
int a;
public:
someclass(int array[])
{
array[0] = a;
}
}
Something like
and it keeps putting the wrong value in a.
You're not assigning anything to "a" in that code.
So it is just putting the array address into it?
You're seem to have reversed the assignment. You are assigning the value of a to the first element of the array.
app.get('/edit', function(req, res, next) {
console.log(req.query.fname);
console.log(req.query.lname);
connection.query("UPDATE `users` SET fname=?, lname=?, pword=? WHERE userID =?", [req.query.fname, req.query.lname, req.query.pword, req.query.userID], function(err, result){
if(err){
next(err);
return;
}
res.render('home', {user: req.user})
});
});
For whatever reason this isn't working the way I want it to. I need this to successfully update a mysql database. This is in express/express-handlebars.
Code:app.get('/edit', function(req, res, next) { console.log(req.query.fname); console.log(req.query.lname); connection.query("UPDATE `users` SET fname=?, lname=?, pword=? WHERE userID =?", [req.query.fname, req.query.lname, req.query.pword, req.query.userID], function (err, result) { if (err) { next(err); return; } res.render('home', {user: req.user}) }); });
console.log statements show the correct stuff is being sent in the query when the user submits an edit to a data field.
Pretty sure my sql syntax is correct. I'm not getting any parse errors.
The page just goes from the edit screen to rendering 'home' , with no update to the database actually being applied.
Any idea why?
The `users` shouldn't probably be in backticks.
Furthermore, you should consider using `PUT` instead of `GET` requests for edits
Thanks, I'll try that.
And yeah, I know it should be in PUT for edits. But I'll deal with that later.
edit: removing backticks changed nothing.
edit: figured it out.
node debug <script>
Possibly stupid question, because I'm newbie for interactive js scripts.
Have someone managed to use a javascript with a read-eval-print-loop inside a Python script?
For example using subprocess.Popen?
Should I investigate or is it a lost cause?
(that's mostly a runaround solution because I can't install python modules on OS-X because of C compiler not working, and I don't want to spend hours doing system administration on OS-X)
Because I'm not the developper, and the students that will write the code know only Python and don't have time to learn js (not that I'm fluent in js myself, to be honest).I'm confused why this is necessary. Why not skip python and just use node?
- a python module I haven't managed to install on OS-X and that will probably be troublesome on windows too (because it tries to compile code at installation... works flawlessly on Linux, though)