Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Once upon a time, I was taking an experimental high energy physics lab and we spent most of the semester assembling various configurations of equipment to perform various experiments. In the last few labs, the experiments got significantly more complicated and the instructor brought out a single piece of equipment that not only replaced every configuration of equipment we had assembled over the whole course but automated the data collection.

Ah yes, the Infinite Improbability Drive. I have often found it useful to be able to deploy the precursor technology, and make a piping hot cup of tea.
 
Yes, and I am thankful for the help. I think for fun I am going to try to turn in each assignment in both Pascal and C.
Code:
Pascal
program carpet(input,output);

const
	width = 15;
	length = 12;
	price = 17;

var
	areaInFeet, areaInYards, cost: integer;

BEGIN

	areaInFeet := width * length;
	areaInYards := areaInFeet DIV 9;
	cost := price * AreaInYards;
	writeln('Cost is ',cost );

END.

C Code 

#include <stdio.h>

int main (int argc, const char * argv[]) {

	int width, length, price, areaInFeet, areaInYards, cost;
	
	width = 15;
	length = 12;
	price = 17;
	
	areaInFeet = width * length;
	areaInYards = areaInFeet / 9;
	cost = price * areaInYards;
	printf("Cost is: %i", cost);
		
    return 0;
}

My friend is staying with the class which means I will stay with it too. If I don't stay with the class then I can't pre register next semester for C or the iPhone programing class. They don't offer an Objective-C course, just c++ and iPhone. I think by that time I will have a pretty good handle on C.

-Lars
 
Pascal! I used to rock at Pascal. You should check out Ada once you're more advanced with Pascal.
 
pascal was my third high-level language (after BASIC and APL). I've probably forgotten most of it by now - although the mnemonic "cats tails vary profusely" rings a bell as how to remember the order of declarations (const, type, var, proc)

One of the assignments was to parse the text of a Shakespeare play (in standard format), and then generate parts for each actor (listing their part only, apart from cues). I think I've probably still got the listing of my effort ;)
 
Yes, and I am thankful for the help. I think for fun I am going to try to turn in each assignment in both Pascal and C.
Code:
Pascal
program carpet(input,output);

const
	width = 15;
	length = 12;
	price = 17;

var
	areaInFeet, areaInYards, cost: integer;

BEGIN

	areaInFeet := width * length;
	areaInYards := areaInFeet DIV 9;
	cost := price * AreaInYards;
	writeln('Cost is ',cost );

END.

C Code 

#include <stdio.h>

int main (int argc, const char * argv[]) {

	int width, length, price, areaInFeet, areaInYards, cost;
	
	width = 15;
	length = 12;
	price = 17;
	
	areaInFeet = width * length;
	areaInYards = areaInFeet / 9;
	cost = price * areaInYards;
	printf("Cost is: %i", cost);
		
    return 0;
}

My friend is staying with the class which means I will stay with it too. If I don't stay with the class then I can't pre register next semester for C or the iPhone programing class. They don't offer an Objective-C course, just c++ and iPhone. I think by that time I will have a pretty good handle on C.

-Lars
Remember, Lars, Pascal is case-insensitive. So "areaInFeet," "AreaInFeet," "areainfeet," and "AREAINFEET" stand for the same variable. That's why it's good to use underscores in your variable names, e.g., "Area_In_Feet." Sometimes case insensitivity can promote bugs when he forget that Pascal is case-insensitive. I just can't think of an example of a that sort of bug yet.

Oh, by the way, in many, probably most, Pascal dialects, "length" stands for a built-in function that counts a string's characters. Many Pascal compilers will still let you declare a variable, or a constant, named "length." But don't be surprised if your computer complains when you do that.
 
Last edited:
Pascal was the second programming language that I learned.

Has anyone played with the Lazarus IDE for FreePascal on OS X lately? It used to be quite broken a couple of years ago, and I haven't looked at it anymore. The whole thing is written in FreePascal, though, and is very similar to Delphi.
 
Bill McEnaney - that is what the instructor said to that it is case insensitive. Like I mentioned I am forced to take this Pascal class so I can get the other classes so I would like to keep using as much of what I have learned in C like 'areaInFeet' instead of Area_in_feet as an example.

The Turbo Pascal book is so wordy and draw out it's painful to read it weighs 3.8 pounds and is like 700 pages.

The code that I listed brings up a question. The Const I declare in Pascal seems to my like they are Variables (Vars)? In C I would write 'int width;' then next line I would write 'width = 15;'. In the Pascal code 'WIDTH = 15;' and I understand that Const comes before Vars but I would expect to see the declaration of WIDTH in the VARS area. How can 15 be stored in WIDTH unless a CONST reserves space in memory like Vars do? I have not come across this in my C book yet.

Thanks!

-Lars
 
The code that I listed brings up a question. The Const I declare in Pascal seems to my like they are Variables (Vars)? In C I would write 'int width;' then next line I would write 'width = 15;'. In the Pascal code 'WIDTH = 15;' and I understand that Const comes before Vars but I would expect to see the declaration of WIDTH in the VARS area. How can 15 be stored in WIDTH unless a CONST reserves space in memory like Vars do? I have not come across this in my C book yet.

Thanks!

-Lars

They're like variables, but CONSTANT. You can't change them. If you declared them without assigning a value, you'd never be able to assign one. Yes, they'll reserve memory, like a variable and that memory will be filled with the value declared until your program ends.

A closer equivalent in your C program would be

const int width = 15;
const int length = 12;
const int price = 17;
 
Cool... I have seen that in the C book but I have not come across that yet. By default C knows that when I write 'int i = 15;' it knows that it is a Var and I have to declare it 'Const Int' to be a Constant. Gotcha!

-Lars
 
Bill McEnaney - that is what the instructor said to that it is case insensitive. Like I mentioned I am forced to take this Pascal class so I can get the other classes so I would like to keep using as much of what I have learned in C like 'areaInFeet' instead of Area_in_feet as an example.
Feel free to use your naming conventions, Lars. I just wanted to remind everybody that case-insensitivity can cause problems, especially when a compiler tells the computer to shorten slightly-different variable names.

The code that I listed brings up a question. The Const I declare in Pascal seems to my like they are Variables (Vars)? In C I would write 'int width;' then next line I would write 'width = 15;'. In the Pascal code 'WIDTH = 15;' and I understand that Const comes before Vars but I would expect to see the declaration of WIDTH in the VARS area. How can 15 be stored in WIDTH unless a CONST reserves space in memory like Vars do? I have not come across this in my C book yet.
I think that the computer probably replaces each instance of a constant name with the corresponding constant. Since constants stay the same, we don't need to declare them as variables. So the computer can discover a constant's data type at or before compile time.

Each constant needs to live in some memory location or other. Unfortunately, constants can occupy more memory than a variable does. Say Capacity is a variable. Then, the computer can look into that that variable's memory location each time it needs to access that variable's value. But what may happen if "Capacity" names a constant, the integer, 10,000, say? If that constant name appears 10,000 times in your Pascal program, that integer will appear at least 10,000 times in the executable version of that program.
You're welcome.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.