Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Jewbert Jewstein
Dec 4, 2007

Bring me a hard copy of the Internet so I can do some serious surfing
Say I have 2 columns of data in excel such as:
code:
Type  # of each
1     3
1     4
1     1
1     3
2     3
2     1
2     1
3     4
4     2
4     3
Can I write an excel macro that would show me just one instance of 1, 2, 3, and 4 that would sum the 2nd column for me?
code:
Results:
1     11
2     5
3     4
4     5

Adbot
ADBOT LOVES YOU

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Jewbert: if I understand what you're asking, that sounds like exactly what pivot tables are for. Does it have to be a macro?

Jewbert Jewstein
Dec 4, 2007

Bring me a hard copy of the Internet so I can do some serious surfing
Why so it is. I love these general question threads. They always make me feel so stupid. Thanks Internet Janitor.

greatn
Nov 15, 2006

by Lowtax
I've been working with some Qt GUI stuff in C++, and honestly every time I try to use signals/slots, I just get kind of baffled. It is completely alien to me. I always end up just programming it like I would a standard .net application, with an event call. Luckily Qt supports this well and I've gotten away with it, but I need to get better at Signals/slots sometime. I have a couple of books but they haven't really made me any smarter on the whole thing.

Any suggestions for a good tutorial to learn signals/slots better? Literally the only thing I've done with them is make some display dials/spinboxes match in a couple of places where it was convenient.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

greatn posted:

I always end up just programming it like I would a standard .net application, with an event call. Luckily Qt supports this well and I've gotten away with it, but I need to get better at Signals/slots sometime.
This is about all there is to it; what are you looking for? Signals & slots are just Qt's stupid language extensions that they made to implement type-safe callbacks.

quote:

Any suggestions for a good tutorial to learn signals/slots better?
http://doc.trolltech.com/4.7/signalsandslots.html

Vanadium
Jan 8, 2005

http://libsigc.sourceforge.net/


:colbert:

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
http://www.boost.org/doc/libs/1_44_0/doc/html/signals2.html

papanugget
Aug 8, 2000
A little javascript help please?

I'm trying to produce a multiplication table that looks like this but using nested loops instead of handcoding each line. If you could either point out a syntax error or nesting location error that would be very helpful.

Handcoded table:
code:
<script type="text/javascript">

document.write('<table width="50%" border="1" cellspacing="5" cellpadding="5">');
document.write("<tr>");
	var A=["X",1,2,3,4,5,6,7,8,9];
	var B=["X",1,2,3,4,5,6,7,8,9];

document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [A][0][0] + '</td>');
document.write('<td bgcolor="#00FFFF">' + [A][0][1] + '</td>');
document.write('<td bgcolor="#00FFFF">' + [A][0][2] + '</td>');
document.write('<td bgcolor="#00FFFF">' + [A][0][3] + '</td>');
document.write('<td bgcolor="#00FFFF">' + [A][0][4] + '</td>');
document.write('<td bgcolor="#00FFFF">' + [A][0][5] + '</td>');
document.write('<td bgcolor="#00FFFF">' + [A][0][6] + '</td>');
document.write('<td bgcolor="#00FFFF">' + [A][0][7] + '</td>');
document.write('<td bgcolor="#00FFFF">' + [A][0][8] + '</td>');
document.write('<td bgcolor="#00FFFF">' + [A][0][9] + '</td>');
document.write('</tr>');


