Pollyanna's Goatee











{Sunday 6th September '09}   Programming Praxis V

The “Perch” is a roulette betting strategy based on ignorance of the “Gambler’s Fallacy”: the gambler perches in a position where they can monitor all roulette tables; when a roulette table has had a run of red or black for the past four spins, the gambler places the minimum £10 bet on the opposite colour, reasoning that a run of five of the same colour is unlikely (the “Gambler’s Fallacy”, as the probability of the fifth spin landing on a given colour is the same as the first spin landing on a given colour); if the bet fails and the run of the colour continues, the gambler reasons that the odds of six in a row are even more unlikely, and increases their original bet by 50%; if that bet too fails, the gambler returns to the perch; the strategy ends when the gambler has either achieved their target winnings, or has insufficient money to place the £10 minimum bet.

Anyway, this {source code & compiled:Mac OS pre-X} is my solution for the fifth Programming Praxis held by The Daily WTF: a program to play roulette using the “Perch” strategy, with a user-entered number of roulette tables, starting amount of money, and target amount of money; the program ends when it has either achieved the target amount of money or has insufficient money to place the minimum £10 bet.

The solution was developed on an Apple Power Macintosh 8100 in C compiled with Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition.)



{Monday 3rd August '09}   Programming Praxis I

Supposedly, Russian peasants perform multiplication in the following interesting fashion: they write the two numbers which are to be multiplied at the top of two columns; then, they multiply the number in the right column by two, and divide the number in the left column by two – throwing away any fractional part – continuing until the number in the left column is one; then, those numbers in the right column whose corresponding number in the left column is odd are added together to produce the result.

Anyway, this {source code|compiled:Mac OS pre-X} is my solution for the first Programming Praxis held by The Daily WTF.

The solution was developed on an Apple Power Macintosh 8100 in C compiled with Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition.)



{Monday 8th December '08}   UEL BSc (Hons) degree calculator

UEL BSc (Hons) degree calculator {source code & compiled:Mac OS pre-X} is, as should be ever-so-slightly obvious, a quick-and-dirty program for determining whether a set of module results meet the minimum requirements for being awarded a BSc (Hons) degree from the University of East London, and, if so, the grade of the degree and which module results were taken into consideration when determining the grade of the degree; UEL themselves express the calculation of such a degree grade as:

Where a student is eligible for an Honours degree, and has gained a minimum of 240 UEL credits at level 2 or 3 on the programme, including a minimum of 120 UEL credits at level 3, the award classification is determined by calculating:

The arithmetic mean of the best 100 credits at level 3
x 2/3 +
The arithmetic mean of the next best 100 credits at levels 2 and/or 3
x 1/3

and applying the mark obtained as a percentage, with all decimal points rounded up to the nearest whole number, to the following classification

70%-100% First Class Honours
60%-69% Second Class Honours, First Division
50%-59% Second Class Honours, Second Division
40%-49% Third Class Honours
0%-39% Not passed

(pages 100-101 of the School of Computing and Technology : UNDERGRADUATE COMPUTING BSc (HONS) COMPUTER GAMES : Student Handbook 2004-2005.)

I hadn’t passed enough modules to be awarded any degree on withdrawing from the course, but if I had continued on the course I could have still achieved a 1st. UEL wasn’t my first choice of uni – it wasn’t even on my list of choices of uni, and I only applied as I was very bored late in the year and UEL offered courses beginning early the following year – and I withdrew from the course as I grew weary of jumping through what I saw as arbitrary hoops, such as being unable to take SD2071 [games programming in Java] because I hadn’t passed SD1071 [introduction to design methods in Flash] … even though I had walked out of SD1042 [introduction to programming in Java] with, I was told, the highest mark in the year.

Anyway, to use UEL BSc (Hons) degree calculator, just propagate the file degree_calculator.hll – the file format should be pretty much self-explanatory – with your module details, and run UEL degree calculator.app; whether you have passed enough modules to be awarded a BSc (Hons) degree will be displayed, and if you have, the modules that count towards the degree will also be displayed. My degree_calculator.hll file looks like…

.mark="80"
.level="1"
.credits="20"
.title="Introduction to computer systems"
.code="CN1044"

.mark="67"
.level="1"
.credits="20"
.title="Introduction to computer games theory and design"
.code="MS1303"

.mark="40"
.level="1"
.credits="20"
.title="Project management 1"
.code="IM1072"

.mark="59"
.level="1"
.credits="20"
.title="Digital graphics & visual culture"
.code="MS1301"

.mark="95"
.level="1"
.credits="20"
.title="Introduction to software development"
.code="SD1042"

.mark="40"
.level="1"
.credits="20"
.title="Introduction to design methods"
.code="SD1071"

.mark="62"
.level="2"
.credits="20"
.title="Multimedia hardware"
.code="IM2075"

…for the module results…

CN1044 Introduction to computer systems Coursework 1 – 62% (2:1) 80% (1st)
Coursework 2 – 100% (1st)
Exam – 79% (1st)
SD1042 Introduction to software development Coursework – 90% (1st) 95% (1st)
TCA – 100% (1st)
Exam – 95% (1st)
IM2075 Multimedia hardware Coursework 1 – 72% (1st) 62% (2:1)
Coursework 2 – 51% (2:2)
SD1071 Introduction to design methods Coursework – 45% (3rd) 40% (3rd)
IM1072 Project management 1 Coursework 1 – 51% (2:2) 40% (3rd)
Coursework 2 – 63% (2:1)
MS1303 Introduction to computer games theory and design Essay – 55% (2:2) 67% (2:1)
Project – 73% (1st)
MS1301 Digital graphics & visual culture Coursework 1 – 71% (1st) 59% (2:2)
Coursework 2 – 52% (2:2)

…and running UEL degree calculator.app displays…

***UEL BSc (Hons) degree calculator 0.1, © Mark Bishop 2007.
You do not meet the minimum requirements to be awarded a BSc (Hons) degree.

UEL BSc (Hons) degree calculator was developed on an Apple Power Macintosh 8100 in C++ using sealfin* compiled with Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition.)



