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
Sebbe
Feb 29, 2004

Ceros_X posted:

I'm working in Excel and trying get some cell formats to display what I want them to...

OK, basically, I am trying to get the cell to evaluate the contents of the cell and then display the number and one of three suffixes depending on the decimal place.

IE, 1 would be displayed as "1 GP"
.1 would be displayed as "1 SP"
.01 would be displayed as "1 CP"

(...)

I've looked around the web and messed with conditional formatting (which seems to be geared only to color coding). Any help?

I've got 3 alternatives:


The first one (shown in column C/D) has the following code:
C1: =IF(MOD(A1,0.1)>0,100*A1,IF(MOD(A1,1)>0,10*A1,A1))
D1: =IF(MOD(A1,0.1)>0,"CP",IF(MOD(A1,1)>0,"SP","GP"))

The second one (column F) has:
F1: =IF(MOD(A1,0.1)>0,CONCATENATE(100*A1," CP"),IF(MOD(A1,1)>0,CONCATENATE(10*A1," SP"),CONCATENATE(A1," GP"))

The third one (column H) has:
H1: =FormatCoins(100*A1)

For this last one, I've defined a small VBA helper to avoid a big messy formula:
code:
' Formats an amount of CP neatly as xx GP yy SP zz CP.
' Example: 1234 would end up as "12 GP 3 SP 4 CP",
'          while 1001 would end up as "10 GP 1 CP"
Function FormatCoins(cpValue As Integer) As String
    Dim output As String
    Dim cp, sp, gp As Integer
    
    output = ""
    
    cp = cpValue Mod 10
    sp = (cpValue Mod 100) \ 10
    gp = cpValue \ 100
    
    If cp > 0 Then
        output = cp & " CP " & output
    End If
    
    If sp > 0 Then
        output = sp & " SP " & output
    End If
    
    If gp > 0 Or output = "" Then
        output = gp & " GP " & output
    End If
    
    ' We will have leftover spaces, so it's easier to trim them here than
    ' to take care of them earlier.
    FormatCoins = Trim(output)
End Function
If you don't have any experience with using VBA in Excel, just follow this guide for how to add functions.

Sebbe fucked around with this message at 01:16 on Apr 30, 2010

Adbot
ADBOT LOVES YOU

Sebbe
Feb 29, 2004

Imagine that, quote != edit.

Anyway, for further Excel questions, there's the Small Excel Question Not Worth Its Own Thread thread. :)

Ceros_X
Aug 6, 2006

U.S. Marine
Thanks!

I checked the first post of this thread for an Excel thread, but it's not in the OP - maybe someone could add it?

Also, the formulas are nice, but I was trying to do it with the cell formating options. This will work, it's just for some dumb rear end mundane gear calculator (although I may wind up submitting it to HeroForge so I didn't want the sheet to be ghetto).

I'll probably just add the values and then hide the column and use your solution (the one from column F) for the price display and the one with the VBA solution for the grand total.

Thanks a lot!