document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [B][0][1] + '</td>');
document.write('<td>' + [A][0][1]*[B][0][1] + '</td>');
document.write('<td>' + [A][0][2]*[B][0][1] + '</td>');
document.write('<td>' + [A][0][3]*[B][0][1] + '</td>');
document.write('<td>' + [A][0][4]*[B][0][1] + '</td>');
document.write('<td>' + [A][0][5]*[B][0][1] + '</td>');
document.write('<td>' + [A][0][6]*[B][0][1] + '</td>');
document.write('<td>' + [A][0][7]*[B][0][1] + '</td>');
document.write('<td>' + [A][0][8]*[B][0][1] + '</td>');
document.write('<td>' + [A][0][9]*[B][0][1] + '</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [B][0][2] + '</td>');
document.write('<td>' + [A][0][1]*[B][0][2] + '</td>');
document.write('<td>' + [A][0][2]*[B][0][2] + '</td>');
document.write('<td>' + [A][0][3]*[B][0][2] + '</td>');
document.write('<td>' + [A][0][4]*[B][0][2] + '</td>');
document.write('<td>' + [A][0][5]*[B][0][2] + '</td>');
document.write('<td>' + [A][0][6]*[B][0][2] + '</td>');
document.write('<td>' + [A][0][7]*[B][0][2] + '</td>');
document.write('<td>' + [A][0][8]*[B][0][2] + '</td>');
document.write('<td>' + [A][0][9]*[B][0][2] + '</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [B][0][3] + '</td>');
document.write('<td>' + [A][0][1]*[B][0][3] + '</td>');
document.write('<td>' + [A][0][2]*[B][0][3] + '</td>');
document.write('<td>' + [A][0][3]*[B][0][3] + '</td>');
document.write('<td>' + [A][0][4]*[B][0][3] + '</td>');
document.write('<td>' + [A][0][5]*[B][0][3] + '</td>');
document.write('<td>' + [A][0][6]*[B][0][3] + '</td>');
document.write('<td>' + [A][0][7]*[B][0][3] + '</td>');
document.write('<td>' + [A][0][8]*[B][0][3] + '</td>');
document.write('<td>' + [A][0][9]*[B][0][3] + '</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [B][0][4] + '</td>');
document.write('<td>' + [A][0][1]*[B][0][4] + '</td>');
document.write('<td>' + [A][0][2]*[B][0][4] + '</td>');
document.write('<td>' + [A][0][3]*[B][0][4] + '</td>');
document.write('<td>' + [A][0][4]*[B][0][4] + '</td>');
document.write('<td>' + [A][0][5]*[B][0][4] + '</td>');
document.write('<td>' + [A][0][6]*[B][0][4] + '</td>');
document.write('<td>' + [A][0][7]*[B][0][4] + '</td>');
document.write('<td>' + [A][0][8]*[B][0][4] + '</td>');
document.write('<td>' + [A][0][9]*[B][0][4] + '</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [B][0][5] + '</td>');
document.write('<td>' + [A][0][1]*[B][0][5] + '</td>');
document.write('<td>' + [A][0][2]*[B][0][5] + '</td>');
document.write('<td>' + [A][0][3]*[B][0][5] + '</td>');
document.write('<td>' + [A][0][4]*[B][0][5] + '</td>');
document.write('<td>' + [A][0][5]*[B][0][5] + '</td>');
document.write('<td>' + [A][0][6]*[B][0][5] + '</td>');
document.write('<td>' + [A][0][7]*[B][0][5] + '</td>');
document.write('<td>' + [A][0][8]*[B][0][5] + '</td>');
document.write('<td>' + [A][0][9]*[B][0][5] + '</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [B][0][6] + '</td>');
document.write('<td>' + [A][0][1]*[B][0][6] + '</td>');
document.write('<td>' + [A][0][2]*[B][0][6] + '</td>');
document.write('<td>' + [A][0][3]*[B][0][6] + '</td>');
document.write('<td>' + [A][0][4]*[B][0][6] + '</td>');
document.write('<td>' + [A][0][5]*[B][0][6] + '</td>');
document.write('<td>' + [A][0][6]*[B][0][6] + '</td>');
document.write('<td>' + [A][0][7]*[B][0][6] + '</td>');
document.write('<td>' + [A][0][8]*[B][0][6] + '</td>');
document.write('<td>' + [A][0][9]*[B][0][6] + '</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [B][0][7] + '</td>');
document.write('<td>' + [A][0][1]*[B][0][7] + '</td>');
document.write('<td>' + [A][0][2]*[B][0][7] + '</td>');
document.write('<td>' + [A][0][3]*[B][0][7] + '</td>');
document.write('<td>' + [A][0][4]*[B][0][7] + '</td>');
document.write('<td>' + [A][0][5]*[B][0][7] + '</td>');
document.write('<td>' + [A][0][6]*[B][0][7] + '</td>');
document.write('<td>' + [A][0][7]*[B][0][7] + '</td>');
document.write('<td>' + [A][0][8]*[B][0][7] + '</td>');
document.write('<td>' + [A][0][9]*[B][0][7] + '</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [B][0][8] + '</td>');
document.write('<td>' + [A][0][1]*[B][0][8] + '</td>');
document.write('<td>' + [A][0][2]*[B][0][8] + '</td>');
document.write('<td>' + [A][0][3]*[B][0][8] + '</td>');
document.write('<td>' + [A][0][4]*[B][0][8] + '</td>');
document.write('<td>' + [A][0][5]*[B][0][8] + '</td>');
document.write('<td>' + [A][0][6]*[B][0][8] + '</td>');
document.write('<td>' + [A][0][7]*[B][0][8] + '</td>');
document.write('<td>' + [A][0][8]*[B][0][8] + '</td>');
document.write('<td>' + [A][0][9]*[B][0][8] + '</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td bgcolor="#00FFFF">' + [B][0][9] + '</td>');
document.write('<td>' + [A][0][1]*[B][0][9] + '</td>');
document.write('<td>' + [A][0][2]*[B][0][9] + '</td>');
document.write('<td>' + [A][0][3]*[B][0][9] + '</td>');
document.write('<td>' + [A][0][4]*[B][0][9] + '</td>');
document.write('<td>' + [A][0][5]*[B][0][9] + '</td>');
document.write('<td>' + [A][0][6]*[B][0][9] + '</td>');
document.write('<td>' + [A][0][7]*[B][0][9] + '</td>');
document.write('<td>' + [A][0][8]*[B][0][9] + '</td>');
document.write('<td>' + [A][0][9]*[B][0][9] + '</td>');
document.write('</tr>');
document.write("</tr>");
document.write("</table>");
	</script>
Nested loop table:
I have commmented where I think the "if" statement should go for the first row and first column but I'm not sure how to proceed. Every statement I've tried so far either resulted in either just one cell being populated or the script looping back and crashing.
code:
<script ="text/javascript">


document.write('<table width="50%" border="1" cellspacing="5" cellpadding="5">');

for(col=0;col<=10;col++)	//second loop written to iterate 1st loop 10 times
	{	//second loop written to iterate 1st loop 10 times
			//if(col == 0 && row == 0)//third loop for 1st row repeat once
			
		   //if(x=0)//fourth loop for 1st column repeat once
	document.write("<tr>");	//first loop written for 1-10 iteration in table
		
		for(row=0;row<=10;row++)	//first loop written for 1-10 iteration in table
		{	//first loop written for 1-10 iteration in table
			document.write('<td>', row, '</td>');	//3rd step change value of x to x*y
		}	//first loop written for 1-10 iteration in table
	document.write('</tr>');	//first loop written for 1-10 iteration in table

	}	//second loop written to iterate 1st loop 10 times
document.write('</table>');

</script>
Thanks in advance.

First Time Caller
Nov 1, 2004

code:
<script type="text/javascript">
    var columns = 10;
    var rows = 10;

    print_multiplication_table(columns,rows);
	
    function print_multiplication_table(columns,rows) {
         document.write('<table width="50%" border="1" cellspacing="5" cellpadding="5">');
	 document.write('<tr><td> </td>');
	 for(col=1;col<=columns;col++) { document.write('<td>',col,'</td>');}
	 document.write('</tr>');

	 for(col=0;col<=columns;col++) {
	      document.write("<tr>");	
	      for(row=0;row<=rows;row++) {
	           if(row==0) {
	                document.write('<td>',col,'</td>')
	           } else {
	                document.write('<td>', row*col,'</td>');
	           }
	      }	
	      document.write('</tr>');
	 }	
	 document.write('</table>');
     }
</script>
produces:

code:
 	1	2	3	4	5	6	7	8	9	10
0	0	0	0	0	0	0	0	0	0	0
1	1	2	3	4	5	6	7	8	9	10
2	2	4	6	8	10	12	14	16	18	20
3	3	6	9	12	15	18	21	24	27	30
4	4	8	12	16	20	24	28	32	36	40
5	5	10	15	20	25	30	35	40	45	50
6	6	12	18	24	30	36	42	48	54	60
7	7	14	21	28	35	42	49	56	63	70
8	8	16	24	32	40	48	56	64	72	80
9	9	18	27	36	45	54	63	72	81	90
10	10	20	30	40	50	60	70	80	90	100
You can avoid a lot of bullshit and make your code a lot easier to read and understand if you just print the first row of the table seperately.

First Time Caller fucked around with this message at 22:01 on Oct 14, 2010

ZentraediElite
Oct 22, 2002

This is killing me, and I don't know exactly how to explain it, much less fix it. However, I think it's my problem.

I recently had my work laptop reimaged so I'm installing SQL Server Express again.

It installed with a named instance (SQLEXPRESS), so when I open SQL Studio I have to connect to MACHINE NAME\SQLEXPRESS. What I need to be able to do is have SQLEXPRESS be what I would name the "default" instance on my machine, so that I can connect to simply my MACHINE NAME and have it resolve. Does that make sense?

I understand that I can also connect to myself via 127.0.0.1, localhost, and ., but I need to do it by machine name for these purposes.

Any ideas?

EDIT:
I've enabled Named Pipes on the SQLEXPRESS instance, and restarted the services, but that doesn't seem to have done anything.

ZentraediElite fucked around with this message at 22:19 on Oct 14, 2010

papanugget
Aug 8, 2000

First Time Caller posted:

helpful advice

That set me on the right path. Thanks very much.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Generally how do people handle doing time-consuming tasks in a GUI callback function? I have some code that has to shuffle some stuff around, which takes just enough time to be annoying, but not enough time to perhaps put a cancel action on it. So I thought in the callback I'd put the requisite code in a thread and detach it. I am figuring this is the simple solution but I wondered if there were some more advanced concepts I should be thinking about right now before I, say, do this all over the place. In this case I'm using C++ with Boost and FLTK.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I have a Windows app that I'm writing in python and will be packaging up with py2exe or something similar. It requires a DLL to be registered on Windows. I'm not familiar with distribution of Windows apps.

What's the best way to handle this for end users instead of making them open a command prompt with admin privileges and typing "regsvr32.exe blah.dll"? I can of course register it programatically from python, but that still doesn't solve the needing admin privs...

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Thermopyle posted:

I have a Windows app that I'm writing in python and will be packaging up with py2exe or something similar. It requires a DLL to be registered on Windows. I'm not familiar with distribution of Windows apps.

What's the best way to handle this for end users instead of making them open a command prompt with admin privileges and typing "regsvr32.exe blah.dll"? I can of course register it programatically from python, but that still doesn't solve the needing admin privs...

You'll need to write an installer. It's pretty easy to get started with NSIS, and it's free, so you should definitely check it out.

Bozart
Oct 28, 2006

Give me the finger.

Rocko Bonaparte posted:

Generally how do people handle doing time-consuming tasks in a GUI callback function? I have some code that has to shuffle some stuff around, which takes just enough time to be annoying, but not enough time to perhaps put a cancel action on it. So I thought in the callback I'd put the requisite code in a thread and detach it. I am figuring this is the simple solution but I wondered if there were some more advanced concepts I should be thinking about right now before I, say, do this all over the place. In this case I'm using C++ with Boost and FLTK.

Pretty sure this is the right way to do it.

Opinion Haver
Apr 9, 2007

Bozart posted:

Pretty sure this is the right way to do it.

Yep. Even if you were gonna pop up a dialog box with a cancel option, you'd still want to fork off a thread so your user can interact with the rest of the application (unless it makes no sense to do so while you're doing the action, like playing music from an MP3 player while you're copying music to it or something).

duck monster
Dec 15, 2004

Not quite a programming question, but an IDE question.

I'm using eclipse and remote-systems-explorer plugin to do SCP stuff.

The problem is, almost at random it choses various files and silently saves them to cache instead of remote end, and then starts loading it from cache. Meaning the remote end never gets updated.

I've been searching google high and low and cant find any documentation to tell me how to induce it to cut this poo poo out, and eclipse IRC on freenode isn't being useful at all.

Any eclipse boffins got ideas on the cause of this?

ufarn
May 30, 2009
Moscow SML. I have to write a function that returns the average age of the people in an ancestry tree who have a registered birth and death. The returned value has to be int option.

The data types are

code:
datatype name    = Name of string;
datatype sex     = M | F;
datatype year = Year of int | Unknown | Irrelevant;
datatype person  = Person of (name * sex * year * year); 
datatype ancTree = Anctree of person * ancTree * ancTree | Udefined;
I've written two functions: to support the avage function: dead counts the number of dead people with a registered birth and death.

agesum counts the age of the people with a registered birth and death and sums them.

avage finally divides the summed ages with the number of dead people to find the average age.

code:
fun dead AncTree (Person (_, _, Year b, Year d), mt, ft) = 
    if valOf(SOME b) < valOf(SOME d) then
      valOf(SOME d) - valOf(SOME b) + (dead mt) + (dead ft)
    else (dead mt) + (dead ft)
  | doede AncTree _ = SOME 0;

fun agesum AncTree (Person (_, _, Year b, Year d), mt, ft) = 
    if valOf(SOME b) < valOf(SOME d) then 
      1 + (agesum mt) + (dead ft)
    else (agesum mt) + (agesum ft)
  | agesum AncTree _ = SOME 0;

fun avage AncTree as at = if (agesum at) = SOME 0 orelse (dead at) = SOME 0 then
                               NONE
                             else valOf(agesum at) div valOf(dead at);
I don't feel very comfortable trying to figure this out. I get this error:

code:
!       valOf(SOME d) - valOf(SOME b) + (dead  mt) + (doede ft)
!                                        ^^^^^^^^
! Type clash: expression of type
!   person * 'a * 'b -> int
! cannot have type
!   int
... which refers to the third line of dead.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

ufarn posted:

dead counts the number of dead people with a registered birth and death.

agesum counts the age of the people with a registered birth and death and sums them.

Why not have a single function that returns a maybe (int, int)?

ufarn posted:

code:
fun dead AncTree (Person (_, _, Year b, Year d), mt, ft) = 

!       valOf(SOME d) - valOf(SOME b) + (dead  mt) + (doede ft)
!                                        ^^^^^^^^
! Type clash: expression of type
!   person * 'a * 'b -> int
! cannot have type
!   int

This error message is pretty clear. The context wants an int — because you're adding something to an int — but you're providing an object with function type. You don't think you are, but you are. That's because the grammar rules for fun declarations are a little wierd, so instead of parsing as a single parameter matching the pattern AncTree(Person(_,_, Year b, Year d), mt, ft)), this parses as two curried parameters matching the patterns AncTree and (Person(_,_, Year b, Year d), mt, ft)). You have to parenthesize constructor patterns at the top level, I'm afraid.

ufarn
May 30, 2009

rjmccall posted:

Why not have a single function that returns a maybe (int, int)?
Don't think I didn't try, but I just couldn't figure it out.

rjmccall posted:

This error message is pretty clear. The context wants an int — because you're adding something to an int — but you're providing an object with function type. You don't think you are, but you are. That's because the grammar rules for fun declarations are a little wierd, so instead of parsing as a single parameter matching the pattern AncTree(Person(_,_, Year b, Year d), mt, ft)), this parses as two curried parameters matching the patterns AncTree and (Person(_,_, Year b, Year d), mt, ft)). You have to parenthesize constructor patterns at the top level, I'm afraid.
I had a feeling about that, but I didn't recall hearing of it being possible in SML.

What exactly does parenthesizing the constructor patterns at top level entail? Do you mean writing (AncTree (Person (_, _, Year b, Year d), mt, ft))?

It's an assignment I've been mulling over for ages, and it's driving me crazy.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

ufarn posted:

Don't think I didn't try, but I just couldn't figure it out.

Okay. It might make the rest of your class easier if you can.

ufarn posted:

I had a feeling about that, but I didn't recall hearing of it being possible in SML.

Currying? Definitely possible in SML.

ufarn posted:

What exactly does parenthesizing the constructor patterns at top level entail? Do you mean writing (AncTree (Person (_, _, Year b, Year d), mt, ft))?

Yep. The idea is that the pattern grammar looks kindof like this:
code:
  pattern ::= '_'    # match arbitrary value, don't bind it to a variable
            | identifier     # match arbitrary value, bind it to a variable
            | '(' pattern ')'     # match as subpattern
            | '(' pattern (',' pattern)+ ')'     # match tuple with elements matching subpatterns
            | identifier pattern*     # match constructor with arguments matching subpatterns
            | ... # some other cases that aren't immediately relevant
but the fun grammar looks like this:
code:
fun-decl ::= 'fun' identifier pattern* = expression
and it turns out that the fun grammar really has to take precedence, so that unparenthesized things get "torn apart" and become separate arguments.

Also, when the compiler sees an identifier pattern, it has to figure out whether you're trying to match a specific no-argument constructor or whether you're just binding a variable. To do that, it has to look up the name to see if it's the name of a known constructor. This lookup — like everything else in the language — is case-sensitive. So if your type declaration has it as Anctree, it needs to be exactly that; your code has it inconsistent, and I suspect that you'd have gotten a better error message except that you also had the capitalization wrong.

rjmccall fucked around with this message at 19:27 on Oct 18, 2010

ufarn
May 30, 2009

rjmccall posted:

Cool tips.
I'm operating on a few hours of sleep and a power nap, so I may be dense. I also feel like I've worked on this for so long, I've acquired some kind of code blindness which makes me overlook the most silly things. I wrapped the expressions in parentheses and renamed the wrongly capitalized constructor (:doh:) like this:

code:
fun dead (Anctree (Person (_, _, Year b, Year d), mt, ft)) = 
    if valOf(SOME b) < valOf(SOME d) then
      valOf(SOME d) - valOf(SOME b) + (dead mt) + (dead ft)
    else (doede mt) + (doede ft)
  | doede AneTrae _ = SOME 0;

fun agesum (Anctree (Person (_, _, Year b, Year d), mt, ft)) = 
    if valOf(SOME b) < valOf(SOME d) then 
      1 + (agesum mt) + (dead ft)
    else (agesum mt) + (agesum ft)
  | agesum Anctrae _ = SOME 0;
But I get this now:

code:
! ....dead (Anctree (Person (_, _, Aarstal b, Aarstal d), mt, ft)) = 
!     if valOf(SOME b) < valOf(SOME d) then
!       valOf(SOME d) - valOf(SOME b) + (doede mt) + (doede ft)
!     else (doede mt) + (doede ft)
!   | doede AneTrae _ = SOME 0.
! Mismatch in the number of curried arguments

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
That message is saying that, syntactically, the different cases of your fun are taking different numbers of arguments. Here that's because the following is parsed (for the same reasons as above) as two different arguments:

ufarn posted:

| doede AneTrae _ = SOME 0;

This should almost certainly be "| doede _ = SOME 0". Except I don't think that's the right logic, because I think you should be recursing on the ancestor's parents regardless of whether you have year data for that ancestor.

(I assume that your functions, types, and constructors are inconsistently named because you are actually writing this in Danish and translating them into English for the forum).

ufarn
May 30, 2009

rjmccall posted:

That message is saying that, syntactically, the different cases of your fun are taking different numbers of arguments. Here that's because the following is parsed (for the same reasons as above) as two different arguments:


This should almost certainly be "| doede _ = SOME 0". Except I don't think that's the right logic, because I think you should be recursing on the ancestor's parents regardless of whether you have year data for that ancestor.

(I assume that your functions, types, and constructors are inconsistently named because you are actually writing this in Danish and translating them into English for the forum).
Now I'm getting this error:

code:
!   | doede _ = SOME 0;
!               ^^^^^^
! Type clash: expression of type
!   'a option
! cannot have type
!   int
Which is because I use the int option value SOME 0 as a regular int in my valOf + ... expression.

It's also made me realize that my final function is going to return an int value, and not an int option value, meaning that I'll have to revise the code. Again. Sigh.

I think I'll let the auxiliary functions return int and convert it to int option in the final function. Although that sounds messy as hell and besides the point, but I'm all about just making something that runs where I am right now.

ufarn fucked around with this message at 00:59 on Oct 19, 2010

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
I don't know why you think that's a problem. Logically, there's a very good reason your final function has to return an option type: it's possible to have no matching people in an ancestor tree, so you have to have some way to indicate that, because you can't take an average of zero numbers. That's not true of your helper functions! There's no place where it makes anything simpler to return NONE instead of SOME 0, which is a pretty compelling argument that you don't really want an option type.

waspinator
Oct 18, 2004

by Y Kant Ozma Post
I'm trying to write a plugin for Joomla that will pull a city from a Geolocation database and based on where they are, show a different version of a website.

Our company owns skating rinks in 2 cities, and corporate wants each rink to have its own information on the site and calendars, as opposed to mixed together. The problem is, I'm not even sure where to begin with this, or where I could find a good free Geolocation database that isn't based on country, but IP, Zip Code, or cities.

This plugin would more than likely be written in php.

Basically in a nutshell..

Site 1 has an event on the 19th - Family Night
Site 2 has an event on the 19th - Free Skate

and corporate wants it to only show the location nearest you via information on the website and calendar instead of both of those events.

Any suggestions? Is this even possible?

ufarn
May 30, 2009
I revised my Moscow ML code from before to this:

code:
fun dead (Anctree (Person (_, _, Aarstal b, Aarstal d), mt, ft)) = 
    if b < d then
      1 + (dead mt) + (dead ft)
    else (dead mt) + (dead ft)
  | dead Udefineret = 0
  | dead (Anctree (_, mt, ft)) = (dead mt) + (dead ft);

fun agesum (Anctree (Person (_, _, Aarstal b, Aarstal d), mt, ft)) = 
    if b < d then 
      (d - b) + (agesum mt) + (agesum ft)
    else (agesum mt) + (agesum ft)
  | agesum Udefineret = 0
  | agesum (Anctree (_, mt, ft)) = (agesum mt) + (agesum ft);

fun avage at = if (agesum at) = 0 orelse (dead at) = 0 then
                    NONE
                  else
                    SOME ((agesum at) div (dead at));
I was just about to hand it in, but, if I check, I get an agesum of 90 and 5 dead, which gives me an average age of 18.

I briefly checked the values, and I think these are the valid ages:


1: 59
2: 60
3: 71
4: 71
5: 27
-----
5: 288

288 div 5 = 57


I recall getting a value somewhat close to 288, if not that, but I must have messed up something in the code. dead seems to work, but agesum is obviously totally bonkers.

I don't really have a clue what is up - dead might be botched as well.

Everything compiles just fine.

Gucci Loafers
May 20, 2006

Ask yourself, do you really want to talk to pair of really nice gaudy shoes?


I've got a drive with about 100k+ of files with all of these spread across some 600+ folders amounting to a total of 300Gbs+. All the folders are named appropriately, 1,2,3,56,57,102,etc.

[code]
Parent Folder
-1(Folder)
-2
-3(expanded folder)
+fileblah.001
+fileblah.002
+fileblah.003

What I need to do is put these files into a zip, of course I really don't want a 300gb zip, so I'm thinking I could do a bunch of 5GB+ zips.

My question is, is XCOPY capable of at least moving these all into one folder? Or am I going to have to program something to do this, and if so how would I figure this out in Java? I know a bit, but if someone could point me in the right direction, that'd help and I could probably take it from there.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Tab8715 posted:

My question is, is XCOPY capable of at least moving these all into one folder? Or am I going to have to program something to do this, and if so how would I figure this out in Java? I know a bit, but if someone could point me in the right direction, that'd help and I could probably take it from there.

If you're running a relatively recent OS I suggest checking out the Powershell thread since it sounds like something that could do pretty easily. The original poster is pretty active and has actually provided run-ready scripts and so on for other people who post their problems there.

FamDav
Mar 29, 2008
code:
1 ]=> (define a '(q r s))

;Value: a

1 ]=> (cons (cdr a) (car a))

;Value 15: ((r s) . q)

Why is there a period in my Scheme list. I'd look through documentation, but searching for "." isn't really effective.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
That's just the infix cons notation:

code:
guile> (cons 'x (cons 'y (cons 'z '())))
(x y z)
guile> '(x . (y . (z . ())))
(x y z)
See?

mr_jim
Oct 30, 2006

OUT OF THE DARK

To elaborate a bit, cons just creates "dotted pairs". The cdr of a pair can be another pair, which can have a cdr that's a pair, and so on. If the cdr of the last pair is '(), then it's a list. Otherwise it's just a series of dotted pairs.

http://en.wikipedia.org/wiki/Cons#Lists might explain it better.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
Anyone here a pro with ANTLR?

I'm developing a toy language to play around with, and I have a situation in my grammar where I want to reuse a set of rules in two different contexts, but where something recognized deeper down in the parse tree relies on the context way further up.

To try to elaborate: I have the usual set of expression rules for a typical programming language, for operator precedence and such. For simplicity, let's pretend I have expressions that look like this:
code:
expression : expression '+' term | term;
term : term '*' factor | factor;
factor : '(' expression ')' | literal;
These are used in two separate contexts:
code:
statement1 : expression /* other stuff */ ;
statement2 : expression /* other stuff */ ;
The catch is, I want the "literal" rule in the grammar (see the "factor" rule) to be syntactically different depending on whether I'm parsing it coming from "statement1" or "statement2".

Does ANTLR have a simple way of expressing this, without having two separate copies of the rules that are exactly the same except for the definition of "literal" at the end? I've tried digging around in the docs but haven't really found anything that seems to work.

Aluminum Record
Feb 2, 2008

When you rip off the breakaway pants, thrust your pelvis toward the bachelorette.
We're programming a Zork-like game for my data structures class. I have a menu using a do-while loop and a switch statement. One of the menu options then requires the user to input a string of text that may contain spaces. getline(cin, theString) is failing me. If I put it at the beginning of my code, outside of the loops and switch statement, like so

string theString;
getline(cin, theString);
cout << theString << endl;

It works perfectly fine. But when I choose the menu option, and it goes to that case statement which contains the getline, it is like the getline statement gets completely stepped over. The program doesn't stop and wait for the user to input anything, it just keeps right on going and reprints the menu and awaits for a new menu input. Anyone know why getline won't work in a switch statement within a do-while loop, and if so any easy fixes?

TasteMyHouse
Dec 21, 2006

Aluminum Record posted:

We're programming a Zork-like game for my data structures class. I have a menu using a do-while loop and a switch statement. One of the menu options then requires the user to input a string of text that may contain spaces. getline(cin, theString) is failing me. If I put it at the beginning of my code, outside of the loops and switch statement, like so

string theString;
getline(cin, theString);
cout << theString << endl;

It works perfectly fine. But when I choose the menu option, and it goes to that case statement which contains the getline, it is like the getline statement gets completely stepped over. The program doesn't stop and wait for the user to input anything, it just keeps right on going and reprints the menu and awaits for a new menu input. Anyone know why getline won't work in a switch statement within a do-while loop, and if so any easy fixes?
First, there's a C++ thread ;)

Second, problems like this are often caused by mixing ">>" and getline -- ">>" doesn't eat \n, so the return that the user enters when they're finished with the "\n" is still sitting there on the input buffer, and then the getline sees that keypress and figures that thats the end of the line that it is looking for.

This can be solved a number of ways -- I think the easiest way is to call getline once to "prime" it for the "real" call.

tef
May 30, 2004

-> some l-system crap ->

Flobbster posted:

The catch is, I want the "literal" rule in the grammar (see the "factor" rule) to be syntactically different depending on whether I'm parsing it coming from "statement1" or "statement2".

Does ANTLR have a simple way of expressing this, without having two separate copies of the rules that are exactly the same except for the definition of "literal" at the end? I've tried digging around in the docs but haven't really found anything that seems to work.

It is almost like you are doing something context sensitive. Yes, you are going to have to duplicate the rules (I think) but you might be able to hack it with a composite grammar

So you import it twice (well you can't do this but you can make a copy of it and import it) and override different rules when you do

tef
May 30, 2004

-> some l-system crap ->

Flobbster posted:

Anyone here a pro with ANTLR?

To be honest, you might get as far knocking up the parser yourself recursive decent style (it is pretty much what antlr does) if you've got a non LL(*) grammar (which it sounds like you have, but you can transform it into one)

So far you will have had to remove left factors and left recursion (and then add that back in post-hoc for left associative operators), and now you're going to have to translate it again to get it to work in your toolkit. Although it is pretty inevitable to mutate the rules some.

Another thing to look at is PEG style parsing toolkits or combinator parsing libraries, as it should be easier to compose the grammar fragments by creating functions that return new rules.


(Although if you're a little mad, I'd recommend writing a left-corner recursive descent parser (essentially, you build up the tree from the left-most token, and then predict down). so you'd parse [1 + 2] by recognizing 1 as an expression, and then predicting + expr to follow an expression. aaanyway.....)

Vanadium
Jan 8, 2005

Aluminum Record posted:

It works perfectly fine.

Generally you post the code that does not.

Waltzing Along
Jun 14, 2008

There's only one
Human race
Many faces
Everybody belongs here
I figured it out. Thanks!

Waltzing Along fucked around with this message at 02:22 on Oct 26, 2010

Adbot
ADBOT LOVES YOU

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

Waltzing Along posted:

Edit: I changed the const in the loop to the actual #s and it works perfectly. So that is what the problem was. I've messed up my const statements and have no idea what I did wrong.
ints don't hold decimals, they automatically are truncated to, well, integers. So your statements are compiled as:
code:
const int BIRTH_RATE = 1;
const int DEATH_RATE = 0;
Use floating point numbers if you want to store decimals.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply