And how about the assigned GOTO in older versions of Fortran? "GOTO N" where N is an integer variable whose value will be known at runtime.
Happy days...
61–66 of 66 posts
And how about the assigned GOTO in older versions of Fortran? "GOTO N" where N is an integer variable whose value will be known at runtime.
Happy days...
The control structures in Icon are not quite what you would expect and qualify as strange: http://en.wikipedia.org/wiki/Icon_(programming_language)
I don't see what you mean; could you spell it out?
http://blogs.kde.org/2006/10/21/ralph-griswold-icon-language...
http://dl.acm.org/citation.cfm?id=104659
http://research.microsoft.com/pubs/69724/tr-99-64.ps
look at Goal-directed evaluation of icon
Snobol... where patterns are first class constructs, and every line can end with a GOTO. That definitely lets you write some very, er, compact code. But it was superb to program in. And how about the assigned GOTO in older versions of Fortran? "GOTO N" where N is an integer variable whose value will be known at runtime. Happy days...
#include
int main( int argc, char ** argv ){
void * p = && lol ;
bounce:
goto *p ;
lol:
printf("lol %p\n", p);
p = && wtf;
goto bounce;
wtf:
printf("wtf %p\n", p);
p = && lol;
goto bounce;
}: 2 3 ; ... redefines the constant 2 as 3. FORTH. Go figure :-)
In Forth, the following are fairly common definitions in the core: 0 CONSTANT 0 1 CONSTANT 1 -1 CONSTANT -1 In an Algolian language like C++ or Java, if the syntax were legal, these would be: const 0 = 0; const 1 = 1; const -1 = -1; The reason for this is to do with the interpreter. How the Forth interpreter works is very simple: 1. Read one word, where "word" is literally defined as "a sequence of non-space characte…
At compilation time (the word : is one of the ways to switch the system to compilation mode), Forth doesn't execute words and numbers if finds, but it adds their addresses (in some form, depending on the implementation) to the generated code. When running the code later, the runtime simply fetches each of these function addresses and 'calls' them (that's what makes Forth systems fast without the need for any convoluted compiler technology. Depending on the implementation, that 'call' may be an actual call in the CPU, but it typically is just another 'grab the addresses found there in sequence and execute them' and yes, it can't be turtles all the way down, but Forth gets awfully close)
Now, the question is: how do you compile "push this constant on the stack"? Forth does it by compiling the word called LITERAL, followed by the constant.
So, compiling a function called 0 or 1 adds a function address to the compiler output, but compiling a literal constant adds the address of the function called LITERAL and that constant. For constants used more than a few (where the exact limit depends on he particular Forth implementation) times, the extra space needed for that function gets more than compensated by the gain. In typical Forth systems, -1, 0, 1, and 2 already are space savers before the user types his first character. That's why they are predefined. If you use another constant often, you can easily define it. Many Forth systems even have a function called CONSTANT for it, but you can define it yourself, if it is absent.
For those wondering how the system knows that that constant it compiled isn't the address of a function to call: it doesn't. Instead, the function called LITERAL, when called, hooks into the runtime, uses the 'current instruction pointer' to read the value to push on he stack, and then increases that pointer to point past the constant. When LITERAL returns, the runtime just reads what it thinks is the next pointer and calls it.
: 2 3 ; ... redefines the constant 2 as 3. FORTH. Go figure :-)
In Forth, the following are fairly common definitions in the core: 0 CONSTANT 0 1 CONSTANT 1 -1 CONSTANT -1 In an Algolian language like C++ or Java, if the syntax were legal, these would be: const 0 = 0; const 1 = 1; const -1 = -1; The reason for this is to do with the interpreter. How the Forth interpreter works is very simple: 1. Read one word, where "word" is literally defined as "a sequence of non-space characte…
While I absolutely hate FORTH as a production language (I've seen millions of dollars flushed down the tubes by FORTH afficianados who were unwilling to admit that their code was unmaintainable, slow, and didn't work), it's fun to play around with. Everybody should write at least one FORTH in their career.
Earlier quoted context omitted.
Certain ancient FORTRAN compilers would let you do that as well. If the target CPU didn't have a "move immediate" instruction, the compiler would just stash the number into memory. The quickest way to implement it is to just add the number into the symbol table... that way an often-used constant will only need one spot in core. Of course when your whole compiler has to run in 8 Kwords or whatever, syntax checking isn…
I haven't heard of that, and it would be great if you could remember where you found it. It sounds to me like it might be an apocryphal corruption of the following: Fortran passes arguments by reference. If the compiler uses a constant pool, and (lazily or efficiently, depending on your point of view) passes the constant pool location as an argument, a subroutine could inadvertently modify a constant. FORTRAN 66 (the…
I'm almost curious enough to fire up a PDP-8 emulator and see what 4K FORTRAN does. Almost. http://techtinkering.com/2009/07/14/running-4k-fortran-on-a-...