(I'll PM you a link to the finished product if you want).

Jose Cuervo
Aug 25, 2004
I have the following problem, and I do not know how to logically approach it:
I have N different time intervals of the form [a,b] (e.g. the time interval [5,9] consists of the times 5, 6, 7, 8, and 9). The problem is to determine the intersection of these N time intervals, where some will overlap, and some will not.
For example, if I have [19,23], [3,7], [5,19], and [44,48], the resulting intersection I want is [3,23], [44,48].

Right now I am able to take all the start and end points of each time interval and sort them in ascending order [3, 5, 7, 19, 19, 23, 44, 48] and have an accompanying vector [s, s, e, s, e, e, s, e] of which point is a start or end.

I am lost as to how to use this information to come up with the resulting intersection, and I am open to new strategies. Any ideas?

litghost
May 26, 2004
Builder

Jose Cuervo posted:

I have the following problem, and I do not know how to logically approach it:
I have N different time intervals of the form [a,b] (e.g. the time interval [5,9] consists of the times 5, 6, 7, 8, and 9). The problem is to determine the intersection of these N time intervals, where some will overlap, and some will not.
For example, if I have [19,23], [3,7], [5,19], and [44,48], the resulting intersection I want is [3,23], [44,48].

Right now I am able to take all the start and end points of each time interval and sort them in ascending order [3, 5, 7, 19, 19, 23, 44, 48] and have an accompanying vector [s, s, e, s, e, e, s, e] of which point is a start or end.

I am lost as to how to use this information to come up with the resulting intersection, and I am open to new strategies. Any ideas?

Conceptually all you need to do is merge all the ranges that overlap. When no ranges overlap each other, the remaining ranges are the answer.

floWenoL
Oct 23, 2002

Jose Cuervo posted:

I have the following problem, and I do not know how to logically approach it:
I have N different time intervals of the form [a,b] (e.g. the time interval [5,9] consists of the times 5, 6, 7, 8, and 9). The problem is to determine the intersection of these N time intervals, where some will overlap, and some will not.
For example, if I have [19,23], [3,7], [5,19], and [44,48], the resulting intersection I want is [3,23], [44,48].

Right now I am able to take all the start and end points of each time interval and sort them in ascending order [3, 5, 7, 19, 19, 23, 44, 48] and have an accompanying vector [s, s, e, s, e, e, s, e] of which point is a start or end.

I am lost as to how to use this information to come up with the resulting intersection, and I am open to new strategies. Any ideas?

Don't you mean union?

shrughes
Oct 11, 2008

(call/cc call/cc)

Jose Cuervo posted:

I have the following problem, and I do not know how to logically approach it:
I have N different time intervals of the form [a,b] (e.g. the time interval [5,9] consists of the times 5, 6, 7, 8, and 9). The problem is to determine the intersection of these N time intervals, where some will overlap, and some will not.
For example, if I have [19,23], [3,7], [5,19], and [44,48], the resulting intersection I want is [3,23], [44,48].

You're talking about the union.

Jose Cuervo posted:

Right now I am able to take all the start and end points of each time interval and sort them in ascending order [3, 5, 7, 19, 19, 23, 44, 48] and have an accompanying vector [s, s, e, s, e, e, s, e] of which point is a start or end.

You're real close. Now you need to walk through the s/e array, left to right, and keep "score", where the score is the number of opening braces minus the number of closing braces. The score starts at zero. Whenever the score increases from zero to one, "output" an open brace and the number at the current index. Whenever the score decreases from one to zero, "output" the number at the current index and a closing brace. Then clump adjacent intervals that end and then start on the same number, like you have with 19. That's more work than necessary

An alternate implementation: Sort by the lower bound, and then pop two intervals and push one interval, occasionally outputting when you have a complete interval.

code:
unionIntervals :: [(Int, Int)] -> [(Int, Int)]
unionIntervals [] = []
unionIntervals xs = go (sortBy (compare `on` fst) xs)
    where go :: [(Int, Int)] -> [(Int, Int)]
          go [x] = [x]
          go ((x1,x2):(y1,y2):xs)
              | x2 < y1   = (x1,x2) : go ((y1,y2):xs)
              | otherwise = go ((x1, max x2 y2):xs)

Jose Cuervo
Aug 25, 2004

shrughes posted:

You're talking about the union.


You're real close. Now you need to walk through the s/e array, left to right, and keep "score", where the score is the number of opening braces minus the number of closing braces. The score starts at zero. Whenever the score increases from zero to one, "output" an open brace and the number at the current index. Whenever the score decreases from one to zero, "output" the number at the current index and a closing brace. Then clump adjacent intervals that end and then start on the same number, like you have with 19. That's more work than necessary

An alternate implementation: Sort by the lower bound, and then pop two intervals and push one interval, occasionally outputting when you have a complete interval.

code:
unionIntervals :: [(Int, Int)] -> [(Int, Int)]
unionIntervals [] = []
unionIntervals xs = go (sortBy (compare `on` fst) xs)
    where go :: [(Int, Int)] -> [(Int, Int)]
          go [x] = [x]
          go ((x1,x2):(y1,y2):xs)
              | x2 < y1   = (x1,x2) : go ((y1,y2):xs)
              | otherwise = go ((x1, max x2 y2):xs)

Doh! Of course I meant union. I do not understand the code you wrote, but I will try and implement the 'score' keepeing procedure you outlined, and see how I fare.

EDIT:
I am working in C++, and I implemented what I think you meant. It seems to work for the examples I have tried on it, but I am at a loss to explain why this method of keeping score works. DO you have any explanation, or a link to an explanation of why this works?

Jose Cuervo fucked around with this message at 05:59 on Apr 27, 2010

shrughes
Oct 11, 2008

(call/cc call/cc)

Jose Cuervo posted:

EDIT:
I am working in C++, and I implemented what I think you meant. It seems to work for the examples I have tried on it, but I am at a loss to explain why this method of keeping score works. DO you have any explanation, or a link to an explanation of why this works?

Imagine yourself walking along the number line, from left to right. Every time you enter one of the intervals, you add 1. Every time you leave one, you subtract 1. Scaevolus is gay.

The score tells how many overlapping intervals you're in. So as long as it's nonzero, you're inside one of the intervals.

shrughes fucked around with this message at 09:20 on Apr 27, 2010

Jose Cuervo
Aug 25, 2004

shrughes posted:

Imagine yourself walking along the number line, from left to right. Every time you enter one of the intervals, you add 1. Every time you leave one, you subtract 1. Scaevolus is gay.

The score tells how many overlapping intervals you're in. So as long as it's nonzero, you're inside one of the intervals.

Gotcha. Thanks so much.

fankey
Aug 31, 2001

chocojosh posted:

Not exactly. We use DependencyProjects for our UserControls, but I haven't fully wrapped my head around the details and haven't even really looked into Attached Properties. WPF is huge and it feels like every month for the past six I've been learning new parts of it.
If you have time, look into Attached DependencyProperties. They are made specifically for what it sounds like you are talking about and have the added plus of being able to access them easily from XAML without and code what-so-ever. If you want a quick rundown on how to use them post something in the .NET thread and I'll whip up a quick example.

Popete
Oct 6, 2009

This will make sure you don't suggest to the KDz
That he should grow greens instead of crushing on MCs

Grimey Drawer
I'm having trouble figuring out a way to find how many digits are in an integer. I need to write a program that adds up the individual digits in a integer, but the only thing I cannot find out is how to get that number of digits for my algorithm. This is in assembly language also, but that shouldn't make a difference.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Popete posted:

I'm having trouble figuring out a way to find how many digits are in an integer. I need to write a program that adds up the individual digits in a integer, but the only thing I cannot find out is how to get that number of digits for my algorithm. This is in assembly language also, but that shouldn't make a difference.

ceil(log10(n+1)) is the number of digits to the left of the decimal in a positive number n, but the naive algorithm for adding the digits in a number should not need to know how many digits it has.

Popete
Oct 6, 2009

This will make sure you don't suggest to the KDz
That he should grow greens instead of crushing on MCs

Grimey Drawer
Right I have that formula 10^(n-1) but the n part is the problem. n is the number of digits in the integer. I don't know of a way to find n, are you saying there is a way to add up the digits without knowing this?

mr_jim
Oct 30, 2006

OUT OF THE DARK

Popete posted:

Right I have that formula 10^(n-1) but the n part is the problem. n is the number of digits in the integer. I don't know of a way to find n, are you saying there is a way to add up the digits without knowing this?

The formula ShoulderDaemon posted gives you the number of digits, not their sum.

To sum the digits without calculating how many there are:
code:
n = 123456789
sum = 0
while (n > 0)
  sum = sum + (n % 10)
  n = n / 10
end
Basically you keep dividing by ten and adding the remainders together.

Popete
Oct 6, 2009

This will make sure you don't suggest to the KDz
That he should grow greens instead of crushing on MCs

Grimey Drawer
Alright thanks, you're right that is much simpler then I was trying to make.

Long Wang
Aug 28, 2006

I'm looking to automate some repetitive stuff I need to do on some bespoke software at work (pressing buttons, filling in text boxes, etc.) I'm not allowed to install software but is there any functionality within Visual Basic that comes with Office that would allow me to do this?

Edit: Looks like VBA can interact with other applications by simulating keystrokes, mouse clicks, etc.

Long Wang fucked around with this message at 18:43 on Apr 28, 2010

Jose Cuervo
Aug 25, 2004
I have written a small program in C++ using Microsoft Visual Studio. The inputs to the program are 4 different integers (number of machines, number of machine groups, number of workers, number of jobs). I want to run the program with 2000 different combinations of these inputs on another computer that does not have Visual Studio. I have heard that I can compile my program into an exe file (?), and then pass each combination of inputs to it using a batch file, but I cannot find any help as to how to do this.

Can anyone give me some help/advice on how to do this, or point me to some resources that would help me with this issue?

yatagan
Aug 31, 2009

by Ozma

Jose Cuervo posted:

I have written a small program in C++ using Microsoft Visual Studio. The inputs to the program are 4 different integers (number of machines, number of machine groups, number of workers, number of jobs). I want to run the program with 2000 different combinations of these inputs on another computer that does not have Visual Studio. I have heard that I can compile my program into an exe file (?), and then pass each combination of inputs to it using a batch file, but I cannot find any help as to how to do this.

Can anyone give me some help/advice on how to do this, or point me to some resources that would help me with this issue?

Yes, you will need to compile your program into an executable (there are other options but don't worry about those). Google "visual studio how to make exe" or whatever.

Now then, if the idea is to run 2000 different random combinations, the easiest solution may be to code in your C++ program a loop that randomizes the variables and runs your program 2000 times.

Failing that, instead of using a batch file I would have your program read in a file with the inputs you want to use. So a line of your program would have four comma separated values that you would read in, parse, and run.

csammis
Aug 26, 2003

Mental Institution

Ceros_X posted:

I checked the first post of this thread for an Excel thread, but it's not in the OP - maybe someone could add it?

It is in the OP :ssh:

Ceros_X
Aug 6, 2006

U.S. Marine

csammis posted:

It is in the OP :ssh:

My reading are failz :smith:

Chumpington
Jan 17, 2010

by Ozma
(ignore this post...moving to SQL thread)

Chumpington fucked around with this message at 09:59 on Apr 29, 2010

nesbit37
Dec 12, 2003
Emperor of Rome
(500 BC - 500 AD)
I have a minor problem that I am trying to solve as quickly as possible. I am in the process of importing a legacy access database into a mySQL database via the program that uses the mySQL database (Archivists' Toolkit). Everything is ready to go, except for one little hiccup. I have an xsd file that is supposed to parse one field into its sub categories, but for some reason it is not doing that. Rather than troubleshoot this file I think it will be faster to just fix it in either Access or Oxygen.

The character that denotes parsing is the period.

Right now, in xml, the field is displayed in one of the following combinations (just for example, the characters are arbitrary for the example):

<accessionNumber>Need.DOG.accssn007.345</accessionNumber>
<accessionNumber>Need.DOG.accssn007</accessionNumber>
<accessionNumber>Need.DOG</accessionNumber>
<accessionNumber>Need</accessionNumber>

They need to show up, in xml, as:

<accessionNumber><part1>Need</part1><part2>DOG</part2><part3>accssn007</part3><part4>345</part4></accessionNumber>

There are, at maximum, 4 parts. Most are only 2 parts.

etc.

Is there a way I can use the find replace function in Oxygen to do this while keeping all the information between the periods and the <accessionNumber></accessionNumber> tags?

If not, can I do this in Access 2007 via either find/replace or a query to the accessionNumber field?

Worse comes to worse I can do it by hand, but would rather not do so for 1600 records if possible. Thanks in advance!

Taz
Feb 21, 2006
woob woob
I am trying to perform some substring manipulation in bourne shell script and it just is not working for me. Basically I have a string $a from which I wish to remove the contents of string $b and place the result into string $c. I've tried various different ways such as tr (won't treat a string as a string, insists on removing all the characters within it) and sed (just doesn't work, hangs the program for some reason, using format "sed 's#$a#b#g' as suggested somewhere or other.)

It's distinctly possible i've just been staring at this for too long and am missing an obvious solution but it's starting to get quite annoying. Any help would be greatly appreciated.

opie
Nov 28, 2000
Check out my TFLC Excuse Log!
This is probably a stupid question, but I'm sick and my brain won't work.

I'm very new to msbuild, and I'm trying to get it to work with these solutions under team foundation. It seems to be overriding the outdir defined in each project. How can I get it to not do that? We seem to be using the default settings in Microsoft.TeamFoundation.Build.targets, and I see a bunch of settings for outdir and publishdir. I don't know what I need to set to get it to just use the settings in the vcproj files.

The problem seems to be that it's creating exp files somewhere, but not using them in dependent projects and instead finding some outdated files. Now that I think about it if it's overriding the outdir folder, everything should be going to the same place so that shouldn't be the problem. In any case, this totally screwed up the manual build that the other techs are used to anyway, so my coworker's changes won't fly.

I don't have access to the build machine right now, so I'm stuck there. I should probably set up the build to run on my own machine, but I'm not sure how to do that within TFS. Plus I am critically low on hard drive space. Anyway, if someone out there knows much about msbuild, I'd appreciate some help.

The1ManMoshPit
Apr 17, 2005

Taz posted:

I am trying to perform some substring manipulation in bourne shell script and it just is not working for me. Basically I have a string $a from which I wish to remove the contents of string $b and place the result into string $c. I've tried various different ways such as tr (won't treat a string as a string, insists on removing all the characters within it) and sed (just doesn't work, hangs the program for some reason, using format "sed 's#$a#b#g' as suggested somewhere or other.)

It's distinctly possible i've just been staring at this for too long and am missing an obvious solution but it's starting to get quite annoying. Any help would be greatly appreciated.

In Bash you can do c=${a//$b/}, not sure if that works in plain old Bourne shell. If you want to use sed you cannot use single quotes around the command, because variable substitution does not happen within single quotes, so you might want to try sed "s#$a#$b#g", but if either of your variables contains the separator character you choose (in your case, "#") then the sed command won't work either.

Taz
Feb 21, 2006
woob woob

The1ManMoshPit posted:

In Bash you can do c=${a//$b/}, not sure if that works in plain old Bourne shell. If you want to use sed you cannot use single quotes around the command, because variable substitution does not happen within single quotes, so you might want to try sed "s#$a#$b#g", but if either of your variables contains the separator character you choose (in your case, "#") then the sed command won't work either.

I'm getting "Bad substitution" for the first one and the sed command just hangs like it did before. I suspect that something else is going on to make sed do that but I can't for the life of me work out what it is. I purposefully chose # as the delimiter by the way, as my variables are paths and contain the "/" so commonly used.

The1ManMoshPit
Apr 17, 2005

I guess it's possible that style of substitution (the first double-slash means replace all occurences) doesn't work in Bourne.

Wait, for your sed command are you just running sed as its own thing? sed expects input on STDIN, so you need to actually do c=`echo $a | sed "s#$b##g"`. I also noticed an error in your sed command that I didn't catch before (you were replacing all $a's with $b's, not replacing $b's with nothing).

ToxicFrog
Apr 26, 2008


Taz posted:

I'm getting "Bad substitution" for the first one and the sed command just hangs like it did before. I suspect that something else is going on to make sed do that but I can't for the life of me work out what it is. I purposefully chose # as the delimiter by the way, as my variables are paths and contain the "/" so commonly used.

Sed, by default, reads from stdin and writes to stdout. The "hanging" is likely just it waiting for you to provide input.

As I understand it, you want to strip all $b from $a and store results in $c? That is to say, if a="foo bar baz" and b=" b", c should be "fooaraz"?

Try:
code:
c=`echo "$a" | sed "s#$b##g"`
E: beaten like a pinata full of Perl developers.

ToxicFrog fucked around with this message at 18:23 on Apr 29, 2010

Taz
Feb 21, 2006
woob woob
:doh:

I suspect the case is true that I was staring at it for too long. That makes total sense now.

Thanks both of you.

Beary Mancrush
Jun 9, 2002


Boring damned people. All over the earth. Propagating more boring damned people. What a horror show. The earth swarmed with them.
I have a stupid newbie type question. I've got a plain text file that has a list of people going on a trip. I'd like to create a form on our intranet page that removes the line containing a name that the user submits. For instance, if the text file looks like:
code:
Bob Jones#Funtimes#Schnoopy#Blargh
Cynthia Jones#Funtimes#Schnoopy#Blargh
Peter Pumpkin Eater#Funtimes#Schnoopy#Blargh
Gerald Ford#Funtimes#Schnoopy#Blargh
and a user types Bob Jones's name into the form, I want the entire line containing Bob Jones to be removed from the text file and any blank lines removed.

I can do this either in asp with vbscript or in perl. Somebody please help me. I'm a computer janitor. I just fix stuff. I think I could write the form, but the scripting is beyond me.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

ToxicFrog posted:

E: beaten like a pinata full of Perl developers.

Oh well you can just suck the fattest part of Randal Schwartz's rear end in a top hat!






;3

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Beary Mancrush posted:

I have a stupid newbie type question. I've got a plain text file that has a list of people going on a trip. I'd like to create a form on our intranet page that removes the line containing a name that the user submits.

In Perl, untested:

code:
#!/usr/bin/perl

use strict;
use warnings;

use CGI::Simple qw( );
use Errno qw( EEXIST );
use Fcntl qw( O_CREAT O_EXCL O_WRONLY );

my $q = CGI::Simple->new( );

my %remove = ( );

foreach my $name ( $q->param( "name" ) ) {
  $remove{$name} = 1;
};

while ( not sysopen( NEW, "/path/to/data.csv.tmp", O_CREAT | O_EXCL | O_WRONLY, 0600 ) ) {
  if ( not $!{EEXIST} ) {
    die "Unable to create data.csv.tmp: $!";
  };
  warn "Sleeping to acquire exclusive control of temporary file.\n";
  sleep( 1 );
};

if ( not open( OLD, "<", "/path/to/data.csv" ) ) {
  close( NEW );
  unlink( "/path/to/data.csv.tmp" );
  die "Unable to open data.csv: $!";
};

while ( defined ( my $line = <OLD> ) ) {
  my ( $name ) = $line =~ m/^([^#]+)#/;
  if ( defined $name and not exists $remove{$name} ) {
    print NEW $line;
  };
};

close( OLD );
close( NEW );

if ( not rename( "/path/to/data.csv.tmp", "/path/to/data.csv" ) ) {
  unlink( "/path/to/data.csv.tmp" );
  die "Unable to move data.csv.tmp on top of data.csv: $!";
};

print <<END;
Status: 303 See Other
Location: /updatesuccessful.html
Content-type: text/plain

Your change has been committed.
END
This script should be saved as a .cgi on a server configured to run CGIs and with perl and CGI::Simple installed.

It accepts form input with any number of fields named "name", ideally via POST. It will ensure no other instance is trying to change the data file, then filter out all lines matching any of the names provided. It is case-sensitive and whitespace-sensitive.

When it's done, it will replace the old data with the filtered data, and redirect the user to /updatesuccessful.html on the same host.

Edit: Made the script marginally less likely to break.

ShoulderDaemon fucked around with this message at 22:03 on Apr 29, 2010

Pantsmaster Bill
May 7, 2007

Anybody clever with Haskell?

I've made myself a calculator for an assignment, but I've just realised something I missed.

It's an RPN calculator, but for whatever reason they want it to be able to display in infix form, specifically using show. My problem is, I can't seem to figure out how to use/overload show for a list.

code:
data Expr = Plus | Times | Divide | Minus | Num Rational | Power | Sqrt
These are the expressions I need to show, and I know how I would be able to convert easily from RPN to infix. I can't make a show instance for a list of Expr though.

Any ideas?

shrughes
Oct 11, 2008

(call/cc call/cc)
That's not what Show is for. The Show typeclass isn't for making pretty or distorted views of what a value looks like. It seems the general rule is that it should return an expression that when evaluated would produce a value indistinguishable from the one you're showing.

Anyway, you can't have what you want. You'll need to make an explicit [Expr] -> String function or wrap your list of Exprs in a new datatype.

Pantsmaster Bill
May 7, 2007

Thanks for confirming that, I realise that it's not for doing that kinda thing and that I could write my own function for it, but for some reason they want me to use show.

I guess I should wrap them, but then I'll have to rewrite the whole rest of the program. Time to talk to my lecturer I think.

shrughes
Oct 11, 2008

(call/cc call/cc)

Pantsmaster Bill posted:

I guess I should wrap them, but then I'll have to rewrite the whole rest of the program.

Not the whole program!

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

shrughes posted:

Anyway, you can't have what you want. You'll need to make an explicit [Expr] -> String function or wrap your list of Exprs in a new datatype.

Apparently someone forgot how Show String is implemented.

code:
instance Show Expr where
  showList lst = ....
That said, as a point of code design, I wouldn't suggest using Show for this, and not because Right-Thinking people think it should be an inverse parser. Show should format data the obvious way. There is an obvious way to format an integer. There is a fairly obvious way to format a string. There isn't really an obvious way to format a list of expressions; if anything, for an RPN calculator the most obvious choice would be RPN, and that's not what the assignment wants.

That said, if the professor wants show [Num 4, Num 3, Plus] to print 4 + 3, you should do it and not raise pedantic points about code design.

shrughes
Oct 11, 2008

(call/cc call/cc)

rjmccall posted:

Apparently someone forgot how Show String is implemented.

Agh, gently caress you! I suck.

Adbot
ADBOT LOVES YOU

Pantsmaster Bill
May 7, 2007

rjmccall posted:

Apparently someone forgot how Show String is implemented.

code:
instance Show Expr where
  showList lst = ....
That said, as a point of code design, I wouldn't suggest using Show for this, and not because Right-Thinking people think it should be an inverse parser. Show should format data the obvious way. There is an obvious way to format an integer. There is a fairly obvious way to format a string. There isn't really an obvious way to format a list of expressions; if anything, for an RPN calculator the most obvious choice would be RPN, and that's not what the assignment wants.

That said, if the professor wants show [Num 4, Num 3, Plus] to print 4 + 3, you should do it and not raise pedantic points about code design.

Awesome cheers, I'll look into that! He wants everything in bracketed infix form, with numbers displayed as doubles (what the christ).

More questions possibly later!

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