ANN: Dogelog Runtime, Prolog to the Moon (2021)

Mostowski Collapse bursejan at gmail.com
Wed Sep 15 14:31:48 EDT 2021


There is a further problem with this:

> for i,term in enumerate(term.args): 
> ____mark_term(term.args[i]) 

It should read:

for i,help in enumerate(term.args): 
____mark_term(help) 

But then i isn't need.

Mostowski Collapse schrieb am Mittwoch, 15. September 2021 um 20:22:50 UTC+2:
> Do you mean, replace this:
> i = 0 
> while i < len(term.args) - 1:
> ____mark_term(term.args[i]) 
> ____i += 1 
> term = term.args[i] 
> 
> By this: 
> 
> for i,term in enumerate(term.args): 
> ____mark_term(term.args[i]) 
> 
> This wouldn't be correct anymore. The 
> recursive call is only for the arguments 
> except for the last one one.
> alister schrieb am Mittwoch, 15. September 2021 um 20:17:23 UTC+2: 
> > On Wed, 15 Sep 2021 18:23:10 +0200, Mostowski Collapse wrote: 
> > 
> > > I really wonder why my Python implementation is a factor 40 slower than 
> > > my JavaScript implementation. 
> > > Structurally its the same code. 
> > > 
> > > You can check yourself: 
> > > 
> > > Python Version: 
> > > https://github.com/jburse/dogelog-moon/blob/main/devel/runtimepy/ 
> > machine.py 
> > > 
> > > JavaScript Version: 
> > > https://github.com/jburse/dogelog-moon/blob/main/devel/runtime/ 
> > machine.js 
> > > 
> > > Its the same while, if-then-else, etc.. its the same classes Variable, 
> > > Compound etc.. Maybe I could speed it up by some details. For example to 
> > > create an array of length n, I use in Python: 
> > > 
> > > temp = [NotImplemented] * code[pos] 
> > > pos += 1 
> > > 
> > > Whereas in JavaScript I use, also in exec_build2(): 
> > > 
> > > temp = new Array(code[pos++]); 
> > > 
> > > So I hear Guido doesn't like ++. So in Python I use += 
> > > and a separate statement as a workaround. But otherwise, 
> > > what about the creation of an array, 
> > > 
> > > is the the idiom [_] * _ slow? I am assuming its compiled away. Or does 
> > > it really first create an array of size 1 and then enlarge it? 
> > > 
> > > Julio Di Egidio wrote: 
> > <sniped due to top posting> 
> > 
> > this is probably a string contender 
> > 
> > i = 0 
> > while i < len(term.args) - 1: 
> > mark_term(term.args[i]) 
> > i += 1 
> > term = term.args[i] 
> > 
> > try replacing with something more pythonic 
> > 
> > for index,term in enumerate(term.args): 
> > mark_term(term.args[i]) 
> > 
> > 
> > & possibly go all the way to changing it into a comprehension 
> > 
> > there are other similar anti patterns throughout this code. 
> > 
> > any time you are manually keeping a counter as an index into a list,tupple 
> > other iterable YOU ARE DOING IT WRONG! 
> > 
> > Do not write javascript in python, write python 
> > 
> > 
> > 
> > -- 
> > Two percent of zero is almost nothing. 
> > 
> > 
> > 
> > 
> > -- 
> > Whoever dies with the most toys wins.


More information about the Python-list mailing list