|
Post by btiffin on Feb 23, 2017 9:05:41 GMT 1
A) A lot of my background is COBOL. We're big on priming the pump before a loop. That style can change. B) I thought I needed the cnt% for the APPEND$, didn't know about the 0 until I read your update, so thanks. I'll probably hit up Rosetta Code shortly with better code. Might. Here is one of my testing dirs. prompt$ ls e "ls" "tt"
Two filenames with quotes. I added your cut to the current program and get: cd e; ../unix-ls; cd .. "ls" "tt" New code \"tt\"" "\"ls\" ls tt
I'm still wondering if delimited strings are the right tool for this particular task. There are other ways of building up that list of names for sorting, and the code will still be short and sweet. Have good, Brian
|
|
|
Post by Pjot on Feb 23, 2017 18:52:54 GMT 1
Well, those are interesting examples, of course.... but who has filenames with double quotes on his disk anyway?!?! But this can be solved. In the world of delimited strings, the double quote has a special meaning. It is used to embed a set of characters which belong together. If the delimiter occurs within such double quotes, then it will be accepted as part of a string. So, when we are to expect items containing double quotes, we must make sure these double quotes are not interpreted as symbols holding a few characters together. So, we must UNFLATTEN them. The program now will look as follows: OPEN CURDIR$ FOR DIRECTORY AS mydir
REPEAT GETFILE myfile$ FROM mydir IF LEFT$(myfile$, 1) != "." AND LEN(myfile$) THEN files$ = APPEND$(files$, 0, UNFLATTEN$(myfile$), "/") ENDIF UNTIL NOT(LEN(myfile$))
CLOSE DIRECTORY mydir
FOR f$ IN SORT$(files$, "/") STEP "/" PRINT FLATTEN$(f$) NEXT
As can be observed, as soon as entries are being added to the delimited list, the entries are unflattened first. With such entries, we can safely walk through them and apply a SORT. Printing now needs FLATTEN. My output: You may wonder why the file "zzz" appears at this position in the middle of the list. This is because when sorting, the unflattened name looks like \"zzz\", and hence, sort regards the '\' character as the first symbol, which, in the ASCII table, occurs before the small letters but after the capitals. We have to use what's best, of course. A program without delimited strings would look like the below. The file counting now is back, because we need to specify a position in the array. OPEN CURDIR$ FOR DIRECTORY AS mydir
DECLARE file$ ARRAY 1
nr = 0
WHILE TRUE GETFILE file$[nr] FROM mydir IF NOT(LEN(file$[nr])) THEN BREAK ELIF LEFT$(file$[nr], 1) != "." THEN INCR nr REDIM file$ TO nr+1 ENDIF WEND
CLOSE DIRECTORY mydir
SORT file$ SIZE nr
FOR x = 0 TO nr-1 PRINT file$[x] NEXT
The file "zzz" now will occur at the top of the list, because the double quote symbol appears before both the small and capital letters in the ASCII table. Best regards Peter
|
|
|
Post by btiffin on Feb 24, 2017 6:53:33 GMT 1
Well, it's your baby, Peter. Which picture would you like shown? Left side or right side? The task objective is to simulate ls, and I'm leaning to non delimited strings, but that's partly because I'm not totally up on the ins and outs of the token splits and what characters, which are allowed in filenames, (spaces for one along with backquotes and nulls and the like) might cause edge case problems. For now, it's still the old code (which has flatten/unflatten, but I may be using them incorrectly for the above mentioned edge cases). I'll explore your new example and see if I can break it. Much fun. Cheers, Brian
|
|
|
Post by btiffin on Mar 5, 2017 10:13:03 GMT 1
Ranked in the top 200 already, out of some 580 language categories. Should be in the top 100 within a few weeks. rosettacode.org/wiki/RC_POP.OUTTo all, some of these tasks are pretty easy, and only take a minute or two to fill in... rosettacode.org/wiki/Category:SimpleOnce the simple tasks are in, BaCon will just about rank in the top 100 by "popularity". The meatier tasks are where people will likely start to take notice though. Cheers, Brian
|
|
|
Post by btiffin on May 15, 2017 4:01:42 GMT 1
|
|
|
Post by Pjot on Jul 20, 2017 21:34:42 GMT 1
Hi Brian, So the last couple of days I made some contributions to Rosetta Code, we're at 85 now. Some assignments are really trivial (like this one) but some are also very interesting (like, for example, this one). It is a nice way to verify various aspects of BaCon, and see if bugs pop up. As a matter of fact, I did find one bug with SORT$ Regards Peter
|
|
|
Post by btiffin on Jul 22, 2017 5:53:58 GMT 1
Nice, Peter. As these programs age a little bit on Rosetta, and people get a chance to try them, "just because" during exploring, I think you'll end up surprising many when they see the simplicity of BASIC running at chip speeds. That can cause a bit of a double take, "What? No, can't be that fast. Wait, it is?" Rosetta Code has a purpose, to compare languages at each of these tasks. It would be nice if performance numbers took on a more prominent role in the solution descriptions. Perhaps we should add some timing values along with some of the Output sections, give BaCon some bragging rights. Have good, Brian
|
|
|
Post by bigbass on Sept 9, 2017 8:46:22 GMT 1
Thank you btiffin and Peter
For your work adding BaCon to rosetta code
This really is the best way to see how to port code to BaCon code and have many working snippets nicely organized
for example we can try to follow the C code and port it to BaCon
this will save a lot of time when we need to add extra code that we don't find in the docs
of course the qbasic/Basic already has many examples as a reference point
I am adding some code too its fun Joe
|
|
|
Post by bigbass on Sept 11, 2017 16:03:49 GMT 1
|
|
|
Post by Pjot on Dec 10, 2017 9:27:42 GMT 1
|
|
|
Post by Pjot on Feb 24, 2021 21:33:55 GMT 1
All, We now can verify the language rankings at rosetta.org without logging in. The BaCon ranking program is here. It uses the API from Rosetta's Mediawiki software, and also the BaCon implementation for the JSON to delimited string parser. You can verify the output of the BaCon code with the official full list. The BaCon program shows 2 columns with ranking. The first column uses same ranking system as Rosetta. Their logic is as follows: if language A and B have the same ranking, then language C ends up at position 3. The second column in the output is the more intuitive way: if language A and B have the same ranking, then language C ends up at position 2. According to the second column, BaCon now has reached position 99 Regards, Peter
........ 100 : 95 : IS-BASIC (198) 101 : 96 : Lingo (194) 102 : 97 : Ursala (193) 103 : 98 : Nanoquery (192) 104 : 99 : BaCon (186) <---------------------- 105 : 100 : Lambdatalk (185) 106 : 101 : ARM Assembly (184) 107 : 102 : ERRE (183) 107 : 102 : Yabasic (183) ........
|
|
|
Post by bigbass on Feb 26, 2021 3:39:06 GMT 1
Hello Peter
offering some feedback compiles and runs correctly for me
(I will have to look at your JSON parsing and see what you did ) *I have been using javascript with node for that type of thing when there is a lot of JSON to parse but if I can do that also with bacon that would be nice and remove those dependencies
Joe
output from your app
100 : 93 : IS-BASIC (198) 101 : 94 : Lingo (194) 102 : 95 : Ursala (193) 103 : 96 : Nanoquery (192) 104 : 97 : BaCon (186) 105 : 98 : Lambdatalk (185) 106 : 99 : ARM Assembly (184) 107 : 100 : ERRE (183) 107 : 100 : Yabasic (183)
P.S I will try to do this in javascript just to see the json parsing in action and get a better understanding of all that is going on
|
|