{Tuesday 8th July '08}   Frye

I’m easily distracted.

I’m really easily distracted.

I’m able to spend hours staring into space, my mind occupied totally by the meanderings of my imagination.

Give me a machine with a web browser and I won’t return to the topic I’m supposed to be occupying my mind with for days

Which is why, when I started studying at UEL, I took my old Performa 460 out of storage to type up my assignments on.

But I found that old Mac’ to be a little too dull; I installed a few pieces of software to improve the aesthetics of the Mac’, but I also wanted software which could provide me with a few minutes of very limited distraction, like the word-of-the-day or this-day-in-history widgets I have on my iMac…

So, I developed Frye {source code|compiled:Mac OS pre-X}.

Frye is a quick-and-dirty-and-ugly program which shows a random quote at launch and allows for the user to add, edit, and delete quotes; instructions as to how to use Frye are given in the program itself; if you want Frye to show a random quote every time you start up your Mac’, put an alias to Frye in your System Folder:Startup Items: folder.

Frye was developed on an Apple Power Macintosh 8100 in C++ compiled with Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition.)


Ps. Most of the quotes with which Frye is distributed come from Faisal N. Jawdat’s quotes file.



{Sunday 24th January '99}   The Most Toys

I’ll be heading to college to take my A-Levels in the September of this year; hopefully this will lead to excellent grades and much barely-legal sex. More than likely this will lead to excellent predicted grades, abysmal actual grades, and being told I’m the most hideous creature ever to walk the world.

Again.

But in the interests of at least trying to achieve excellent grades, I’ve developed The Most Toys {source code & compiled:Mac OS pre-X} – a quick-and-dirty relational database recording games I’d like to play as well as related details, such as the magazines a game has been previewed or reviewed in – as practice in preparation for developing the coursework component of my A-Level in Computer Science; instructions as to how to use The Most Toys, as far as I believe they are required, are given in the application itself.

The Most Toys was developed on an Apple Power Macintosh 8100 in C++ compiled with Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition.)



