|
Post by B+ on Feb 4, 2020 16:04:37 GMT
input "Enter a string to insert dots ";insertThis$ print "Here it is from the function: ";insertDotBetweenEveryCharacter$(insertThis$) print "Here it is from the function unpacked into main code: ";
'unpack function into main code block(s) insertMe$ = insertThis$ '<<<<<<<<<<<<<<<<<<<<<< give parameters starting values [startLoop] i = i + 1 if i > len(insertMe$) then 'remove last _ 'exit function 'done goto [exitLoop] '<<<<<<<<<<<<<<<<<<<<<<<<<< instead of exit function, exit the code block that is from function else if i = 1 then insert.BetweenEveryCharacter$ = mid$(insertMe$, i, 1) ' <<< change name from function's name so no name conflict else insert.BetweenEveryCharacter$ = insert.BetweenEveryCharacter$;".";mid$(insertMe$, i, 1) ' ditto above comment end if end if goto [startLoop] [exitLoop] print insert.BetweenEveryCharacter$
'Here is a sample function to unpack (without any loop structure other than GOTO) function insertDotBetweenEveryCharacter$(insertMe$) [startLoop] i = i + 1 if i > len(insertMe$) then exit function 'done else if i = 1 then 'first character doesn't get a dot insertDotBetweenEveryCharacter$ = mid$(insertMe$, i, 1) else insertDotBetweenEveryCharacter$ = insertDotBetweenEveryCharacter$;".";mid$(insertMe$, i, 1) end if end if goto [startLoop] end function
Oh hey! no label name conflicts, label names inside functions stay inside the function and can use same label name in main code without conflict.
Unpacking Functions is kind of silly but you can use just the reverse of this process to take main code block(s) to pack into a Function and that is smart!
|
|
|
Post by tsh73 on Feb 4, 2020 17:07:18 GMT
Ow. Reversing things that kind of silly is smart. Sounds very mathy for me. I need a badge with that.
|
|
|
Post by B+ on Feb 4, 2020 17:48:31 GMT
|
|
casco
New Member
Posts: 16
|
Post by casco on Feb 6, 2020 11:36:17 GMT
Meow, B+, is it ok to stick with the old-fashioned way? input "enter string: "; a$ input "enter single-character delimiter: "; d$
for i=1 to len(a$) ad$=ad$+mid$(a$,i,1)+d$ next i
print left$(ad$,len(ad$)-1) end loops
|
|
|
Post by B+ on Feb 6, 2020 13:53:47 GMT
Woof! casco, What's more old fashioned than GOTO! ;-))
The original post was responding to a student rejecting code demos in functions wanting something done in main only (I guess). So this was attempt (maybe d.u.m.b but es task was to insert commas between every 3) to show how easy it is to take a function and main stream it, so to speak.
Another part of students assignment was to not use a FOR... NEXT Loop or any loop structure??? So I was showing how GOTO provides loop functionality without a formal loop structure like FOR, WHILE, DO, REPEAT and whatever else is out there. Probably went over everyone's head, oh well... I had fun. ;-))
|
|
|
Post by tsh73 on Feb 6, 2020 16:57:25 GMT
Line numbers! You forgot line numbers! And program used to be IN ALL CAPS. And - string variables used to be single-character only. (it was ZxSpectrom online emulator. Man, I stuck to keyboard Graph mode and hardly escaped alive!)
|
|
casco
New Member
Posts: 16
|
Post by casco on Feb 6, 2020 22:34:36 GMT
Line numbers! You forgot line numbers! And program used to be IN ALL CAPS. And - string variables used to be single-character only. Sorry to say I'm not overall familiar with the Sumerian period. That's a remarkable clay fragment though.
|
|
casco
New Member
Posts: 16
|
Post by casco on Feb 6, 2020 22:49:31 GMT
Woof! casco, What's more old fashioned than GOTO! ;-)) The original post was responding to a student rejecting code demos in functions wanting something done in main only (I guess). So this was attempt (maybe d.u.m.b but es task was to insert commas between every 3) to show how easy it is to take a function and main stream it, so to speak. Another part of students assignment was to not use a FOR... NEXT Loop or any loop structure??? So I was showing how GOTO provides loop functionality without a formal loop structure like FOR, WHILE, DO, REPEAT and whatever else is out there. Probably went over everyone's head, oh well... I had fun. ;-)) Oh, I missed that post!
|
|