Basicprogramming(.org) > Tutorials and articles

Notes on Script BASIC

<< < (9/10) > >>

B+:

--- Quote from: B+ on September 22, 2018, 02:19:36 PM ---Uh! because Script ASIC doesn't structure variables the same as other PL's doesn't mean it couldn't produce same results in one elegant line, just needs some setup.

For example QB64 has next to nothing for array handling, I had to build a library just to sort an array of floats and some other tools for handling number arrays but I had all tools to make a function that does same as these built-ins of PL's you are showing off.


--- Code: ---'Test Floats Array Tools Library.bas for QB64
PRINT UniqueSortSlice$("120 135 345 345 1890 12 120 12 135 712 78 120", "descend", 0, 3) 'Tomaaz sample
PRINT UniqueSortSlice$("120 135 345 345 1890 12 120 12 135 712 78 120", "ascend", -10, 5) 'test join tolerance
PRINT UniqueSortSlice$("120 135 345 345 1890 12 120 12 135 712 78 120", "descend", 3, 16)
PRINT UniqueSortSlice$("1 1.1 1.11 1.1 1.11 1. 1.0 1.111 .999999999999999999999999999999999999999", "ascend", 0, 1000) 'oh that's nice!!! but I think .99... is same as 1

FUNCTION UniqueSortSlice$ (NumberStr$, ascendDescend$, SliceStart AS LONG, SliceEnd AS LONG)
    REDIM temp(0) AS _FLOAT
    Split2Floats NumberStr$, " ", temp()
    uniqueFloats temp()
    qSortFloats LBOUND(temp), UBOUND(temp), temp()
    IF ascendDescend$ <> "ascend" THEN reverseFloats temp()
    UniqueSortSlice$ = JoinFloats$(temp(), SliceStart, SliceEnd, " ")
END FUNCTION

'$include: 'Floats Array Tools.bm'

--- End code ---

See attached output. It would have been easier with Script Basic or with SmallBASIC because both use variant variable types and more advanced array stuff is already built into language.

--- End quote ---


How can the above possibly be construed as advocating QB64?

I thought I was defending the SB's for their variant type variables and advanced array manipulation over and above QB64 in that one department.

I thought I was demonstrating that even QB64 can do what Tomaaz was doing though it takes a few or many more lines.

So to be clear to everyone named Mike that is what I was attempting to do.

Here is the last line of the quote once again, in John's style:
See attached output. It would have been easier with Script Basic or with SmallBASIC because both use variant variable types and more advanced array stuff is already built into language.

B+:

--- Quote from: B+ on September 22, 2018, 02:42:55 PM ---I built a special library to handle float arrays the same as you are showing, as strings$

I did build a special function because QB64 sucks as far as not being able to pass arrays through functions, not same problem with Script or SmallBASIC.

How hard is it to change your output to this? (attached)

And how do these things handle floats? The forth line? I am curious the decision it would make for 1, 1.0, 1. and .99.... would they be the same or each unique?

--- End quote ---

Tomaaz,

I am inquiring about how the language you are advocating handles a couple of things, did you miss it?

You didn't just setup a more difficult task to blow off my question did you?

And yes, I agree new tasks should go in a different board.

They really don't belong here, just the answer to my question. ;)

PS the library is not special for your task, it is a general set of useful tools for handling Float Arrays. Sure, they may come in handy in future dealings with Tomaaz Tasks. :)

Peter:

--- Quote from: Tomaaz on September 22, 2018, 03:48:49 PM ---OK. Here is another task. Recursively walk directory, find all .jpg files which names are integers, sort the names by numbers and print the result.

--- End quote ---

I know why you proposed this task, and my code below is completely off-topic, but I simply couldn't resist solving this  :) I am interested to see how it looks in other BASIC variants.


--- Code: ---SUB Recurse_Dir(STRING dir$)
    LOCAL here TYPE DIR*
    OPEN dir$ FOR DIRECTORY AS here
    WHILE TRUE
        GETFILE item$ FROM here
        IF NOT(LEN(item$)) THEN BREAK
        IF item$ = "." OR item$ = ".." THEN CONTINUE
        new$ = dir$ & "/" & item$
        IF FILETYPE(new$) = 2 THEN
            Recurse_Dir(new$)
        ELSE
            IF BASENAME$(new$, 2) = "jpg" AND REGEX(BASENAME$(new$, 1), "^[[:digit:]]*$") THEN result$ = APPEND$(result$, 0, new$, NL$)
        END IF
    WEND
    CLOSE DIRECTORY here
END SUB
Recurse_Dir(".")
PRINT SORT$(result$, NL$)

--- End code ---


--- Quote from: Mike Lobanovsky on September 22, 2018, 10:27:36 PM ---Yet if I were in your shoes I'd most likely stop posting here and would rather open a couple of new threads to present the Python/Ruby examples as challenges for the BASIC-ers to compete.

--- End quote ---

That is a great idea! It would stimulate improving implementations of BASIC.

Tomaaz:
Yes, that would be great, but I seriously doub " the WinApi guru" will let us do it. He's already declared Python, Perl, Ruby etc. to be "junk",  OOP to be " useles" and https to be "just another crap". When he sees my nickname together with the word " Python" in one post,  it's the end of serious discussion (this topic is a perfect example).

B+:

--- Quote from: Tomaaz on September 23, 2018, 02:39:32 PM ---Yes, that would be great, but I seriously doub " the WinApi guru" will let us do it. He's already declared Python, Perl, Ruby etc. to be "junk",  OOP to be " useles" and https to be "just another crap". When he sees my nickname together with the word " Python" in one post,  it's the end of serious discussion (this topic is a perfect example).

--- End quote ---

Yeah sure blame it on him. (Though it's definitely more than partly true, you love it.) I had a serious question, is it being ignored?

PS I am eager to try an SB out on this latest challenge, will someone please post something in another thread or do I have to do it again?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version