{Wednesday 31st December '97}   METAL Help ‘Mogrifier

METAL is a freeware BASIC IDE by Marin Saric of Galactic Dreams Software, and is quite a capable development tool if you’re into lateral-thinking-to-overcome-the-limitations-of-the-language-development…

METAL comes with pretty good built-in hyper-linked help/documentation; unfortunately, pretty good isn’t perfect, and the built-in help has several flaws: it can’t be printed, it can’t be searched (not that the language is that big, but…), and it can’t be copied and pasted.

So, I’ve developed METAL Help ‘Mogrifier {source code|compiled:Mac OS pre-X} to help.

METAL Help ‘Mogrifier is a minimalist application to convert .MHLP files viewable with METAL’s built-in help browser to .HTML files viewable with any web-browser.

To use, just copy the file metal_help.mhlp from METAL’s folder into the same folder as METAL Help ‘Mogrifier, and run METAL Help ‘Mogrifier; metal_help.mhlp will be converted and output as METAL Help.html.

So far, METAL Help ‘Mogrifier has been tested only with the metal_help.mhlp file included with METAL 1.0ß; as updated versions of METAL are released, METAL Help ‘Mogrifier will be updated to cope with any changes to the .MHLP file format (unless of course METAL’s built-in help browser is updated to fix the flaws which prompted the development of METAL Help ‘Mogrifier…)

METAL Help ‘Mogrifier was developed on an Apple Power Macintosh 8100 in C++ compiled with Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition.)



