6 ms·
New versions of BASIC are surprisingly common (heck, I even have one that's gotten some super-nice comments). Mind-blowing BASIC example from the 1970's:
by pedasmith 8y ago
New versions of BASIC are surprisingly common (heck, I even have one that's gotten some super-nice comments).
Mind-blowing BASIC example from the 1970's:
100 A$="ABCDEF"
110 A$ = REP ("123", 4, 0)
120 PRINT A$
The result is ABC123DEF -- at position 4 (strings start at 1), replace 0 characters with "123". So the REP function looks at the statement it's part of, finds the variable that is being assigned to, and uses that as the starting string (!). It's kind of like a function, only with a weird implied variable that only works in an assignment.
You can't just PRINT the result directly, because then how would REP know what the string to change is?
Nowadays "weird" syntax has some solid foundational reason why it's useful or important. This not-really-a-function, though, simply has no justification whatsoever.
(This example is from the BASIC embedded in the Tektronix 4050 terminal).
There are enough variants of BASIC that there's a really nifty handbook with the differences at https://archive.org/details/Basic_Handbook_2nd_Edition_1981_CompuSoft_Publishing https://archive.org/details/Basic_Handbook_2nd_Edition_1981_...
- pvg 8y agoIsn't that just someone putting some weird thing in some oddball BASIC implementation? I don't think any of the popular ones did anything like that.
- rzzzt 8y agoSome of them allowed to use MID$ for the left-hand side of an assignment to replace a substring, which is also unexpected.
- pvg 8y agoMID$ still took a string as an argument, though, right?
- rzzzt 8y agoYup, see https://news.ycombinator.com/item?id=17998173 https://news.ycombinator.com/item?id=17998173 for an example.
- lucio 8y agoThat syntax was irregular but very useful. It was not surprising or confusing. A$ = "ABCD" MID(A$,2,2)="12" PRINT $A >A123
- bbernoulli 8y agoAssuming a typo here, but I would be surprised if the output contained "3"
- quietbritishjim 8y agoThis is still going strong today in list slice notation in Python (and other languages, no doubt): x = [1,2,5,6] x[2:2] = [3,4] print(x) (Slice notation can be used on any collection, not just lists, but you can't use it in assignment like that for strings because they're immutable, so you'd have to convert to a list of characters and back.)
- exikyut 8y agoHmm. perl -le '$A = "ABCDEF"; substr($A, 3, 0) = 123; print $A' ABC123DEF
- aduitsis 8y agohttps://perldoc.perl.org/perlsub.html#Lvalue-subroutines https://perldoc.perl.org/perlsub.html#Lvalue-subroutines
- imglorp 8y agoLook again at that comment. He wasn't remarking about a substr, it was the curious syntax where the LHS of an assignment was actually an argument to the RHS function.
- deleted 8y ago[deleted]
- tralarpa 8y agoI did my first serious programming steps with BASIC on the C64 and the Amiga. The (actually second) BASIC interpreter on the Amiga was made by Microsoft. It was great and horrible at the same time. Great because it had while-loops, labels instead of line numbers, and basic (no pun intended) support for the Amiga GUI, i.e you could open windows and create menus. Horrible because it was super slow and, for some reasons unknown to me, Microsoft had decided to not implement stack frames for subroutines. So, all local variables in subroutines were static and recursions were not allowed. The weird thing: You still had to write the "STATIC" keyword although all subroutines were static anyway! (I assume the STATIC keyword was optional in the other Microsoft BASIC version and non-static subroutines were supported there)
- kijin 8y agoAn object-oriented version (assuming mutable strings) might be: A$.REP("123", 4, 0) So the syntax is weird, but the concept isn't totally unusual.
- pedasmith 8y agoExactly. It's a perfectly reasonable concept with a completely outlandish syntax. I don't know of any current programming language where the RHS of an assignment will even know what the LHS is.
- DonHopkins 8y agoIn C++ that would be called "operator REP="
- DonHopkins 8y agoSpeaking of weird BASIC features, does anyone know why DECSYSTEM 20's BASIC had a "LISTREVERSE" command? Yes, it actually did exactly what it sounds like! Chalk one up for DEC and BASIC. What other programming languages support that feature, huh? https://imgur.com/a/Bt40M https://imgur.com/a/Bt40M DECSYSTEM 20 BASIC User's Guide: LISTREVERSE command LISTREVERSE LISTNHREVERSE LISTREVERSE and LISTNHREVERSE print the contents of the user's memory area in order of descending line numbers. LISTREVERSE precedes the output with a heading, LISTNHREVERSE eliminates the heading. LISTREVERSE EQUIV 10:53 13-NOV-75 40 END 35 PRINT "THE EQUIVALENT CURRENT IS",I, " AMPERES" 25 I=E1/R 10 INPUT R 5 INPUT E1 READY http://www.bitsavers.org/www.computer.museum.uq.edu.au/pdf/DEC-20-LBMAA-A-D%20BASIC%20User's%20Guide.pdf http://www.bitsavers.org/www.computer.museum.uq.edu.au/pdf/D...
- tom_ 8y agoIf you're using a printer, presumably you might sometimes want the stuff at the top of the program to be last on the printout, so it's easy to get at without having to flip through a pile of paper? Same might go for a terminal with no scrollback... Come to think of it, this sounds actually rather useful. Had this been available when I was programming on the BBC Micro, I bet I'd have used it.
- DonHopkins 8y agoEmacs should have an edit-reverse-mode!
- thaumasiotes 8y ago> So the REP function looks at the statement it's part of, finds the variable that is being assigned to, and uses that as the starting string (!). It's kind of like a function, only with a weird implied variable that only works in an assignment. As DonHopkins notes, this appears substantially identical to the assign-equals operators which are generally thought of as "easy and convenient" rather than "weird". How is the line of code "a *= 7" meaning "whatever the current value of a is, multiply that by 7 and assign the result to a" weirder than the line 'a$ = REP("123",4,0)' meaning "whatever the current value of a$ is, do a string replacement on it and assign the result to a$"?