syntax fixes#6
Conversation
|
Hi dragoncoder047, First of all - I see that Phoo is "inspired by Quackery" Wow! That my pet language inspired someone to create their own language has completely made my day. Achievement unlocked! :-) Sorry you can't edit the TBoQ pdfs - if you have MacOS I can let you have the masters - rather thoughtlessly I used my word processor of preference and managed to lock it into "only the MAcOS version of Pages can edit it" - it's not compatible with the online Pages. D'Oh. The best I have is to suggest that you rustle up an addendum/errata document to accompany it.
First is that the branching functionality is intended to be limited. I'm enforcing structured programming by design, and Second is I have a whole load of stuff on Rosettacode that I don't want to plough through looking for meta-words to update. (There's also a small but promising repository of Quackery code at olus2000/ALEx btw.) On the other hand, I'll definitely be incorporating your Python syntax fixes. Thank you for those. I literally taught myself just enough Python to code Quackery, so if it looks like it was written by a newb, that's because it was! Yours, Gordon |
|
Alright, I put it back. I will review the code again for pythonics again. As to the PDF files, I do not have a Mac. (I have a Raspberry Pi at home and a chromebook at school which I am on right now.) If you're up to the task you could convert them to Markdown, and that way anyone with a text editor could edit them - Python Markdown has a def_list extension that would work GREAT for the documentation of each word. BTW, Phoo is broken right now. I am working on getting it fixed. |
]if[, ]iff[ and ]else[ into ## ]cjump[, syntax fixes|
Syntax looks good now. I also changed some of the error messages. For example you had the same error message for both I also changed all the error messages in the building code from using EDIT: typo EDIT 2: Oops, forgot to mention this. I put some possible future suggestions/improvements in the code too. Search for my username to find them. |
|
You've been busy! I'll hold off merging your commits until you're confident that no more are imminent. Some comments. Thank you for that! I learned something today. I spent too long failing to find a way to not use the
� would be the logical choice. Quackery is a unicode-free-zone. I spent far too long perusing the Unicode specs and decided that if I can't do it right I won't do it at all. I have yet to find a language or OS that gets it right (see: "this message will crash your android/iOS etc.")
The predefined quackery string mentions
Aha! Error messages within the Python Quackery compiler. Those are only there because I didn't remove them. build() only exists to compile the predefined Quackery string, which is error-free. If the error detection code is anything it is hints for anyone who wants to recode Quackery in a different language. But yes, raising the relevant error is better than using sys.exit. I'm fine with all the changes to error messages apart from Migrate TBoQ to markdown? Well, "never say never" but I don't see it happening any time soon. That sound like a BIG job. G |
|
Great, I don't see any more PEP 20 violations. As a side note I also wanted to swap out the Python definitions of I also have some other ideas about how to be able to incorporate external Python libraries (such as |
One other thing before I forget -- would changing |
|
I don't see pop and push as technobabble. I just don't like the word "pop" in the context of stacks, IMO you pop a balloon, or drink fizzy pop, or pop to the shops. I know that sometimes I'm a bit weird about words. On a more serious note, I don't see any advantage to renaming I think your fork will remain after merging. (Definitely not a GitHub expert - I'm only here because a bunch of people said "you should put it on GitHub." Now I'm figuring it out as I go along. Story of my life.) Looking forward to finding out how to avoid using Yup, the received wisdom in the Forth community is that (How practical? One guy I pay particular attention to, retired now, but developed systems for the most safety critical of all jobs... nuclear reactors. That's a job where you literally put your livelihood on the line. You don't supply programs with the big legal disclaimer that says "hey, take your chances, we guarantee nothing" that comes with every operating system, word processor etc. etc. instead you sign a document that says "I accept personal liability" and no insurance company will insure you against accidentally causing a nuclear catastrophe. So when there's an "event" not only do you get major guilt to live with, but you're bankrupt too. When someone who codes under those conditions says "it's a bad idea" I tend to believe them!) So instead I added
Not the I'm averse to the academic approach. I found this recently and it blew my mind that rather than "Forth with a sprinkling of Lisp" they went for "Lisp with a sprinkling of Forth" as their starting point. It's a good little paper, amusing and insightful. And they note that all you need is https://hashingit.com/elements/research-resources/1994-03-ForthStack.pdf Now that I've seen some Phoo code, I like it. I notice you're using the original versions of |
|
Back when I had a working version of Phoo (that was pre-me-on-Github) I noticed the strangest thing was Phoo was super fast compared to Quackery (except when I tried to use Right now Quackery is set up so that whenever you call the And speaking of the "old" versions of Avoiding |
|
Yup, rebuilding the predefined words every time is wasteful. If it was as simple as pickling the output of But… the whole point of Quackery is that you should be able to look at the code for It's a prototype, or a proof-of-concept. Maybe at some point I'll make it run fast, but for the time being switching to PyPy3 as it's host environment has given me sufficient speed boost to make it not painful-to-use, and I want to be an "experienced Quackery programmer" before I consider optimisation. Which is why I've been doing Rosettacode tasks for the last year and some. (Pypy3 has JIT compilation rather than a byte code interpreter, and incremental mark and sweep garbage collection that's way better than cPython's reference counting.) |
|
Goodness, no, I don't think you ever are going to need to rewrite I think the bottleneck is in The changes I was thinking in terms of speed and nonredundancy were things like moving Anyway, I think you're safe to merge this PR now. I don't see any more changes. |
|
" moving build, traverse, and all the Python function-words out into the main module instead of indented" That would make a difference? Python doesn't compile nested functions until it needs them? Oh my! |
|
Yep. Python only compiles the Also, if you don't mind, I haven't had a chance to test my modifications. They're pretty major. EDIT: typo |
|
Not so many No, I nested all the python function-words because they are local to I had a quick look at your fork and tried running it. Looks like you have plenty of typos. My total knowledge of objects, classes etc. is: I bought "Smalltalk-80: The Language and its Implementation" in hardback in 1983 and thoroughly enjoyed reading it. Since then I have forgotten almost everything in it, and the definition of "Object Oriented" has changed substantially since then. I looked at that aspect of Python and decided I didn't need it. So a lot of your fork whooshed over me like a low pass from a jet fighter. |
|
Great! Did a lot of debugging today and it should work now. I pasted it into A Pythonanywhere console (CPython 3.9.5) and it ran just fine. With all the Python Quackery words on the global scope in my fork now, if someone does After some fixing of the loadfile system I was thinking of making a web console using Transcrypt and jQuery Terminal (which I am already using for Phoo) and making it available via Github Pages. Do you like that idea? |
|
Amazing! I saw not cluttering the namespace as a major benefit of nesting all the functions, and if all it takes is a one-line dunder then I'm in favour of that. Why wait until it's necessary? I love the idea of making it available in a web console! The easier it is for people to try it out, the better. |
|
That's the magic of dunders! In lieu of a web console, the closest substitute I have found is going to https://www.pythonanywhere.com/embedded3/ and pasting in this: from requests import get
def load(url):
c = compile(get(url).text, url, 'exec')
exec(c, globals(), globals())
load('https://raw.githubusercontent.com/GordonCharlton/Quackery/main/quackery.py')or For some reason it screws up the Python stack traces when Quackery crashes, but so long as Quackery doesn't crash it will run fine. (Try |
|
Your fork runs on my 2011 iMac under Python 3.8.1, and on my Mac mini under Python 3.10.2 and PyPy 3.7.12 without any complaints. I can also try it on a Raspberry Pi 400 if you like, but I don't expect it would have any issues. :-) But… timings suggest that it's running slower. :-( (the file On the Mac mini,
On the iMac,
|
|
I don't think you'll need to test it on the RPi. I only think the difference is 32/64 bit and RAM amount, so if you try Oh well. I suspected as much - calling bound methods of objects has a higher overhead than just accessing variables in an outer scope. Javascript has a JIT compiler, so the online Transcrypt-compiled Quackery should produce similar numbers as PyPy did (and if my experience with Phoo is still correct, maybe even smaller numbers). |
|
It would be interesting to see what numbers would come up with a more stressful test (such doing something simple 100000 times) and then compare the numbers. Maybe something like |
|
It's a bank holiday weekend here, so mostly family time, no opportunity to devise a well thought out test suite, but I found a few minutes here and there to cobble together a quick test by adapting an existing piece of code ("Yellowstone numbers" on rosettacode) to compile and run a thousand times. (Had to rename the file from .qky to .txt to upload it.) Results are quite interesting. (The system times are negligible so omitted. They changed the terminology from real time to user time and stopped reporting in minutes between the two versions of the OS. Probably because Apple switched the terminal from BASH to ZSH.) As I'd expect, JIT is the major factor, but on this test at least, JIT favours your approach. |
I have a testing online Quackery console using Pyodide: https://dragoncoder047.github.io/QuackeryFork/ Right now it appears to have issues because Let me know if it works for you - it hasn't for me yet. |
|
Not working yet. Gets as far as printing the duckhead prompt and a bunch of diagnostics. So I tried this, And yes! It works!!! "Numfar, do the dance of joy" |
|
The Pythonanywhere paste hack was just a hack until the Pyodide problem is resolved. I already mentioned it in a previous comment and seeing that it worked I figured I would share it in the error message when the online console didn't work. The disadvantage of that option is that you would need a constant internet connection because the code is actually running on the Pythonanywhere server and you are essentially just SSH'ing in and seeing the output. The online console I have built is running all the code on your browser (and then crashing!) so it would not need an internet connection once it downloads everything and stores it in the cache. I learned that you can make a Promise synchrounous and block until it is resolved by using EDIT: typo |
|
Aaack, it doesn't seem to be working as I expected. The serviceworker appears to do absolutely nothing and the input function still crashes it all. I have filed another bug with Pyodide (pyodide/pyodide#2505), which tries to fix a similar issue with their online REPL and |
|
Trying a different approach today... Using the AST module to "rewrite" the Quackery code and make all the functions that need to be async async. Hope it works, still a few bugs. |
|
Super necropost but what kind of speeds are you getting with the newer CPython versions? The CPython devs are really stepping up the speed game now... |
|
Just ran a comparison using the code from the Rosetta Code task Blum integer. So yeah, Python 3.12 is about twice as fast as 3.9, but pypy3 still beats it by a country mile. |
]cjump[expects a number (how many to jump) and the boolean under that. (SED here.) That allows a user to define their ownifff,iffff, etc. without having to edit the Quackery source file or resort todup ]iff[ ]iff[hacks, and also to jump backwards with negative jump amounts such as[ false -1 ]cjump[ ] is hang. (Although I haven't encountered anywhere where that would be useful.)I have not been able to edit the PDF documentation files, you will have to get that yourself. I haven't also checked the Rosetta Code pages to see where this would impact code there that uses
]if[,]iff[and]else[, but nonetheless it would be a trivial drop-in substitution - each would simply be replaced by1 ]cjump[,2 ]cjump[, andfalse 1 ]cjump[respectively - and that's pretty much what I did anyway in the definitions ofif,iff, andelse.There are also a couple of minor syntax fixes to make the code more Pythonic (
return xinstead ofreturn(x), etc.)