{Sunday 28th December '97}   PIIIC_03

I suck at maths.

I really, really suck at maths.

Given my ambitions, that I really, really, really suck at maths is an ever-so-slight problem.

So, I’ve begun to develop quick-and-dirty-and-ugly programs to further my mathematical ability; PIIIC_03 {source code & compiled:Mac OS pre-X} is the latest of those programs, a – like PIIIC_02 – 3D model viewer; where PIIIC_03 differs from PIIIC_02 is that the 3D model may be rotated about any axis, not just the y axis.

Pressing the x, y, or z key will set the current axis; pressing the left and right arrow keys will rotate the 3D model about the current axis; pressing the up and down arrow keys will zoom the 3D model out and in; and the program may be quit by pressing the escape key.

PIIIC_03 was developed on an Apple Power Macintosh 8100 in (HEAVY) METAL BASIC compiled with my HEAVY METAL 1.0ß and Galactic Dreams Software’s METAL 1.0ß.



{Saturday 27th December '97}   PIIIC_02

I suck at maths.

I really, really suck at maths.

Given my ambitions, that I really, really, really suck at maths is an ever-so-slight problem.

So, I’ve begun to develop quick-and-dirty-and-ugly programs to further my mathematical ability; PIIIC_02 {source code & compiled:Mac OS pre-X} – a 3D model viewer – is the latest of those programs; the 3D model may be rotated about the y axis by pressing the left and right arrow keys and may be zoomed in and out by pressing the down and up arrow keys respectively; perspective may be turned on and off by pressing the 1 and 0 keys respectively; and the program may be quit by pressing the escape key.

PIIIC_02 was developed on an Apple Macintosh 8100 in (HEAVY) METAL BASIC compiled with my HEAVY METAL 1.0ß and Galactic Dreams Software’s METAL 1.0ß.



{Thursday 25th December '97}   HEAVY METAL

Contents

Intro

METAL is a freeware BASIC IDE by Marin Saric of Galactic Dreams Software, and is quite a capable development tool if you’re into lateral-thinking-to-overcome-the-limitations-of-the-language-development…

However, the language has a few limitations that I feel merely irritate rather than present an interesting challenge to overcome: no support for multiple files, no support for named constants, no requirement that variables be declared/no scoping of variables, no support for parameterised functions, …

So, I’ve developed HEAVY METAL {source code|compiled:Mac OS pre-X} to try to remedy some of those limitations.

HEAVY METAL is a pre-compiler: taking one HEAVY METAL-language file (which may reference other such files) as input, one METAL-language file is output; that output file can then be compiled using METAL.

HEAVY METAL introduces several instructions to try to remedy several of the aforementioned limitations of METAL, such as instructions for declaring and calling parameterised functions, but, as a pre-compiler, is limited in the features it can introduce to METAL; however, with a bit of lateral thinking, even features such as recursive parameterised functions and polymorphic parameterised functions (planned for a future update to HEAVY METAL) can be implemented – so, if you have a suggestion for an instruction or feature, I would be happy to receive it (with the caveat that instructions and features will be implemented in the order that they are useful to me…) Similarly, I would be happy to receive reports of any bugs not included in the list below.

Every instruction introduced by HEAVY METAL begins with a ‘@’ character, and ends with a ‘ ‘ character, eg. “@new_scope·variable;” and “@delete_scope·“.

Due to METAL‘s lack of in-depth language documentation, HEAVY METAL does not try to check for errors in the METAL-language files it produces.

To use HEAVY METAL, copy all of the HEAVY METAL-language files pertaining to your project into the same folder as HEAVY METAL; run HEAVY METAL, type in the name of your project’s primary HEAVY METAL-language file and press the Return key, and that file (and any file it references) will be ‘compiled’, producing a METAL-language file with the same name as that file, and the suffix .hmet.

So far, HEAVY METAL has been tested only with METAL 1.0ß; as updated versions of METAL are released, HEAVY METAL will be updated to cope with any changes to the language (unless of course METAL is updated to remedy those limitations which prompted the development of HEAVY METAL…)

Instructions

@include | Include file

@include <file>;

Inserts the contents of <file>, which undergo the same ‘compilation’ as any other file; @include instructions may be nested, viz., a file can include another file, which can include another file, …

The file @include (name).bas:

"Mark"

The file @include (greeting).bas:

@new_scope n_suffix$;

if £n = 1 then

£n_suffix$ = "st"

else

if £n = 2 then

£n_suffix$ = "nd"

end if

end if

print "Greetings, world! This is the "; £n; £n_suffix$; " time I've greeted you! My name is " + @include @include (name).bas; + "!"

@delete_scope

The file @include.bas:

@new_scope n;

£n = 1

@include @include (greeting).bas;

@++ £n;

@include @include (greeting).bas;

@delete_scope

The result of ‘compiling’ @include.bas:

xmwpiq_n = 1

if xmwpiq_n = 1 then

nsmopg_n_suffix$ = "st"

else

if xmwpiq_n = 2 then

nsmopg_n_suffix$ = "nd"

end if

end if

print "Greetings, world! This is the "; xmwpiq_n; nsmopg_n_suffix$; " time I've greeted you! My name is " + "Mark" + "!"

xmwpiq_n = ( xmwpiq_n + 1 )

if xmwpiq_n = 1 then

ctohvj_n_suffix$ = "st"

else

if xmwpiq_n = 2 then

ctohvj_n_suffix$ = "nd"

end if

end if

print "Greetings, world! This is the "; xmwpiq_n; ctohvj_n_suffix$; " time I've greeted you! My name is " + "Mark" + "!"

@FALSE | False constant

@FALSE

Inserts METAL‘s false constant, 0.

Mark_likes_seals = @FALSE

if Mark_likes_seals then

print "All is right with the world."

else

print "Something is very wrong with the world…"

end if

Result of ‘compilation’:

Mark_likes_seals = 0

if Mark_likes_seals then

print "All is right with the world."

else

print "Something is very wrong with the world…"

end if

@TRUE | True constant

@TRUE

Inserts METAL‘s true constant, -1.

Mark_likes_seals = @TRUE

if Mark_likes_seals then

print "All is right with the world."

else

print "Something is very wrong with the world…"

end if

Result of ‘compilation’:

Mark_likes_seals = -1

if Mark_likes_seals then

print "All is right with the world."

else

print "Something is very wrong with the world…"

end if

@B | Binary constant

@B <binary constant>;

Replaces <binary constant> with the equivalent decimal constant.

print "I was born in the "; @B 111;; "th month."

Result of ‘compilation’:

print "I was born in the "; 7; "th month."

@H | Hexadecimal constant

@H <hexadecimal constant>;

Replaces <hexadecimal constant> with the equivalent decimal constant.

print "I was born in the year "; @H 7BF;; "."

Result of ‘compilation’:

print "I was born in the year "; 1983; "."

@CONSOLE | Console constant

Inserts METAL‘s console constant, 0.

w = 48

h = 48

image = init screen( 0, 0, ( w * 2 ), h )

set screen to image

loadpict "image.pict"

set screen to console

copyrect masked 0, 0, w, h, w, 0, ( w * 2 ), h, 0, 0, w, h, image, image, @CONSOLE

Result of ‘compilation’:

w = 48

h = 48

image = init screen( 0, 0, ( w * 2 ), h )

set screen to image

loadpict "image.pict"

set screen to console

copyrect masked 0, 0, w, h, w, 0, ( w * 2 ), h, 0, 0, w, h, image, image, 0

@new_scope & @delete_scope | Declaring/scoping of variables

@new_scope <variable1>,<variable2>,<…>;

<…>

£<variable>

<…>

@delete_scope

When developing in METAL, it is easy to make a mistake in typing the name of a variable, or to cause a clash with the names of variables in subs (and now parameterised functions), resulting in bugs with hard to track down causes.

To try to remedy these causes of bugs, HEAVY METAL introduces declaring/scoping of variables, at the minor cost of typing an extra character before the name of a scoped variable.

The @new_scope instructions begins a new scope, and is followed by a list of the names of the variables introduced in that scope – a scoped variable can have the same name as a non-scoped variable or a scoped variable introduced in the scope immediately prior without clashing.

To use a scoped variable, simply prefix the name of the variable with a ‘£’ character.

Scoped variable names are not case-sensitive.

The @delete_scope instruction ends a scope.

Scopes are implemented by generating a random, unique prefix for each scope; when a scoped variable is used, it is simply given that prefix.

print "This program will print the numbers 21, 7, 1983, and 1997, in that order; each number will be printed on a new line."

v = 1997

@new_scope v;

£v = 1983

@new_scope v;

£v = 7

@new_scope v;

£v = 21

print £v

@delete_scope

print £v

@delete_scope

print £v

@delete_scope

print v

Result of ‘compilation’:

print "This program will print the numbers 21, 7, 1983, and 1997, in that order; each number will be printed on a new line."

v = 1997

mnjmuu_v = 1983

xdrhri_v = 7

lujggi_v = 21

print lujggi_v

print xdrhri_v

print mnjmuu_v

print v

@begin_func, @end_func, & @func | Declaring/calling functions

@begin_func <function>:<parameter1>,<parameter2>,<…>;

<…>

@end_func

@func <function>:<parameter1>,<parameter2>,<…>;

HEAVY METAL introduces parameterised functions; the @begin_func instruction begins the declaration of a function, and is followed by the name of the function, terminated by a ‘:’ character; that is then followed by a list of the names of the parameters of the function.

The @end_func instruction ends the declaration of the function; note that the function must be explicitly returned from using METAL‘s return instruction.

Parameterised functions are implemented using subs; the names of the parameters are prefixed with the name of the function to avoid clashes with variables elsewhere in the code; the parameters are then assigned the values passed to them, and the sub is called using METAL‘s gosub instruction.

Neither function nor parameter names are case-sensitive.

If in the declaration of a function a parameter is prefixed by a ‘~’ character, the value of that parameter is passed back when returning from the function.

goto MAIN



@begin_func Highest:value1,value2,~highestValue;

if value1 > value2 then

highestValue = value1

else

highestValue = value2

end if

return

@end_func



MAIN:

@func Highest:21,7,highestValue;

print "The highest value is: "; highestValue; "."

Result of ‘compilation’:

goto MAIN



highest:

if highest_value1 > highest_value2 then

highest_highestvalue = highest_value1

else

highest_highestvalue = highest_value2

end if

return



MAIN:

highest_value1=21

highest_value2=7

highest_highestvalue=highestValue

gosub highest

highestValue=highest_highestvalue

print "The highest value is: "; highestValue; "."

@++ | Increment variable

@++ <variable>;

Inserts instructions for incrementing <variable> by 1.

m = 6

@++ m;

print "I was born in the "; m; "th month."

Result of ‘compilation’:

m = 6

m = ( m + 1 )

print "I was born in the "; m; "th month."

@– | Decrement variable

@-- <variable>;

Inserts instructions for decrementing <variable> by 1.

y = 1984

@-- y;

print "I was born in the year "; y; "."

Result of ‘compilation’:

y = 1984

y = ( y - 1 )

print "I was born in the year "; y; "."

@+= | Increase variable by

@+= <variable1>,<variable1, 2, or constant>;

Inserts instructions for increasing <variable1> by <variable1, 2, or constant>.

m = 3.5

@+= m,m;

print "I was born in the "; m; "th month."

Result of ‘compilation’:

m = 3.5

m = ( m + m )

print "I was born in the "; m; "th month."

@-= | Decrease variable by

@-= <variable1>,<variable1, 2, or constant>;

Inserts instructions for decreasing <variable1> by <variable1, 2, or constant>.

y = 1997

z = 14

@-= y,z;

print "I was born in the year "; y; "."

Result of ‘compilation’:

y = 1997

z = 14

y = ( y - z )

print "I was born in the year "; y; "."

@*= | Multiply variable by

@*= <variable1>,<variable1, 2, or constant>;

Inserts instructions for multiplying <variable1> by <variable1, 2, or constant>.

d = 7

@*= d,3;

print "I was born on the "; d; "st of July."

Result of ‘compilation’:

d = 7

d = ( d * 3 )

print "I was born on the "; d; "st of July."

@/= | Divide variable by

@/= <variable1>,<variable1, 2, or constant>;

Inserts instructions for dividing <variable1> by <variable1, 2, or constant>.

m = 21

@/= m,3;

print "I was born in the "; m; "th month."

Result of ‘compilation’:

m = 21

m = ( m / 3 )

print "I was born in the "; m; "th month."

@&= | Logically AND variable

@&= <variable1>,<variable2 or constant>;

Inserts instructions for performing a logical AND of <variable1> and <variable2 or constant>, assigning the result to <variable1>.

v = @B 111111;

print "I'm pretty sure I wasn't born on the "; v; "rd of July…"

@&= v,@B 010101;;

print "I was born on the "; v; "st of July."

Result of ‘compilation’:

v = 63

print "I'm pretty sure I wasn't born on the "; v; "rd of July…"

v = ( v and 21 )

print "I was born on the "; v; "st of July."

@|= | Logically OR variable

@|= <variable1>,<variable2 or constant>;

Inserts instructions for performing a logical OR of <variable1> and <variable2 or constant>, assigning the result to <variable1>.

v = @B 010000;

print "I'm pretty sure I wasn't born on the "; v; "th of July…"

@|= v,@B 000101;;

print "I was born on the "; v; "st of July."

Result of ‘compilation’:

v = 16

print "I'm pretty sure I wasn't born on the "; v; "th of July…"

v = ( v or 5 )

print "I was born on the "; v; "st of July."

@!= | Logically NOT variable

@!= <variable>;

Inserts instructions for performing a logical NOT of <variable>, assigning the result to <variable>.

v = @B 101010;

print "I'm pretty sure I wasn't born on the "; ( v and @B 111111; ); "nd of July…"

@!= v;

print "I was born on the "; ( v and @B 111111; ); "st of July."

Result of ‘compilation’:

v = 42

print "I'm pretty sure I wasn't born on the "; ( v and 63 ); "nd of July…"

v = ( not v )

print "I was born on the "; ( v and 63 ); "st of July."

@” | Quotation mark

@"

Inserts instructions for inserting a quotation mark character.

print "Mark " + @" + "sealfin" + @" + " Bishop"

Result of ‘compilation’:

print "Mark " + chr$( 34 )+ "sealfin" + chr$( 34 )+ " Bishop"

Bug

  • Comments are not respected, viz., HEAVY METAL instructions in comments will still be ‘compiled’; for many instructions, this is not a problem, but not for all, as the following two programs demonstrate.

    Program #1:

    rem My_name_is_Mark = @TRUE

    Result of ‘compilation’:

    rem My_name_is_Mark = -1

    Program #2:

    goto MAIN



    @begin_func Highest:value1,value2;

    @new_scope highest;

    if value1 > value2 then

    £highest = value1

    else

    £highest = value2

    end if

    print "Out of "; value1; " and "; value2; ", "; £highest; " is the highest value."

    return

    @delete_scope

    @end_func



    MAIN:

    rem @func Highest:21,7;

    Result of ‘compilation’:

    goto MAIN



    highest:

    if highest_value1 > highest_value2 then

    kydcwk_highest = highest_value1

    else

    kydcwk_highest = highest_value2

    end if

    print "Out of "; highest_value1; " and "; highest_value2; ", "; kydcwk_highest; " is the highest value."

    return



    MAIN:

    rem highest_value1=21

    highest_value2=7

    gosub highest

  • If a function calls another function, the first function’s parameters cannot be passed straight to the second, as the parameters will not be properly prefixed with the name if the first function during ‘compilation’; for now this bug can be circumvented by assigning the first function’s parameters to intermediate variables, and passing those intermediate variables to the second function; the following two programs demonstrate the bug, and circumventing the bug.

    Program #1:

    goto MAIN



    @begin_func function1:parameter1$;

    print "parameter1$: " + @" + parameter1$ + @"

    return

    @end_func



    @begin_func function2:parameter2$;

    @new_scope s$,i,c$;

    @func function1:parameter2$;

    £s$ = ""

    for £i = 1 to len( parameter2$ )

    £c$ = mid$( parameter2$, £i, 1 )

    if ( asc( £c$ ) >= asc( "a" )) and ( asc( £c$ ) <= asc( "z" )) then

    £c$ = chr$( asc( "A" ) + ( asc( £c$ ) - asc( "a" )))

    end if

    @+= £s$,£c$;

    next £i

    print "parameter2$: " + @" + £s$ + @"

    return

    @delete_scope

    @end_func



    MAIN:

    print "This program should print two strings, the second a capitalised copy of the first."

    @new_scope s$;

    £s$ = "Cower now brief mortals, for I am Death, 'gainst whom no lock will hold nor fastened portal bar"

    @func function2:£s$;

    @delete_scope

    Result of ‘compilation’:

    goto MAIN



    function1:

    print "parameter1$: " + chr$( 34 )+ function1_parameter1$ + chr$( 34 )

    return



    function2:

    function1_parameter1$=parameter2$

    gosub function1

    fjofsy_s$ = ""

    for fjofsy_i = 1 to len( function2_parameter2$ )

    fjofsy_c$ = mid$( function2_parameter2$, fjofsy_i, 1 )

    if ( asc( fjofsy_c$ ) >= asc( "a" )) and ( asc( fjofsy_c$ ) <= asc( "z" )) then

    fjofsy_c$ = chr$( asc( "A" ) + ( asc( fjofsy_c$ ) - asc( "a" )))

    end if

    fjofsy_s$ = ( fjofsy_s$ + fjofsy_c$ )

    next fjofsy_i

    print "parameter2$: " + chr$( 34 )+ fjofsy_s$ + chr$( 34 )

    return



    MAIN:

    print "This program should print two strings, the second a capitalised copy of the first."

    olqxut_s$ = "Cower now brief mortals, for I am Death, 'gainst whom no lock will hold nor fastened portal bar"

    function2_parameter2$=olqxut_s$

    gosub function2

    Program #2:

    goto MAIN



    @begin_func function1:parameter1$;

    print "parameter1$: " + @" + parameter1$ + @"

    return

    @end_func



    @begin_func function2:parameter2$;

    @new_scope s$,i,c$;

    £s$ = parameter2$

    @func function1:£s$;

    £s$ = ""

    for £i = 1 to len( parameter2$ )

    £c$ = mid$( parameter2$, £i, 1 )

    if ( asc( £c$ ) >= asc( "a" )) and ( asc( £c$ ) <= asc( "z" )) then

    £c$ = chr$( asc( "A" ) + ( asc( £c$ ) - asc( "a" )))

    end if

    @+= £s$,£c$;

    next £i

    print "parameter2$: " + @" + £s$ + @"

    return

    @delete_scope

    @end_func



    MAIN:

    print "This program should print two strings, the second a capitalised copy of the first."

    @new_scope s$;

    £s$ = "Cower now brief mortals, for I am Death, 'gainst whom no lock will hold nor fastened portal bar"

    @func function2:£s$;

    @delete_scope

    Result of ‘compilation’:

    goto MAIN



    function1:

    print "parameter1$: " + chr$( 34 )+ function1_parameter1$ + chr$( 34 )

    return



    function2:

    uduavc_s$ = function2_parameter2$

    function1_parameter1$=uduavc_s$

    gosub function1

    uduavc_s$ = ""

    for uduavc_i = 1 to len( function2_parameter2$ )

    uduavc_c$ = mid$( function2_parameter2$, uduavc_i, 1 )

    if ( asc( uduavc_c$ ) >= asc( "a" )) and ( asc( uduavc_c$ ) <= asc( "z" )) then

    uduavc_c$ = chr$( asc( "A" ) + ( asc( uduavc_c$ ) - asc( "a" )))

    end if

    uduavc_s$ = ( uduavc_s$ + uduavc_c$ )

    next uduavc_i

    print "parameter2$: " + chr$( 34 )+ uduavc_s$ + chr$( 34 )

    return



    MAIN:

    print "This program should print two strings, the second a capitalised copy of the first."

    fxqyrj_s$ = "Cower now brief mortals, for I am Death, 'gainst whom no lock will hold nor fastened portal bar"

    function2_parameter2$=fxqyrj_s$

    gosub function2

Outro

HEAVY METAL was developed on an Apple Power Macintosh 8100 in C++ compiled with Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition.)



{Monday 15th December '97}   Mark’s Math ‘Mogrifier

METAL is a freeware BASIC IDE by Marin Saric of Galactic Dreams Software, and is quite a capable development tool if you’re into lateral-thinking-to-overcome-the-limitations-of-the-language-development…

However, the language has a few limitations that I feel merely irritate rather than present a challenge to overcome: no support for multiple files, no support for named constants, no requirement that variables be declared/no scoping of variables, no support for parameterised functions, … So, I began to develop a utility to extend the language to remedy those limitations.

Mark’s Math ‘Mogrifier {source code|compiled:Mac OS pre-X} is… …not that utility.

Partway through the development of that utility I realised that if the extensions to the language were to include parameterised functions, then the developer could easily pass expressions, and not merely constants or variables, to the parameters of the functions; unfortunately, I had no experience writing code which parsed expressions…

So, I developed Mark’s Math ‘Mogrifier, a quick-and-dirty calculator, to gain experience writing code which parsed expressions before I resumed development of that utility.

Mark’s Math ‘Mogrifier is pretty limited, and only supports the operators +-*/^ and parentheses; type in an expression, press the Return key, and the expression will be solved, with the calculator showing each step in the solution.

Mark’s Math ‘Mogrifier was developed on an Apple Power Macintosh 8100 in C++ compiled with Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition.)



et cetera
Follow

Get every new post delivered to your Inbox.