Weird issue with assigning object positions

6 views
Skip to first unread message

dbor...@willamette.edu

unread,
Jan 27, 2026, 8:21:22 PM (14 days ago) Jan 27
to Glowscript Users
One of my students made an error in their code (which plops down spheres and assigns them positions and an extra attribute q for charge according to information stored in a dictionary). I don't quite understand why the output is what it is...

Here's a minimal working and non-working example:


In particular, I'm not sure why all the spheres end up at vec(0,0,0) when the mistake is made.

Thoughts?

Steve Spicklemire

unread,
Jan 28, 2026, 5:25:05 AM (14 days ago) Jan 28
to 'Jim D.' via Glowscript Users, Steve Spicklemire
So I think the technical reason this happens in WebVPython is due to the way RapydScript handles keyword and non-keyword arguments. It always puts non-keyword arguments first which results in the mixup. I’d be happy to get into details off-list if you’re interested, but it’s a little arcane. Basically the first case produces this javascript:

esphere = ρσ_interpolate_kwargs.call(this, sphere, [ρσ_desugar_kwargs({pos: r, q: qc})]);

and the second results in this:

esphere = ρσ_interpolate_kwargs.call(this, sphere, [qc].concat([ρσ_desugar_kwargs({pos: r})]));

Notice that in the first case pos and q are in a separate dictionary, but in the second, pos is appended to a list with qc already inserted first.

If you try to run this in the (highly experimental) WASM version of WebVPython you get a syntax error:

Error:PythonError: Traceback (most recent call last):
File "/lib/python311.zip/_pyodide/_base.py", line 540, in eval_code_async
await CodeRunner(
^^^^^^^^^^^
File "/lib/python311.zip/_pyodide/_base.py", line 248, in __init__
self.ast = next(self._gen)
^^^^^^^^^^^^^^^
File "/lib/python311.zip/_pyodide/_base.py", line 144, in _parse_and_compile_gen
mod = compile(source, filename, mode, flags | ast.PyCF_ONLY_AST)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<exec>", line 28
esphere = sphere(pos=r, qc)
^
SyntaxError: positional argument follows keyword argument
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/glowscript-users/977952a1-2d48-41fb-9754-47bec8741527n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages