4 ms·
Probably hadn't thought of passing a subroutine address to a routine in z80 machine language he was familiar with?
by Questron 9y ago
Probably hadn't thought of passing a subroutine address to a routine in z80 machine language he was familiar with?
- geofft 9y agoYeah, I understand why this is difficult if not impossible to do in BASIC, but functions are first-class in just about any assembly language. That said, remember that the author is talking about his experience as a first-year college student. When I went to college, I had extensive experience with BASIC (GW, Q, TI, and a bit of Visual), a year of C++ in high school, and a few vague attempts at assembly (386 and Z80) that got me nowhere. The idea of function pointers was one of those scary advanced C things that I had picked up to avoid, and certainly the corresponding assembly concept didn't occur to me. Of course I knew you could jump to a computed value, but the mindset was foreign. I sort of knew that this was doable with objects in C++ - I could define a base class with an abstract method calculate(), and make a Cube subclass - but thinking of functions as first-class still wasn't obvious.
- Questron 9y agoYes, pointers to pointers etc. are difficult to grasp, but then again, so is passing functions as arguments. Also, information wasn't as readily available then as it is now. Anyways, to make a long story short, here's "mega-deriver" numerical calculus package I just whipped up in COMMODORE BASIC 2.0: http://imgur.com/94eNuSX http://imgur.com/94eNuSX It should run (unmodified?) on all MS BASIC dialects of the time (including Apple II and VIC-20). Note the higher precision of floating-point numbers than the puny m86k lisp the OP linked to. This one's probably faster, too ;)
- Sharlin 9y agoPassing function addresses as parameters is easy. It's more difficult to return a nested function that closes over the outer function's variables.
- Questron 9y agoNot really in machine language or even BASIC (see below).
- int_19h 9y agoYour BASIC example doesn't have any local variables to close over. It just references a global. That defeats the whole point of closures. Passing or returning first-class functions aren't a problem. First-class closures (function pointer + state) are.
- Questron 9y agoYou can create closures in CBM BASIC V2 by referencing arrays or creating thunks as an extension. But that's beside the original point. Implementing is not a lot of work but since my mega-deriver already solves the problem (derivation) elegantly and efficiently (most likely more efficiently than the original m68k lisp program), I really don't see any reason to use closures here. Do you?